From e04ed6db6b44681b7a7876b9c4a1e6adaf877670 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Jul 2019 19:05:25 +0200 Subject: [PATCH 1/6] =?UTF-8?q?exit-status:=20rename=20EXIT=5FSTATUS=5FGLI?= =?UTF-8?q?BC=20=E2=86=92=20EXIT=5FSTATUS=5FLIBC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After all these two exit codes are defined by ISO C as part of the C library, and it's not the GNU implementation defines them. --- src/core/execute.c | 2 +- src/core/main.c | 2 +- src/shared/exit-status.c | 8 ++++---- src/shared/exit-status.h | 4 ++-- src/systemctl/systemctl.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/execute.c b/src/core/execute.c index 5b55557f4e..21127d4f70 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -3881,7 +3881,7 @@ int exec_spawn(Unit *unit, if (r < 0) { const char *status = exit_status_to_string(exit_status, - EXIT_STATUS_GLIBC | EXIT_STATUS_SYSTEMD); + EXIT_STATUS_LIBC | EXIT_STATUS_SYSTEMD); log_struct_errno(LOG_ERR, r, "MESSAGE_ID=" SD_MESSAGE_SPAWN_FAILED_STR, diff --git a/src/core/main.c b/src/core/main.c index 0698f893fd..bcce7178a8 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -223,7 +223,7 @@ _noreturn_ static void crash(int sig) { log_emergency_errno(r, "Caught <%s>, waitpid() failed: %m", signal_to_string(sig)); else if (status.si_code != CLD_DUMPED) { const char *s = status.si_code == CLD_EXITED - ? exit_status_to_string(status.si_status, EXIT_STATUS_GLIBC) + ? exit_status_to_string(status.si_status, EXIT_STATUS_LIBC) : signal_to_string(status.si_status); log_emergency("Caught <%s>, core dump failed (child "PID_FMT", code=%s, status=%i/%s).", diff --git a/src/shared/exit-status.c b/src/shared/exit-status.c index 80ac4868cb..44b1c9b749 100644 --- a/src/shared/exit-status.c +++ b/src/shared/exit-status.c @@ -26,8 +26,8 @@ const ExitStatusMapping exit_status_mappings[256] = { * │ signal or such, and we follow that logic here.) */ - [EXIT_SUCCESS] = { "SUCCESS", EXIT_STATUS_GLIBC }, - [EXIT_FAILURE] = { "FAILURE", EXIT_STATUS_GLIBC }, + [EXIT_SUCCESS] = { "SUCCESS", EXIT_STATUS_LIBC }, + [EXIT_FAILURE] = { "FAILURE", EXIT_STATUS_LIBC }, [EXIT_CHDIR] = { "CHDIR", EXIT_STATUS_SYSTEMD }, [EXIT_NICE] = { "NICE", EXIT_STATUS_SYSTEMD }, @@ -107,8 +107,8 @@ const char* exit_status_class(int code) { return NULL; switch (exit_status_mappings[code].class) { - case EXIT_STATUS_GLIBC: - return "glibc"; + case EXIT_STATUS_LIBC: + return "libc"; case EXIT_STATUS_SYSTEMD: return "systemd"; case EXIT_STATUS_LSB: diff --git a/src/shared/exit-status.h b/src/shared/exit-status.h index d6da8c19b9..9ea147c842 100644 --- a/src/shared/exit-status.h +++ b/src/shared/exit-status.h @@ -75,11 +75,11 @@ enum { }; typedef enum ExitStatusClass { - EXIT_STATUS_GLIBC = 1 << 0, /* libc EXIT_STATUS/EXIT_FAILURE */ + EXIT_STATUS_LIBC = 1 << 0, /* libc EXIT_STATUS/EXIT_FAILURE */ EXIT_STATUS_SYSTEMD = 1 << 1, /* systemd's own exit codes */ EXIT_STATUS_LSB = 1 << 2, /* LSB exit codes */ EXIT_STATUS_BSD = 1 << 3, /* BSD (EX_xyz) exit codes */ - EXIT_STATUS_FULL = EXIT_STATUS_GLIBC | EXIT_STATUS_SYSTEMD | EXIT_STATUS_LSB | EXIT_STATUS_BSD, + EXIT_STATUS_FULL = EXIT_STATUS_LIBC | EXIT_STATUS_SYSTEMD | EXIT_STATUS_LSB | EXIT_STATUS_BSD, } ExitStatusClass; typedef struct ExitStatusSet { diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 880a04411c..82babaa691 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4380,7 +4380,7 @@ static void print_status_info( printf("status=%i", p->status); - c = exit_status_to_string(p->status, EXIT_STATUS_GLIBC | EXIT_STATUS_SYSTEMD); + c = exit_status_to_string(p->status, EXIT_STATUS_LIBC | EXIT_STATUS_SYSTEMD); if (c) printf("/%s", c); @@ -4422,7 +4422,7 @@ static void print_status_info( printf("status=%i", i->exit_status); c = exit_status_to_string(i->exit_status, - EXIT_STATUS_GLIBC | EXIT_STATUS_SYSTEMD); + EXIT_STATUS_LIBC | EXIT_STATUS_SYSTEMD); if (c) printf("/%s", c); From 563067ad265f4704395165177fb5b83bc9628c66 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Jul 2019 19:14:09 +0200 Subject: [PATCH 2/6] analyze: always use "int" to display exit status values That's what it actually is, hence let's use that and cast when the type is bigger. --- src/analyze/analyze.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 45e41fedee..199d49f5b9 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -1653,7 +1653,7 @@ static int dump_exit_codes(int argc, char *argv[], void *userdata) { r = table_add_many(table, TABLE_STRING, exit_status_mappings[i].name, - TABLE_UINT, i, + TABLE_INT, (int) i, TABLE_STRING, exit_status_class(i)); if (r < 0) return r; @@ -1669,7 +1669,7 @@ static int dump_exit_codes(int argc, char *argv[], void *userdata) { assert(code >= 0 && (size_t) code < ELEMENTSOF(exit_status_mappings)); r = table_add_many(table, TABLE_STRING, exit_status_mappings[code].name ?: "-", - TABLE_UINT, code, + TABLE_INT, code, TABLE_STRING, exit_status_class(code) ?: "-"); if (r < 0) return r; From 5238d9a83a52c64e24856b0d3b2ca0b0ee52479a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Jul 2019 19:18:56 +0200 Subject: [PATCH 3/6] analyze: rename "exit-codes" to "exit-status" waitid(2) and the libc function signature calls this "exit status", and uses "exit code" for something different. Let's stick to the same nomenclature hence. --- NEWS | 6 +++--- man/systemd-analyze.xml | 26 +++++++++++++------------- src/analyze/analyze.c | 24 ++++++++++++------------ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/NEWS b/NEWS index b26c749a5f..5ad412ef99 100644 --- a/NEWS +++ b/NEWS @@ -106,9 +106,9 @@ CHANGES WITH 243 in spe: unambiguously distinguished. * SuccessExitStatus=, RestartPreventExitStatus=, and - RestartForceExitStatus= now accept exit code names (e.g. "DATAERR" is - equivalent to "65"). systemd-analyze learnt a new 'exit-codes' verb - to display those exit code name mappings. + RestartForceExitStatus= now accept exit status names (e.g. "DATAERR" + is equivalent to "65"). systemd-analyze learnt a new 'exit-status' + verb to display those exit status name mappings. * /usr/sbin/halt.local is no longer supported. Implementation in distributions was inconsistent and it seems this functionality was diff --git a/man/systemd-analyze.xml b/man/systemd-analyze.xml index 8e9f24caac..7e842ac201 100644 --- a/man/systemd-analyze.xml +++ b/man/systemd-analyze.xml @@ -86,8 +86,8 @@ systemd-analyze OPTIONS - exit-codes - CODE + exit-status + STATUS systemd-analyze @@ -372,25 +372,25 @@ $ eog targets.svg - <command>systemd-analyze exit-codes <optional><replaceable>CODE</replaceable>...</optional></command> + <command>systemd-analyze exit-status <optional><replaceable>STATUS</replaceable>...</optional></command> - This command prints a list of exit codes along with their "class", i.e. the source of the + This command prints a list of exit statuses along with their "class", i.e. the source of the definition (one of glibc, systemd, LSB, or BSD), see the Process Exit Codes section in systemd.exec5. - If no additional arguments are specified, all known codes are are shown. Otherwise, only the + If no additional arguments are specified, all known statuses are are shown. Otherwise, only the definitions for the specified codes are shown. - <command>Show some example exit code names</command> + <command>Show some example exit status names</command> - $ systemd-analyze exit-codes 0 1 {63..65} -NAME CODE CLASS -SUCCESS 0 glibc -FAILURE 1 glibc -- 63 - -USAGE 64 BSD -DATAERR 65 BSD + $ systemd-analyze exit-status 0 1 {63..65} +NAME STATUS CLASS +SUCCESS 0 glibc +FAILURE 1 glibc +- 63 - +USAGE 64 BSD +DATAERR 65 BSD diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 199d49f5b9..1785e2ec07 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -1638,11 +1638,11 @@ static void dump_syscall_filter(const SyscallFilterSet *set) { printf(" %s%s%s\n", syscall[0] == '@' ? ansi_underline() : "", syscall, ansi_normal()); } -static int dump_exit_codes(int argc, char *argv[], void *userdata) { +static int dump_exit_status(int argc, char *argv[], void *userdata) { _cleanup_(table_unrefp) Table *table = NULL; int r; - table = table_new("name", "code", "class"); + table = table_new("name", "status", "class"); if (!table) return log_oom(); @@ -1660,17 +1660,17 @@ static int dump_exit_codes(int argc, char *argv[], void *userdata) { } else for (int i = 1; i < argc; i++) { - int code; + int status; - code = exit_status_from_string(argv[i]); - if (code < 0) - return log_error_errno(r, "Invalid exit code \"%s\": %m", argv[i]); + status = exit_status_from_string(argv[i]); + if (status < 0) + return log_error_errno(r, "Invalid exit status \"%s\": %m", argv[i]); - assert(code >= 0 && (size_t) code < ELEMENTSOF(exit_status_mappings)); + assert(status >= 0 && (size_t) status < ELEMENTSOF(exit_status_mappings)); r = table_add_many(table, - TABLE_STRING, exit_status_mappings[code].name ?: "-", - TABLE_INT, code, - TABLE_STRING, exit_status_class(code) ?: "-"); + TABLE_STRING, exit_status_mappings[status].name ?: "-", + TABLE_INT, status, + TABLE_STRING, exit_status_class(status) ?: "-"); if (r < 0) return r; } @@ -2213,7 +2213,7 @@ static int help(int argc, char *argv[], void *userdata) { " dump Output state serialization of service manager\n" " cat-config Show configuration file and drop-ins\n" " unit-paths List load directories for units\n" - " exit-codes List exit code definitions\n" + " exit-status List exit status definitions\n" " syscall-filter [NAME...] Print list of syscalls in seccomp filter\n" " condition CONDITION... Evaluate conditions and asserts\n" " verify FILE... Check unit files for correctness\n" @@ -2418,7 +2418,7 @@ static int run(int argc, char *argv[]) { { "dump", VERB_ANY, 1, 0, dump }, { "cat-config", 2, VERB_ANY, 0, cat_config }, { "unit-paths", 1, 1, 0, dump_unit_paths }, - { "exit-codes", VERB_ANY, VERB_ANY, 0, dump_exit_codes }, + { "exit-status", VERB_ANY, VERB_ANY, 0, dump_exit_status }, { "syscall-filter", VERB_ANY, VERB_ANY, 0, dump_syscall_filters }, { "condition", 2, VERB_ANY, 0, do_condition }, { "verify", 2, VERB_ANY, 0, do_verify }, From d8e17e7356d50240b691db5b450f0df685e74f92 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Jul 2019 19:22:34 +0200 Subject: [PATCH 4/6] analyze: right-align exit status column --- src/analyze/analyze.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 1785e2ec07..f7e0843ab4 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -1646,6 +1646,10 @@ static int dump_exit_status(int argc, char *argv[], void *userdata) { if (!table) return log_oom(); + r = table_set_align_percent(table, table_get_cell(table, 0, 1), 100); + if (r < 0) + return log_error_errno(r, "Failed to right-align status: %m"); + if (strv_isempty(strv_skip(argv, 1))) for (size_t i = 0; i < ELEMENTSOF(exit_status_mappings); i++) { if (!exit_status_mappings[i].name) From 29a3d5caea40821079a73628d6dbe275f7ff475a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Jul 2019 19:25:49 +0200 Subject: [PATCH 5/6] man: remove trailing space in link in HTML output --- man/systemd.exec.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index f9c3f41890..fbbfd4f514 100644 --- a/man/systemd.exec.xml +++ b/man/systemd.exec.xml @@ -2718,8 +2718,7 @@ StandardInputData=SWNrIHNpdHplIGRhIHVuJyBlc3NlIEtsb3BzLAp1ZmYgZWVtYWwga2xvcHAncy The following service exit codes are defined by the LSB specification - . + url="https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html">LSB specification. From d68d0366dcde5adedf652be28d2e8e3c59a0219d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Jul 2019 19:44:24 +0200 Subject: [PATCH 6/6] analyze: clarify that 'exit-status' optionally takes arguments --- src/analyze/analyze.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index f7e0843ab4..e5c0cc853d 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -2217,7 +2217,7 @@ static int help(int argc, char *argv[], void *userdata) { " dump Output state serialization of service manager\n" " cat-config Show configuration file and drop-ins\n" " unit-paths List load directories for units\n" - " exit-status List exit status definitions\n" + " exit-status [STATUS...] List exit status definitions\n" " syscall-filter [NAME...] Print list of syscalls in seccomp filter\n" " condition CONDITION... Evaluate conditions and asserts\n" " verify FILE... Check unit files for correctness\n"