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";
128 case EXIT_NO_NEW_PRIVILEGES:
129 return "NO_NEW_PRIVILEGES";
136 if (level == EXIT_STATUS_LSB) {
137 switch ((int) status) {
139 case EXIT_INVALIDARGUMENT:
140 return "INVALIDARGUMENT";
142 case EXIT_NOTIMPLEMENTED:
143 return "NOTIMPLEMENTED";
145 case EXIT_NOPERMISSION:
146 return "NOPERMISSION";
148 case EXIT_NOTINSTALLED:
149 return "NOTINSSTALLED";
151 case EXIT_NOTCONFIGURED:
152 return "NOTCONFIGURED";
154 case EXIT_NOTRUNNING:
163 bool is_clean_exit(int code, int status, ExitStatusSet *success_status) {
165 if (code == CLD_EXITED)
166 return status == 0 ||
168 set_contains(success_status->code, INT_TO_PTR(status)));
170 /* If a daemon does not implement handlers for some of the
171 * signals that's not considered an unclean shutdown */
172 if (code == CLD_KILLED)
179 set_contains(success_status->signal, INT_TO_PTR(status)));
184 bool is_clean_exit_lsb(int code, int status, ExitStatusSet *success_status) {
186 if (is_clean_exit(code, status, success_status))
190 code == CLD_EXITED &&
191 (status == EXIT_NOTINSTALLED || status == EXIT_NOTCONFIGURED);
194 int parse_show_status(const char *v, ShowStatus *ret) {
200 if (streq(v, "auto")) {
201 *ret = SHOW_STATUS_AUTO;
204 r = parse_boolean(v);
207 *ret = r ? SHOW_STATUS_YES : SHOW_STATUS_NO;