]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/exit-status.c
udev: set errno = ENOSYS for removed interfaces
[thirdparty/systemd.git] / src / exit-status.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
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 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <stdlib.h>
23 #include <sys/wait.h>
24
25 #include "exit-status.h"
26
27 const char* exit_status_to_string(ExitStatus status, ExitStatusLevel level) {
28
29 /* We cast to int here, so that -Wenum doesn't complain that
30 * EXIT_SUCCESS/EXIT_FAILURE aren't in the enum */
31
32 switch ((int) status) {
33
34 case EXIT_SUCCESS:
35 return "SUCCESS";
36
37 case EXIT_FAILURE:
38 return "FAILURE";
39 }
40
41
42 if (level == EXIT_STATUS_SYSTEMD || level == EXIT_STATUS_LSB) {
43 switch ((int) status) {
44
45 case EXIT_CHDIR:
46 return "CHDIR";
47
48 case EXIT_NICE:
49 return "NICE";
50
51 case EXIT_FDS:
52 return "FDS";
53
54 case EXIT_EXEC:
55 return "EXEC";
56
57 case EXIT_MEMORY:
58 return "MEMORY";
59
60 case EXIT_LIMITS:
61 return "LIMITS";
62
63 case EXIT_OOM_ADJUST:
64 return "OOM_ADJUST";
65
66 case EXIT_SIGNAL_MASK:
67 return "SIGNAL_MASK";
68
69 case EXIT_STDIN:
70 return "STDIN";
71
72 case EXIT_STDOUT:
73 return "STDOUT";
74
75 case EXIT_CHROOT:
76 return "CHROOT";
77
78 case EXIT_IOPRIO:
79 return "IOPRIO";
80
81 case EXIT_TIMERSLACK:
82 return "TIMERSLACK";
83
84 case EXIT_SECUREBITS:
85 return "SECUREBITS";
86
87 case EXIT_SETSCHEDULER:
88 return "SETSCHEDULER";
89
90 case EXIT_CPUAFFINITY:
91 return "CPUAFFINITY";
92
93 case EXIT_GROUP:
94 return "GROUP";
95
96 case EXIT_USER:
97 return "USER";
98
99 case EXIT_CAPABILITIES:
100 return "CAPABILITIES";
101
102 case EXIT_CGROUP:
103 return "CGROUP";
104
105 case EXIT_SETSID:
106 return "SETSID";
107
108 case EXIT_CONFIRM:
109 return "CONFIRM";
110
111 case EXIT_STDERR:
112 return "STDERR";
113
114 case EXIT_TCPWRAP:
115 return "TCPWRAP";
116
117 case EXIT_PAM:
118 return "PAM";
119
120 case EXIT_NETWORK:
121 return "NETWORK";
122
123 case EXIT_NAMESPACE:
124 return "NAMESPACE";
125 }
126 }
127
128 if (level == EXIT_STATUS_LSB) {
129 switch ((int) status) {
130
131 case EXIT_INVALIDARGUMENT:
132 return "INVALIDARGUMENT";
133
134 case EXIT_NOTIMPLEMENTED:
135 return "NOTIMPLEMENTED";
136
137 case EXIT_NOPERMISSION:
138 return "NOPERMISSION";
139
140 case EXIT_NOTINSTALLED:
141 return "NOTINSSTALLED";
142
143 case EXIT_NOTCONFIGURED:
144 return "NOTCONFIGURED";
145
146 case EXIT_NOTRUNNING:
147 return "NOTRUNNING";
148 }
149 }
150
151 return NULL;
152 }
153
154
155 bool is_clean_exit(int code, int status) {
156
157 if (code == CLD_EXITED)
158 return status == 0;
159
160 /* If a daemon does not implement handlers for some of the
161 * signals that's not considered an unclean shutdown */
162 if (code == CLD_KILLED)
163 return
164 status == SIGHUP ||
165 status == SIGINT ||
166 status == SIGTERM ||
167 status == SIGPIPE;
168
169 return false;
170 }
171
172 bool is_clean_exit_lsb(int code, int status) {
173
174 if (is_clean_exit(code, status))
175 return true;
176
177 return
178 code == CLD_EXITED &&
179 (status == EXIT_NOTINSTALLED || status == EXIT_NOTCONFIGURED);
180 }