]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/exit-status.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include "exit-status.h"
29 const char* exit_status_to_string(ExitStatus status
, ExitStatusLevel level
) {
31 /* We cast to int here, so that -Wenum doesn't complain that
32 * EXIT_SUCCESS/EXIT_FAILURE aren't in the enum */
34 switch ((int) status
) {
44 if (level
== EXIT_STATUS_SYSTEMD
|| level
== EXIT_STATUS_LSB
) {
45 switch ((int) status
) {
68 case EXIT_SIGNAL_MASK
:
89 case EXIT_SETSCHEDULER
:
90 return "SETSCHEDULER";
92 case EXIT_CPUAFFINITY
:
101 case EXIT_CAPABILITIES
:
102 return "CAPABILITIES";
125 case EXIT_NO_NEW_PRIVILEGES
:
126 return "NO_NEW_PRIVILEGES";
131 case EXIT_SELINUX_CONTEXT
:
132 return "SELINUX_CONTEXT";
134 case EXIT_PERSONALITY
:
135 return "PERSONALITY";
137 case EXIT_APPARMOR_PROFILE
:
140 case EXIT_ADDRESS_FAMILIES
:
141 return "ADDRESS_FAMILIES";
143 case EXIT_RUNTIME_DIRECTORY
:
144 return "RUNTIME_DIRECTORY";
149 case EXIT_MAKE_STARTER
:
150 return "MAKE_STARTER";
152 case EXIT_BUS_ENDPOINT
:
153 return "BUS_ENDPOINT";
155 case EXIT_SMACK_PROCESS_LABEL
:
156 return "SMACK_PROCESS_LABEL";
160 if (level
== EXIT_STATUS_LSB
) {
161 switch ((int) status
) {
163 case EXIT_INVALIDARGUMENT
:
164 return "INVALIDARGUMENT";
166 case EXIT_NOTIMPLEMENTED
:
167 return "NOTIMPLEMENTED";
169 case EXIT_NOPERMISSION
:
170 return "NOPERMISSION";
172 case EXIT_NOTINSTALLED
:
173 return "NOTINSTALLED";
175 case EXIT_NOTCONFIGURED
:
176 return "NOTCONFIGURED";
178 case EXIT_NOTRUNNING
:
187 bool is_clean_exit(int code
, int status
, ExitStatusSet
*success_status
) {
189 if (code
== CLD_EXITED
)
190 return status
== 0 ||
192 set_contains(success_status
->status
, INT_TO_PTR(status
)));
194 /* If a daemon does not implement handlers for some of the
195 * signals that's not considered an unclean shutdown */
196 if (code
== CLD_KILLED
)
203 set_contains(success_status
->signal
, INT_TO_PTR(status
)));
208 bool is_clean_exit_lsb(int code
, int status
, ExitStatusSet
*success_status
) {
210 if (is_clean_exit(code
, status
, success_status
))
214 code
== CLD_EXITED
&&
215 (status
== EXIT_NOTINSTALLED
|| status
== EXIT_NOTCONFIGURED
);
218 void exit_status_set_free(ExitStatusSet
*x
) {
223 x
->status
= x
->signal
= NULL
;
226 bool exit_status_set_is_empty(ExitStatusSet
*x
) {
230 return set_isempty(x
->status
) && set_isempty(x
->signal
);
233 bool exit_status_set_test(ExitStatusSet
*x
, int code
, int status
) {
235 if (exit_status_set_is_empty(x
))
238 if (code
== CLD_EXITED
&& set_contains(x
->status
, INT_TO_PTR(status
)))
241 if (IN_SET(code
, CLD_KILLED
, CLD_DUMPED
) && set_contains(x
->signal
, INT_TO_PTR(status
)))