diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2011-09-29 21:18:17 +0200 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2011-09-29 21:25:50 +0200 |
commit | 798e258d301ac237cb1d72b5fc4b19ee900d6f7d (patch) | |
tree | ae70c1d2242c61e982190ca1e8a512a54b32305c /src | |
parent | a0ccd2acab443f5fa33e464a7e2f756dff2a5e35 (diff) |
systemctl: fix corrupted output of units
On some systems the list of units in systemctl output came out wrong,
all on one line and with missing descriptions.
It turns out printf() really attempts to mmap 2G memory when INT_MAX is
passed as the field width. On machines with small virtual memory
without overcommit the mmap inside printf() failed.
Do not use INT_MAX for unlimited width.
Diffstat (limited to 'src')
-rw-r--r-- | src/systemctl.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/systemctl.c b/src/systemctl.c index 9b54da16ca..0de2444d43 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -358,13 +358,14 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) { } else id_len = max_id_len; - if (arg_full || !arg_no_pager) - desc_len = INT_MAX; - - if (!arg_no_legend) - printf("%-*s %-6s %-*s %-*s %-*s %.*s\n", id_len, "UNIT", "LOAD", - active_len, "ACTIVE", sub_len, "SUB", job_len, "JOB", - desc_len, "DESCRIPTION"); + if (!arg_no_legend) { + printf("%-*s %-6s %-*s %-*s %-*s ", id_len, "UNIT", "LOAD", + active_len, "ACTIVE", sub_len, "SUB", job_len, "JOB"); + if (!arg_full && arg_no_pager) + printf("%.*s\n", desc_len, "DESCRIPTION"); + else + printf("%s\n", "DESCRIPTION"); + } for (u = unit_infos; u < unit_infos + c; u++) { char *e; @@ -391,13 +392,16 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) { e = arg_full ? NULL : ellipsize(u->id, id_len, 33); - printf("%-*s %s%-6s%s %s%-*s %-*s%s %-*s %.*s\n", + printf("%-*s %s%-6s%s %s%-*s %-*s%s %-*s ", id_len, e ? e : u->id, on_loaded, u->load_state, off_loaded, on_active, active_len, u->active_state, sub_len, u->sub_state, off_active, - job_len, u->job_id ? u->job_type : "", - desc_len, u->description); + job_len, u->job_id ? u->job_type : ""); + if (!arg_full && arg_no_pager) + printf("%.*s\n", desc_len, u->description); + else + printf("%s\n", u->description); free(e); } |