]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Add 8bit-version of get_process_cmdline() and use in cgroup-show.c
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 16 May 2019 15:44:57 +0000 (17:44 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 22 May 2019 08:16:00 +0000 (10:16 +0200)
This restores show_pid_array() output in legacy locales on the console.
Only one call to get_process_cmdline() is changed, all others retain
utf8-only mode. This affects systemd-cgls, systemctl status, etc, when
working locally.

Calls to get_process_cmdline() that cross a process boundary always use
utf8. It's the callers responsibility to convert this to some encoding that
they use. This means that we always pass utf8 over the bus.

src/basic/escape.c
src/basic/escape.h
src/basic/process-util.c
src/basic/process-util.h
src/shared/cgroup-show.c

index 77e86a58f3182288e7e5998de121b4797c699da2..33a6f204f55f5efb92e673c752cfac3f72a27d91 100644 (file)
@@ -435,6 +435,13 @@ char *xescape_full(const char *s, const char *bad, size_t console_width, bool ei
         return ans;
 }
 
+char *escape_non_printable_full(const char *str, size_t console_width, bool eight_bit) {
+        if (eight_bit)
+                return xescape_full(str, "", console_width, true);
+        else
+                return utf8_escape_non_printable_full(str, console_width);
+}
+
 char *octescape(const char *s, size_t len) {
         char *r, *t;
         const char *f;
index 45e23d0651bf5c40bd3b7e3dae5f7015a1f514e3..b26054c5df8abb765e7c68163c3c47ca41906c22 100644 (file)
@@ -51,6 +51,7 @@ static inline char *xescape(const char *s, const char *bad) {
         return xescape_full(s, bad, SIZE_MAX, false);
 }
 char *octescape(const char *s, size_t len);
+char *escape_non_printable_full(const char *str, size_t console_width, bool eight_bit);
 
 char *shell_escape(const char *s, const char *bad);
 char* shell_maybe_quote(const char *s, EscapeStyle style);
index 3e94c9a4aa78350bf6d50bdaa6e0538c4962b344..b50537908cc75362861a665cb4beeaa8c0233847 100644 (file)
@@ -30,6 +30,7 @@
 #include "fileio.h"
 #include "fs-util.h"
 #include "ioprio.h"
+#include "locale-util.h"
 #include "log.h"
 #include "macro.h"
 #include "memory-util.h"
@@ -178,7 +179,9 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
 
         delete_trailing_chars(t, WHITESPACE);
 
-        ans = utf8_escape_non_printable_full(t, max_columns);
+        bool eight_bit = (flags & PROCESS_CMDLINE_USE_LOCALE) && !is_locale_utf8();
+
+        ans = escape_non_printable_full(t, max_columns, eight_bit);
         if (!ans)
                 return -ENOMEM;
 
index b68729cf78b5b6779e34136587b92f27b033f4c1..2e3bd7250545406d818635ecfd6ca290ed16c173 100644 (file)
@@ -33,6 +33,7 @@
 
 typedef enum ProcessCmdlineFlags {
         PROCESS_CMDLINE_COMM_FALLBACK = 1 << 0,
+        PROCESS_CMDLINE_USE_LOCALE    = 1 << 1,
 } ProcessCmdlineFlags;
 
 int get_process_comm(pid_t pid, char **name);
index 464a3e5c0359637bf8ed74f06d7972fa65ed2253..e6fdcfa277deddfbfca7c1001b57058b72ad3ab4 100644 (file)
@@ -61,7 +61,9 @@ static void show_pid_array(
         for (i = 0; i < n_pids; i++) {
                 _cleanup_free_ char *t = NULL;
 
-                (void) get_process_cmdline(pids[i], n_columns, PROCESS_CMDLINE_COMM_FALLBACK, &t);
+                (void) get_process_cmdline(pids[i], n_columns,
+                                           PROCESS_CMDLINE_COMM_FALLBACK | PROCESS_CMDLINE_USE_LOCALE,
+                                           &t);
 
                 if (extra)
                         printf("%s%s ", prefix, special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET));