2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include "exit-status.h"
27 const char* exit_status_to_string(int status
, ExitStatusLevel level
) {
29 /* We cast to int here, so that -Wenum doesn't complain that
30 * EXIT_SUCCESS/EXIT_FAILURE aren't in the enum */
41 if (IN_SET(level
, EXIT_STATUS_SYSTEMD
, EXIT_STATUS_LSB
)) {
65 case EXIT_SIGNAL_MASK
:
86 case EXIT_SETSCHEDULER
:
87 return "SETSCHEDULER";
89 case EXIT_CPUAFFINITY
:
98 case EXIT_CAPABILITIES
:
99 return "CAPABILITIES";
122 case EXIT_NO_NEW_PRIVILEGES
:
123 return "NO_NEW_PRIVILEGES";
128 case EXIT_SELINUX_CONTEXT
:
129 return "SELINUX_CONTEXT";
131 case EXIT_PERSONALITY
:
132 return "PERSONALITY";
134 case EXIT_APPARMOR_PROFILE
:
137 case EXIT_ADDRESS_FAMILIES
:
138 return "ADDRESS_FAMILIES";
140 case EXIT_RUNTIME_DIRECTORY
:
141 return "RUNTIME_DIRECTORY";
146 case EXIT_SMACK_PROCESS_LABEL
:
147 return "SMACK_PROCESS_LABEL";
152 case EXIT_STATE_DIRECTORY
:
153 return "STATE_DIRECTORY";
155 case EXIT_CACHE_DIRECTORY
:
156 return "CACHE_DIRECTORY";
158 case EXIT_LOGS_DIRECTORY
:
159 return "LOGS_DIRECTORY";
161 case EXIT_CONFIGURATION_DIRECTORY
:
162 return "CONFIGURATION_DIRECTORY";
166 if (level
== EXIT_STATUS_LSB
) {
169 case EXIT_INVALIDARGUMENT
:
170 return "INVALIDARGUMENT";
172 case EXIT_NOTIMPLEMENTED
:
173 return "NOTIMPLEMENTED";
175 case EXIT_NOPERMISSION
:
176 return "NOPERMISSION";
178 case EXIT_NOTINSTALLED
:
179 return "NOTINSTALLED";
181 case EXIT_NOTCONFIGURED
:
182 return "NOTCONFIGURED";
184 case EXIT_NOTRUNNING
:
192 bool is_clean_exit(int code
, int status
, ExitClean clean
, ExitStatusSet
*success_status
) {
194 if (code
== CLD_EXITED
)
195 return status
== 0 ||
197 set_contains(success_status
->status
, INT_TO_PTR(status
)));
199 /* If a daemon does not implement handlers for some of the signals that's not considered an unclean shutdown */
200 if (code
== CLD_KILLED
)
202 (clean
== EXIT_CLEAN_DAEMON
&& IN_SET(status
, SIGHUP
, SIGINT
, SIGTERM
, SIGPIPE
)) ||
204 set_contains(success_status
->signal
, INT_TO_PTR(status
)));
209 void exit_status_set_free(ExitStatusSet
*x
) {
212 x
->status
= set_free(x
->status
);
213 x
->signal
= set_free(x
->signal
);
216 bool exit_status_set_is_empty(ExitStatusSet
*x
) {
220 return set_isempty(x
->status
) && set_isempty(x
->signal
);
223 bool exit_status_set_test(ExitStatusSet
*x
, int code
, int status
) {
225 if (exit_status_set_is_empty(x
))
228 if (code
== CLD_EXITED
&& set_contains(x
->status
, INT_TO_PTR(status
)))
231 if (IN_SET(code
, CLD_KILLED
, CLD_DUMPED
) && set_contains(x
->signal
, INT_TO_PTR(status
)))