basic/process-util: add mode where posix shell escape is used for quoting

The new flag is not used, except in tests, so no functional change yet.

This way, the command as shown can be copied-and-pasted into the shell
in more cases. For simple cases, shell quoting with "" is enough. But
$'' is needed when there are control characters in the command.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-05-05 13:59:23 +02:00
parent 07468a16e4
commit 99009ed0f4
3 changed files with 20 additions and 2 deletions
+5 -2
View File
@@ -208,7 +208,10 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
if (full < 0)
return full;
if (flags & PROCESS_CMDLINE_QUOTE) {
if (flags & (PROCESS_CMDLINE_QUOTE | PROCESS_CMDLINE_QUOTE_POSIX)) {
ShellEscapeFlags shflags = SHELL_ESCAPE_EMPTY |
FLAGS_SET(flags, PROCESS_CMDLINE_QUOTE_POSIX) * SHELL_ESCAPE_POSIX;
assert(!(flags & PROCESS_CMDLINE_USE_LOCALE));
_cleanup_strv_free_ char **args = NULL;
@@ -220,7 +223,7 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
for (size_t i = 0; args[i]; i++) {
char *e;
e = shell_maybe_quote(args[i], SHELL_ESCAPE_EMPTY);
e = shell_maybe_quote(args[i], shflags);
if (!e)
return -ENOMEM;