Merge pull request #13219 from poettering/named-exit-codes-tweaks

quick follow-up for the symbolic exit status PR #13207
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-07-30 08:27:20 +02:00 committed by GitHub
commit e397eb50da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 41 deletions

6
NEWS
View File

@ -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

View File

@ -86,8 +86,8 @@
<cmdsynopsis>
<command>systemd-analyze</command>
<arg choice="opt" rep="repeat">OPTIONS</arg>
<arg choice="plain">exit-codes</arg>
<arg choice="opt" rep="repeat"><replaceable>CODE</replaceable></arg>
<arg choice="plain">exit-status</arg>
<arg choice="opt" rep="repeat"><replaceable>STATUS</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>systemd-analyze</command>
@ -372,25 +372,25 @@ $ eog targets.svg</programlisting>
</refsect2>
<refsect2>
<title><command>systemd-analyze exit-codes <optional><replaceable>CODE</replaceable>...</optional></command></title>
<title><command>systemd-analyze exit-status <optional><replaceable>STATUS</replaceable>...</optional></command></title>
<para>This command prints a list of exit codes along with their "class", i.e. the source of the
<para>This command prints a list of exit statuses along with their "class", i.e. the source of the
definition (one of <literal>glibc</literal>, <literal>systemd</literal>, <literal>LSB</literal>, or
<literal>BSD</literal>), see the Process Exit Codes section in
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
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.</para>
<example>
<title><command>Show some example exit code names</command></title>
<title><command>Show some example exit status names</command></title>
<programlisting>$ systemd-analyze exit-codes 0 1 {63..65}
NAME CODE CLASS
SUCCESS 0 glibc
FAILURE 1 glibc
- 63 -
USAGE 64 BSD
DATAERR 65 BSD
<programlisting>$ systemd-analyze exit-status 0 1 {63..65}
NAME STATUS CLASS
SUCCESS 0 glibc
FAILURE 1 glibc
- 63 -
USAGE 64 BSD
DATAERR 65 BSD
</programlisting>
</example>
</refsect2>

View File

@ -2718,8 +2718,7 @@ StandardInputData=SWNrIHNpdHplIGRhIHVuJyBlc3NlIEtsb3BzLAp1ZmYgZWVtYWwga2xvcHAncy
</table>
<para>The following service exit codes are defined by the <ulink
url="https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html">LSB specification
</ulink>.
url="https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html">LSB specification</ulink>.
</para>
<table>

View File

@ -1638,14 +1638,18 @@ 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();
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)
@ -1653,24 +1657,24 @@ 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;
}
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_UINT, 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 +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-codes List exit code 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"
@ -2418,7 +2422,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 },

View File

@ -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,

View File

@ -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).",

View File

@ -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:

View File

@ -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 {

View File

@ -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);