]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coredump: use "POSIX quotes" for cmdline
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 2 Apr 2021 11:52:56 +0000 (13:52 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 5 May 2021 11:59:23 +0000 (13:59 +0200)
$ coredumpctl info |grep Command
  Command Line: bash -c kill -SEGV $$      (before)
  Command Line: bash -c "kill -SEGV \$\$"  (road not taken, C quotes)
  Command Line: bash -c $'kill -SEGV $$'   (now, POSIX quotes)

Before we wouldn't use any quoting, making it impossible to figure how the
command line was split into arguments. We could use "normal" quotes, but this
has the disadvantage that the commandline *looks* like it could be pasted into
the terminal and executed, but this is not true: various non-printable
characters cannot be expressed in this quoting style. (This is not visible in
this example). Thus, "POSIX quotes" are used, which should allow any command
line to be expressed acurrately and pasted directly into a shell prompt to
reexecute.

I wonder if we should another field in the coredump entry that simply shows the
original cmdline with embedded NULs, in the original /proc/*/cmdline
format. This would allow clients to format the data as they see fit. But I
think we'd want to keep the serialized form anyway, for backwards compatibility.

man/coredumpctl.xml
src/coredump/coredump.c

index 68ba6dc9f2568a2832788011c7cd987f00e7ad8a..6ceed41b0598e0f720bb993235ccb3e44ff4ec71 100644 (file)
@@ -362,7 +362,7 @@ Fri … 552351 1000 1000 SIGSEGV present  /usr/lib64/firefox/firefox 28.7M
            GID: 1000 (user)
         Signal: 11 (SEGV)
      Timestamp: Mon 2021-01-01 00:00:01 CET (20s ago)
-  Command Line: bash -c kill -SEGV $$
+  Command Line: bash -c $'kill -SEGV $$'
     Executable: /usr/bin/bash
  Control Group: /user.slice/user-1000.slice/…
           Unit: user@1000.service
index 2fb2404500e88c026241b69ad03c71178ac831e8..a16be3c44832cf14f3995e634e26914995bddc2c 100644 (file)
@@ -665,7 +665,7 @@ static int get_process_container_parent_cmdline(pid_t pid, char** cmdline) {
         if (r < 0)
                 return r;
 
-        r = get_process_cmdline(container_pid, SIZE_MAX, 0, cmdline);
+        r = get_process_cmdline(container_pid, SIZE_MAX, PROCESS_CMDLINE_QUOTE_POSIX, cmdline);
         if (r < 0)
                 return r;
 
@@ -1115,7 +1115,7 @@ static int gather_pid_metadata(struct iovec_wrapper *iovw, Context *context) {
         if (sd_pid_get_slice(pid, &t) >= 0)
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_SLICE=", t);
 
-        if (get_process_cmdline(pid, SIZE_MAX, 0, &t) >= 0)
+        if (get_process_cmdline(pid, SIZE_MAX, PROCESS_CMDLINE_QUOTE_POSIX, &t) >= 0)
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_CMDLINE=", t);
 
         if (cg_pid_get_path_shifted(pid, NULL, &t) >= 0)