exit-status.c revision d7832d2c6e0ef5f2839a2296c1cc2fc85c7d9632
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering/***
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering This file is part of systemd.
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering Copyright 2010 Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering systemd is free software; you can redistribute it and/or modify it
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering under the terms of the GNU General Public License as published by
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering the Free Software Foundation; either version 2 of the License, or
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering (at your option) any later version.
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering systemd is distributed in the hope that it will be useful, but
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering General Public License for more details.
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering You should have received a copy of the GNU General Public License
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering***/
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering#include <stdlib.h>
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering#include <sys/wait.h>
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering#include "exit-status.h"
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poetteringconst char* exit_status_to_string(ExitStatus status, ExitStatusLevel level) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering /* We cast to int here, so that -Wenum doesn't complain that
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering * EXIT_SUCCESS/EXIT_FAILURE aren't in the enum */
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering switch ((int) status) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_SUCCESS:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "SUCCESS";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_FAILURE:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "FAILURE";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (level == EXIT_STATUS_SYSTEMD || level == EXIT_STATUS_LSB) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering switch ((int) status) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_CHDIR:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "CHDIR";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_NICE:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "NICE";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_FDS:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "FDS";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_EXEC:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "EXEC";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_MEMORY:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "MEMORY";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_LIMITS:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "LIMITS";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_OOM_ADJUST:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "OOM_ADJUST";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_SIGNAL_MASK:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "SIGNAL_MASK";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_STDIN:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "STDIN";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_STDOUT:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "STDOUT";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_CHROOT:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "CHROOT";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_IOPRIO:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "IOPRIO";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_TIMERSLACK:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "TIMERSLACK";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_SECUREBITS:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "SECUREBITS";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_SETSCHEDULER:
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering return "SETSCHEDULER";
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering case EXIT_CPUAFFINITY:
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering return "CPUAFFINITY";
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering case EXIT_GROUP:
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering return "GROUP";
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering case EXIT_USER:
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering return "USER";
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering case EXIT_CAPABILITIES:
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering return "CAPABILITIES";
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering case EXIT_CGROUP:
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering return "CGROUP";
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering case EXIT_SETSID:
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering return "SETSID";
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_CONFIRM:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "CONFIRM";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_STDERR:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "STDERR";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_TCPWRAP:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "TCPWRAP";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_PAM:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "PAM";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_NETWORK:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "NETWORK";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_NAMESPACE:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "NAMESPACE";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (level == EXIT_STATUS_LSB) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering switch ((int) status) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_INVALIDARGUMENT:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "INVALIDARGUMENT";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_NOTIMPLEMENTED:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "NOTIMPLEMENTED";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_NOPERMISSION:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "NOPERMISSION";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_NOTINSTALLED:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "NOTINSSTALLED";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_NOTCONFIGURED:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "NOTCONFIGURED";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering case EXIT_NOTRUNNING:
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return "NOTRUNNING";
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return NULL;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering}
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poetteringbool is_clean_exit(int code, int status) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (code == CLD_EXITED)
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return status == 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering /* If a daemon does not implement handlers for some of the
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering * signals that's not considered an unclean shutdown */
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (code == CLD_KILLED)
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering status == SIGHUP ||
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering status == SIGINT ||
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering status == SIGTERM ||
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering status == SIGPIPE;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return false;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering}
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poetteringbool is_clean_exit_lsb(int code, int status) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (is_clean_exit(code, status))
12ca818ffddb77eb6a0fabe369a5bcbf6994ff8bLennart Poettering return true;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering code == CLD_EXITED &&
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering (status == EXIT_NOTINSTALLED || status == EXIT_NOTCONFIGURED);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering}
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering