| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "bitmap.h" |
| 5 |
#include "shared-forward.h" |
| 6 |
|
| 7 |
/* This defines pretty names for the LSB 'start' verb exit codes. Note that they shouldn't be confused with |
| 8 |
* the LSB 'status' verb exit codes which are defined very differently. For details see: |
| 9 |
* |
| 10 |
* https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html |
| 11 |
*/ |
| 12 |
|
| 13 |
enum { |
| 14 |
/* EXIT_SUCCESS defined by libc */ |
| 15 |
/* EXIT_FAILURE defined by libc */ |
| 16 |
EXIT_INVALIDARGUMENT = 2, |
| 17 |
EXIT_NOTIMPLEMENTED = 3, |
| 18 |
EXIT_NOPERMISSION = 4, |
| 19 |
EXIT_NOTINSTALLED = 5, |
| 20 |
EXIT_NOTCONFIGURED = 6, |
| 21 |
EXIT_NOTRUNNING = 7, |
| 22 |
|
| 23 |
/* BSD's sysexits.h defines a couple EX_xyz exit codes in the range 64 … 78 */ |
| 24 |
|
| 25 |
/* The LSB suggests that error codes >= 200 are "reserved". We use them here under the assumption |
| 26 |
* that they hence are unused by init scripts. */ |
| 27 |
EXIT_CHDIR = 200, |
| 28 |
EXIT_NICE, |
| 29 |
EXIT_FDS, |
| 30 |
EXIT_EXEC, |
| 31 |
EXIT_MEMORY, |
| 32 |
EXIT_LIMITS, |
| 33 |
EXIT_OOM_ADJUST, |
| 34 |
EXIT_SIGNAL_MASK, |
| 35 |
EXIT_STDIN, |
| 36 |
EXIT_STDOUT, |
| 37 |
EXIT_CHROOT, /* 210 */ |
| 38 |
EXIT_IOPRIO, |
| 39 |
EXIT_TIMERSLACK, |
| 40 |
EXIT_SECUREBITS, |
| 41 |
EXIT_SETSCHEDULER, |
| 42 |
EXIT_CPUAFFINITY, |
| 43 |
EXIT_GROUP, |
| 44 |
EXIT_USER, |
| 45 |
EXIT_CAPABILITIES, |
| 46 |
EXIT_CGROUP, |
| 47 |
EXIT_SETSID, /* 220 */ |
| 48 |
EXIT_CONFIRM, |
| 49 |
EXIT_STDERR, |
| 50 |
_EXIT_RESERVED, /* used to be tcpwrap, don't reuse! */ |
| 51 |
EXIT_PAM, |
| 52 |
EXIT_NETWORK, |
| 53 |
EXIT_NAMESPACE, |
| 54 |
EXIT_NO_NEW_PRIVILEGES, |
| 55 |
EXIT_SECCOMP, |
| 56 |
EXIT_SELINUX_CONTEXT, |
| 57 |
EXIT_PERSONALITY, /* 230 */ |
| 58 |
EXIT_APPARMOR_PROFILE, |
| 59 |
EXIT_ADDRESS_FAMILIES, |
| 60 |
EXIT_RUNTIME_DIRECTORY, |
| 61 |
_EXIT_RESERVED2, /* used to be used by kdbus, don't reuse */ |
| 62 |
EXIT_CHOWN, |
| 63 |
EXIT_SMACK_PROCESS_LABEL, |
| 64 |
EXIT_KEYRING, |
| 65 |
EXIT_STATE_DIRECTORY, |
| 66 |
EXIT_CACHE_DIRECTORY, |
| 67 |
EXIT_LOGS_DIRECTORY, /* 240 */ |
| 68 |
EXIT_CONFIGURATION_DIRECTORY, |
| 69 |
EXIT_NUMA_POLICY, |
| 70 |
EXIT_CREDENTIALS, |
| 71 |
EXIT_BPF, |
| 72 |
EXIT_KSM, |
| 73 |
EXIT_MEMORY_THP, |
| 74 |
|
| 75 |
EXIT_EXCEPTION = 255, /* Whenever we want to propagate an abnormal/signal exit, in line with bash */ |
| 76 |
}; |
| 77 |
|
| 78 |
typedef enum ExitStatusClass { |
| 79 |
EXIT_STATUS_LIBC = 1 << 0, /* libc EXIT_STATUS/EXIT_FAILURE */ |
| 80 |
EXIT_STATUS_SYSTEMD = 1 << 1, /* systemd's own exit codes */ |
| 81 |
EXIT_STATUS_LSB = 1 << 2, /* LSB exit codes */ |
| 82 |
EXIT_STATUS_BSD = 1 << 3, /* BSD (EX_xyz) exit codes */ |
| 83 |
EXIT_STATUS_FULL = EXIT_STATUS_LIBC | EXIT_STATUS_SYSTEMD | EXIT_STATUS_LSB | EXIT_STATUS_BSD, |
| 84 |
} ExitStatusClass; |
| 85 |
|
| 86 |
typedef struct ExitStatusSet { |
| 87 |
Bitmap status; |
| 88 |
Bitmap signal; |
| 89 |
} ExitStatusSet; |
| 90 |
|
| 91 |
const char* exit_status_to_string(int code, ExitStatusClass class) _const_; |
| 92 |
const char* exit_status_class(int code) _const_; |
| 93 |
DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(exit_status, int); |
| 94 |
|
| 95 |
typedef struct ExitStatusMapping { |
| 96 |
const char *name; |
| 97 |
ExitStatusClass class; |
| 98 |
} ExitStatusMapping; |
| 99 |
|
| 100 |
extern const ExitStatusMapping exit_status_mappings[256]; |
| 101 |
|
| 102 |
typedef enum ExitClean { |
| 103 |
EXIT_CLEAN_DAEMON, |
| 104 |
EXIT_CLEAN_COMMAND, |
| 105 |
} ExitClean; |
| 106 |
|
| 107 |
bool is_clean_exit(int code, int status, ExitClean clean, const ExitStatusSet *success_status) _pure_; |
| 108 |
|
| 109 |
void exit_status_set_free(ExitStatusSet *x); |
| 110 |
bool exit_status_set_is_empty(const ExitStatusSet *x) _pure_; |
| 111 |
bool exit_status_set_test(const ExitStatusSet *x, int code, int status) _pure_; |