commit:     9bdf33b7308577d2d132677f3f4ed962f08ab831
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 28 05:22:52 2026 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sat Feb 28 05:22:52 2026 +0000
URL:        https://gitweb.gentoo.org/proj/install-xattr.git/commit/?id=9bdf33b7

Exit with status 126 or 127 when posix_spawn fails

This roughly emulates the status codes set by bash under similar
circumstances.

Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 install-xattr.c | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/install-xattr.c b/install-xattr.c
index 7a0a1e5..4b3662f 100644
--- a/install-xattr.c
+++ b/install-xattr.c
@@ -163,22 +163,8 @@ copyxattr(const char *source, const char *target)
        free(lxattr);
 }
 
-
 extern char **environ;
 
-static pid_t
-spawn(char *path, char *argv[])
-{
-       pid_t pid;
-       int r = posix_spawn(&pid, path, NULL, NULL, argv, environ);
-       if (r) {
-               errno = r;
-               return -1;
-       }
-       return pid;
-}
-
-
 int
 main(int argc, char* argv[])
 {
@@ -190,8 +176,9 @@ main(int argc, char* argv[])
 
        argv[0] = getenv("REAL_INSTALL") ?: REAL_INSTALL;
 
-       if (spawn(argv[0], argv) < 0)
-               err(1, "failed to spawn install");
+       int r = posix_spawn(NULL, argv[0], NULL, NULL, argv, environ);
+       if (r)
+               errx(r == ENOENT ? 127 : 126, "failed to spawn install: %s", 
strerror(r));
 
        char *portage_xattr_exclude = getenv("PORTAGE_XATTR_EXCLUDE");
        if (portage_xattr_exclude) {

Reply via email to