]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/c: add errexec()
authorKarel Zak <kzak@redhat.com>
Thu, 1 Feb 2018 13:58:52 +0000 (14:58 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 1 Feb 2018 13:58:52 +0000 (14:58 +0100)
The new errexec() macro consolidate and unify the way how util-linux
tools react to failed exec()-like functions:

 * exit code 126 when program located, but not usable
 * exit code 127 when could not find program to exec

The exit codes are compatible with coreutils.

Note that all the change is located in c.h; the file exitcodes.h
contains API specific (mkfs, fsck, ...) codes only.

Addresses: https://github.com/karelzak/util-linux/pull/311
Signed-off-by: Karel Zak <kzak@redhat.com>
include/c.h

index b0670dcaade805c426cd281a47c37e9df4ffe422..c8bcb375b27b012a532e19e8ce3d7f1c2ca1d67d 100644 (file)
@@ -216,6 +216,12 @@ errmsg(char doexit, int excode, char adderr, const char *fmt, ...)
        exit(eval); \
 })
 
+/* After failed execvp() */
+#define EX_EXEC_FAILED         126     /* Program located, but not usable. */
+#define EX_EXEC_ENOENT         127     /* Could not find program to exec.  */
+#define errexec(name)  err(errno == ENOENT ? EX_EXEC_ENOENT : EX_EXEC_FAILED, \
+                       _("failed to execute %s"), name)
+
 
 static inline __attribute__((const)) int is_power_of_2(unsigned long num)
 {