Skip to content

Commit 75458f9

Browse files
authored
Merge pull request #450 from mdeguzis/master
Use bash subshell for procfs interpolation of cmdline file
2 parents 3606e4f + 1431ba6 commit 75458f9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

save_command_strategies/linux_procfs.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ exit_safely_if_empty_ppid() {
1313

1414
full_command() {
1515
[[ -z "$COMMAND_PID" ]] && exit 0
16-
cat /proc/${COMMAND_PID}/cmdline | xargs -0 printf "%q "
16+
# See: https://unix.stackexchange.com/a/567021
17+
# Avoid complications with system printf by using bash subshell interpolation.
18+
# This will properly escape sequences and null in cmdline.
19+
cat /proc/${COMMAND_PID}/cmdline | xargs -0 bash -c 'printf "%q " "$0" "$@"'
1720
}
1821

1922
main() {

0 commit comments

Comments
 (0)