Merge pull request #8799 from poettering/exit-status-string
add friendly string support for BSD EX_ exit statusses
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
# Control Group APIs and Delegation
|
||||
|
||||
*Intended audience: hackers working on userspace subsystems that require direct
|
||||
cgroup access, such as container managers and similar.*
|
||||
|
||||
So you are wondering about resource management with systemd, you know Linux
|
||||
control groups (cgroups) a bit and are trying to integrate your software with
|
||||
what systemd has to offer there. Here's a bit of documentation about the
|
||||
|
||||
+107
-20
@@ -1972,7 +1972,9 @@ StandardInputData=SWNrIHNpdHplIGRhIHVuJyBlc3NlIEtsb3BzLAp1ZmYgZWVtYWwga2xvcHAncy
|
||||
|
||||
<listitem><para>Variables read from files specified via <varname>EnvironmentFile=</varname> in the unit file</para></listitem>
|
||||
|
||||
<listitem><para>Variables set by any PAM modules in case <varname>PAMName=</varname> is in effect, cf. <citerefentry project='man-pages'><refentrytitle>pam_env</refentrytitle><manvolnum>8</manvolnum></citerefentry></para></listitem>
|
||||
<listitem><para>Variables set by any PAM modules in case <varname>PAMName=</varname> is in effect,
|
||||
cf. <citerefentry
|
||||
project='man-pages'><refentrytitle>pam_env</refentrytitle><manvolnum>8</manvolnum></citerefentry></para></listitem>
|
||||
</itemizedlist>
|
||||
|
||||
<para>If the same environment variables are set by multiple of these sources, the later source — according to the
|
||||
@@ -1980,7 +1982,8 @@ StandardInputData=SWNrIHNpdHplIGRhIHVuJyBlc3NlIEtsb3BzLAp1ZmYgZWVtYWwga2xvcHAncy
|
||||
<varname>UnsetEnvironment=</varname> are removed again from the compiled environment variable list, immediately
|
||||
before it is passed to the executed process.</para>
|
||||
|
||||
<para>The following select environment variables are set by the service manager itself for each invoked process:</para>
|
||||
<para>The following select environment variables are set or propagated by the service manager for each invoked
|
||||
process:</para>
|
||||
|
||||
<variablelist class='environment-variables'>
|
||||
<varlistentry>
|
||||
@@ -2031,24 +2034,11 @@ StandardInputData=SWNrIHNpdHplIGRhIHVuJyBlc3NlIEtsb3BzLAp1ZmYgZWVtYWwga2xvcHAncy
|
||||
<varlistentry>
|
||||
<term><varname>$XDG_RUNTIME_DIR</varname></term>
|
||||
|
||||
<listitem><para>The directory for volatile state. Set for the
|
||||
user <command>systemd</command> instance, and also in user
|
||||
sessions. See
|
||||
<citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>$XDG_SESSION_ID</varname></term>
|
||||
<term><varname>$XDG_SEAT</varname></term>
|
||||
<term><varname>$XDG_VTNR</varname></term>
|
||||
|
||||
<listitem><para>The identifier of the session, the seat name,
|
||||
and virtual terminal of the session. Set by
|
||||
<citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>
|
||||
for login sessions. <varname>$XDG_SEAT</varname> and
|
||||
<varname>$XDG_VTNR</varname> will only be set when attached to
|
||||
a seat and a tty.</para></listitem>
|
||||
<listitem><para>The directory to use for runtime objects (such as IPC objects) and volatile state. Set for all
|
||||
services run by the user <command>systemd</command> instance, as well as any system services that use
|
||||
<varname>PAMName=</varname> with a PAM stack that includes <command>pam_systemd</command>. See below and
|
||||
<citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry> for more
|
||||
information.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
@@ -2302,6 +2292,11 @@ StandardInputData=SWNrIHNpdHplIGRhIHVuJyBlc3NlIEtsb3BzLAp1ZmYgZWVtYWwga2xvcHAncy
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
<para>For system services, when <varname>PAMName=</varname> is enabled and <command>pam_systemd</command> is part
|
||||
of the selected PAM stack, additional environment variables defined by systemd may be set for
|
||||
services. Specifically, these are <varname>$XDG_SEAT</varname>, <varname>$XDG_VTNR</varname>, see
|
||||
<citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry> for details.</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
@@ -2612,6 +2607,98 @@ StandardInputData=SWNrIHNpdHplIGRhIHVuJyBlc3NlIEtsb3BzLAp1ZmYgZWVtYWwga2xvcHAncy
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
|
||||
<para>Finally, the BSD operating systems define a set of exit codes, typically defined on Linux systems too:</para>
|
||||
|
||||
<table>
|
||||
<title>BSD exit codes</title>
|
||||
<tgroup cols='3'>
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Exit Code</entry>
|
||||
<entry>Symbolic Name</entry>
|
||||
<entry>Description</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>64</entry>
|
||||
<entry><constant>EX_USAGE</constant></entry>
|
||||
<entry>Command line usage error</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>65</entry>
|
||||
<entry><constant>EX_DATAERR</constant></entry>
|
||||
<entry>Data format error</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>66</entry>
|
||||
<entry><constant>EX_NOINPUT</constant></entry>
|
||||
<entry>Cannot open input</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>67</entry>
|
||||
<entry><constant>EX_NOUSER</constant></entry>
|
||||
<entry>Addressee unknown</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>68</entry>
|
||||
<entry><constant>EX_NOHOST</constant></entry>
|
||||
<entry>Host name unknown</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>69</entry>
|
||||
<entry><constant>EX_UNAVAILABLE</constant></entry>
|
||||
<entry>Service unavailable</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>70</entry>
|
||||
<entry><constant>EX_SOFTWARE</constant></entry>
|
||||
<entry>internal software error</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>71</entry>
|
||||
<entry><constant>EX_OSERR</constant></entry>
|
||||
<entry>System error (e.g., can't fork)</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>72</entry>
|
||||
<entry><constant>EX_OSFILE</constant></entry>
|
||||
<entry>Critical OS file missing</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>73</entry>
|
||||
<entry><constant>EX_CANTCREAT</constant></entry>
|
||||
<entry>Can't create (user) output file</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>74</entry>
|
||||
<entry><constant>EX_IOERR</constant></entry>
|
||||
<entry>Input/output error</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>75</entry>
|
||||
<entry><constant>EX_TEMPFAIL</constant></entry>
|
||||
<entry>Temporary failure; user is invited to retry</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>76</entry>
|
||||
<entry><constant>EX_PROTOCOL</constant></entry>
|
||||
<entry>Remote error in protocol</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>77</entry>
|
||||
<entry><constant>EX_NOPERM</constant></entry>
|
||||
<entry>Permission denied</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>78</entry>
|
||||
<entry><constant>EX_CONFIG</constant></entry>
|
||||
<entry>Configuration error</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
||||
+69
-7
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sysexits.h>
|
||||
|
||||
#include "exit-status.h"
|
||||
#include "macro.h"
|
||||
@@ -14,10 +15,21 @@
|
||||
|
||||
const char* exit_status_to_string(int status, ExitStatusLevel level) {
|
||||
|
||||
/* We cast to int here, so that -Wenum doesn't complain that
|
||||
* EXIT_SUCCESS/EXIT_FAILURE aren't in the enum */
|
||||
/* Exit status ranges:
|
||||
*
|
||||
* 0…1 │ ISO C, EXIT_SUCCESS + EXIT_FAILURE
|
||||
* 2…7 │ LSB exit codes for init scripts
|
||||
* 8…63 │ (Currently unmapped)
|
||||
* 64…78 │ BSD defined exit codes
|
||||
* 79…199 │ (Currently unmapped)
|
||||
* 200…241 │ systemd's private error codes (might be extended to 254 in future development)
|
||||
* 242…254 │ (Currently unmapped, but see above)
|
||||
* 255 │ (We should probably stay away from that one, it's frequently used by applications to indicate an
|
||||
* │ exit reason that cannot really be expressed in a single exit status value — such as a propagated
|
||||
* │ signal or such)
|
||||
*/
|
||||
|
||||
switch (status) {
|
||||
switch (status) { /* We always cover the ISO C ones */
|
||||
|
||||
case EXIT_SUCCESS:
|
||||
return "SUCCESS";
|
||||
@@ -26,8 +38,8 @@ const char* exit_status_to_string(int status, ExitStatusLevel level) {
|
||||
return "FAILURE";
|
||||
}
|
||||
|
||||
if (IN_SET(level, EXIT_STATUS_SYSTEMD, EXIT_STATUS_LSB)) {
|
||||
switch (status) {
|
||||
if (IN_SET(level, EXIT_STATUS_SYSTEMD, EXIT_STATUS_LSB, EXIT_STATUS_FULL)) {
|
||||
switch (status) { /* Optionally we cover our own ones */
|
||||
|
||||
case EXIT_CHDIR:
|
||||
return "CHDIR";
|
||||
@@ -151,8 +163,8 @@ const char* exit_status_to_string(int status, ExitStatusLevel level) {
|
||||
}
|
||||
}
|
||||
|
||||
if (level == EXIT_STATUS_LSB) {
|
||||
switch (status) {
|
||||
if (IN_SET(level, EXIT_STATUS_LSB, EXIT_STATUS_FULL)) {
|
||||
switch (status) { /* Optionally we support LSB ones */
|
||||
|
||||
case EXIT_INVALIDARGUMENT:
|
||||
return "INVALIDARGUMENT";
|
||||
@@ -174,6 +186,56 @@ const char* exit_status_to_string(int status, ExitStatusLevel level) {
|
||||
}
|
||||
}
|
||||
|
||||
if (level == EXIT_STATUS_FULL) {
|
||||
switch (status) { /* Optionally, we support BSD exit statusses */
|
||||
|
||||
case EX_USAGE:
|
||||
return "USAGE";
|
||||
|
||||
case EX_DATAERR:
|
||||
return "DATAERR";
|
||||
|
||||
case EX_NOINPUT:
|
||||
return "NOINPUT";
|
||||
|
||||
case EX_NOUSER:
|
||||
return "NOUSER";
|
||||
|
||||
case EX_NOHOST:
|
||||
return "NOHOST";
|
||||
|
||||
case EX_UNAVAILABLE:
|
||||
return "UNAVAILABLE";
|
||||
|
||||
case EX_SOFTWARE:
|
||||
return "SOFTWARE";
|
||||
|
||||
case EX_OSERR:
|
||||
return "OSERR";
|
||||
|
||||
case EX_OSFILE:
|
||||
return "OSFILE";
|
||||
|
||||
case EX_CANTCREAT:
|
||||
return "CANTCREAT";
|
||||
|
||||
case EX_IOERR:
|
||||
return "IOERR";
|
||||
|
||||
case EX_TEMPFAIL:
|
||||
return "TEMPFAIL";
|
||||
|
||||
case EX_PROTOCOL:
|
||||
return "PROTOCOL";
|
||||
|
||||
case EX_NOPERM:
|
||||
return "NOPERM";
|
||||
|
||||
case EX_CONFIG:
|
||||
return "CONFIG";
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@ enum {
|
||||
EXIT_NOTCONFIGURED = 6,
|
||||
EXIT_NOTRUNNING = 7,
|
||||
|
||||
/* The LSB suggests that error codes >= 200 are "reserved". We
|
||||
* use them here under the assumption that they hence are
|
||||
* unused by init scripts. */
|
||||
/* BSD's sysexits.h defines a couple EX_xyz exit codes in the range 64 … 78 */
|
||||
|
||||
/* The LSB suggests that error codes >= 200 are "reserved". We use them here under the assumption that they
|
||||
* hence are unused by init scripts. */
|
||||
EXIT_CHDIR = 200,
|
||||
EXIT_NICE,
|
||||
EXIT_FDS,
|
||||
@@ -81,7 +81,7 @@ typedef enum ExitStatusLevel {
|
||||
EXIT_STATUS_MINIMAL, /* only cover libc EXIT_STATUS/EXIT_FAILURE */
|
||||
EXIT_STATUS_SYSTEMD, /* cover libc and systemd's own exit codes */
|
||||
EXIT_STATUS_LSB, /* cover libc, systemd's own and LSB exit codes */
|
||||
EXIT_STATUS_FULL = EXIT_STATUS_LSB
|
||||
EXIT_STATUS_FULL, /* cover libc, systemd's own, LSB and BSD (EX_xyz) exit codes */
|
||||
} ExitStatusLevel;
|
||||
|
||||
typedef struct ExitStatusSet {
|
||||
|
||||
@@ -518,7 +518,7 @@ _public_ int sd_journal_sendv_with_location(
|
||||
assert_return(iov, -EINVAL);
|
||||
assert_return(n > 0, -EINVAL);
|
||||
|
||||
niov = newa(struct iovec, (n + 3));
|
||||
niov = newa(struct iovec, n + 3);
|
||||
memcpy(niov, iov, sizeof(struct iovec) * n);
|
||||
|
||||
ALLOCA_CODE_FUNC(f, func);
|
||||
|
||||
Reference in New Issue
Block a user