diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-07-28 10:19:53 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-07-29 15:54:53 +0200 |
commit | f0d67dcddd4bcbe0a221a4ff4248114e5cf57dd8 (patch) | |
tree | 1abaa60f026d888f88145060c12f3b41b4b9bd03 /src/shared/exit-status.c | |
parent | shared/exit-status: turn status level into a bitmask, add "test" (diff) | |
download | systemd-f0d67dcddd4bcbe0a221a4ff4248114e5cf57dd8.tar.xz systemd-f0d67dcddd4bcbe0a221a4ff4248114e5cf57dd8.zip |
shared/exit-status: add exit_status_from_string()
Diffstat (limited to 'src/shared/exit-status.c')
-rw-r--r-- | src/shared/exit-status.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/shared/exit-status.c b/src/shared/exit-status.c index 51f2380027..12880f805e 100644 --- a/src/shared/exit-status.c +++ b/src/shared/exit-status.c @@ -6,7 +6,9 @@ #include "exit-status.h" #include "macro.h" +#include "parse-util.h" #include "set.h" +#include "string-util.h" const ExitStatusMapping exit_status_mappings[256] = { /* Exit status ranges: @@ -117,6 +119,21 @@ const char* exit_status_class(int code) { } } +int exit_status_from_string(const char *s) { + uint8_t val; + int r; + + for (size_t i = 0; i < ELEMENTSOF(exit_status_mappings); i++) + if (streq_ptr(s, exit_status_mappings[i].name)) + return i; + + r = safe_atou8(s, &val); + if (r < 0) + return r; + + return val; +} + bool is_clean_exit(int code, int status, ExitClean clean, ExitStatusSet *success_status) { if (code == CLD_EXITED) return status == 0 || |