X Tutup
Skip to content

Commit e3b4efd

Browse files
committed
Add 8bit-version of get_process_cmdline() and use in cgroup-show.c
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.
1 parent 09c1dce commit e3b4efd

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

src/basic/escape.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ char *xescape_full(const char *s, const char *bad, size_t console_width, bool ei
435435
return ans;
436436
}
437437

438+
char *escape_non_printable_full(const char *str, size_t console_width, bool eight_bit) {
439+
if (eight_bit)
440+
return xescape_full(str, "", console_width, true);
441+
else
442+
return utf8_escape_non_printable_full(str, console_width);
443+
}
444+
438445
char *octescape(const char *s, size_t len) {
439446
char *r, *t;
440447
const char *f;

src/basic/escape.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static inline char *xescape(const char *s, const char *bad) {
5151
return xescape_full(s, bad, SIZE_MAX, false);
5252
}
5353
char *octescape(const char *s, size_t len);
54+
char *escape_non_printable_full(const char *str, size_t console_width, bool eight_bit);
5455

5556
char *shell_escape(const char *s, const char *bad);
5657
char* shell_maybe_quote(const char *s, EscapeStyle style);

src/basic/process-util.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "fileio.h"
3131
#include "fs-util.h"
3232
#include "ioprio.h"
33+
#include "locale-util.h"
3334
#include "log.h"
3435
#include "macro.h"
3536
#include "memory-util.h"
@@ -178,7 +179,9 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
178179

179180
delete_trailing_chars(t, WHITESPACE);
180181

181-
ans = utf8_escape_non_printable_full(t, max_columns);
182+
bool eight_bit = (flags & PROCESS_CMDLINE_USE_LOCALE) && !is_locale_utf8();
183+
184+
ans = escape_non_printable_full(t, max_columns, eight_bit);
182185
if (!ans)
183186
return -ENOMEM;
184187

src/basic/process-util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
typedef enum ProcessCmdlineFlags {
3535
PROCESS_CMDLINE_COMM_FALLBACK = 1 << 0,
36+
PROCESS_CMDLINE_USE_LOCALE = 1 << 1,
3637
} ProcessCmdlineFlags;
3738

3839
int get_process_comm(pid_t pid, char **name);

src/shared/cgroup-show.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ static void show_pid_array(
6161
for (i = 0; i < n_pids; i++) {
6262
_cleanup_free_ char *t = NULL;
6363

64-
(void) get_process_cmdline(pids[i], n_columns, PROCESS_CMDLINE_COMM_FALLBACK, &t);
64+
(void) get_process_cmdline(pids[i], n_columns,
65+
PROCESS_CMDLINE_COMM_FALLBACK | PROCESS_CMDLINE_USE_LOCALE,
66+
&t);
6567

6668
if (extra)
6769
printf("%s%s ", prefix, special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET));

0 commit comments

Comments
 (0)
X Tutup