Github user zasdfgbnm commented on a diff in the pull request: https://github.com/apache/spark/pull/14231#discussion_r72276770 --- Diff: bin/spark-class --- @@ -65,24 +65,25 @@ fi # characters that would be otherwise interpreted by the shell. Read that in a while loop, populating # an array that will be used to exec the final command. # -# The exit code of the launcher is appended to the output, so the parent shell removes it from the -# command array and checks the value to see if the launcher succeeded. -build_command() { - "$RUNNER" -Xmx128m -cp "$LAUNCH_CLASSPATH" org.apache.spark.launcher.Main "$@" - printf "%d\0" $? -} +# To keep both the output and the exit code of the launcher, the output is first converted to a hex +# dump which prevents the bash from getting rid of the NULL character, and the exit code retrieved +# from the bash array ${PIPESTATUS[@]}. +# +# Note that the seperator NULL character can not be replace with space or '\n' so that the command +# won't fail if some path of the user contain special characher such as '\n' or space +# +# Also note that when the launcher fails, it might not output something ending with '\0' [SPARK-16586] +_CMD=$("$RUNNER" -Xmx128m -cp "$LAUNCH_CLASSPATH" org.apache.spark.launcher.Main "$@"|xxd -p|tr -d '\n';exit ${PIPESTATUS[0]}) --- End diff -- Since bash don't allow us to store \0 in a variable, we need to find some way to deal with it. One way to deal with it is to run the launcher in a subshell and pipe the output of the subshell to the current shell by using the "read" provided by bash (see the original code line 76-78). In this way, the $? will be the exit status of some command in the while loop of this shell, not the exit code of launcher in the subshell. That's why in the origin implementation, $? is appended in the end. Another way to deal with \0, which is what I have proposed in this PR is, to make a hexdump of the output with '\0' and store the hexdump into a variable and when we just decode it we need to use the output with '\0'. In this way, the $? will be the exit status of "tr" rather than of the launcher.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org