From 1c4dd05f407633b9d8ca156a7ee4984e1b131cf6 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 15 Aug 2020 23:11:09 -0400 Subject: Add 126 to hardcoded stop exits > If a command is not found, the exit status shall be 127. If the > command name is found, but it is not an executable utility, the exit > status shall be 126. Applications that invoke utilities without using > the shell should use these exit status values to report similar errors. [1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02 --- service.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'service.c') diff --git a/service.c b/service.c index e7cfe2f..63a647c 100644 --- a/service.c +++ b/service.c @@ -34,6 +34,11 @@ #include "daemon.h" +enum { + ExitNotFound = 127, + ExitNoExec = 126, +}; + const char *serviceDir = "/"; uid_t serviceUID; gid_t serviceGID; @@ -173,13 +178,13 @@ void serviceStart(struct Service *service) { dup2(service->errPipe[1], STDERR_FILENO); int error = chdir(serviceDir); - if (error) err(StopExit, "%s", serviceDir); + if (error) err(ExitNoExec, "%s", serviceDir); error = setgid(serviceGID); - if (error) err(StopExit, "setgid"); + if (error) err(ExitNoExec, "setgid"); error = setuid(serviceUID); - if (error) err(StopExit, "setuid"); + if (error) err(ExitNoExec, "setuid"); size_t len = 0; char command[ARG_MAX]; @@ -197,7 +202,7 @@ void serviceStart(struct Service *service) { _PATH_BSHELL, "-c", command, service->name, NULL, serviceEnviron ); - err(StopExit, "%s", _PATH_BSHELL); + err(ExitNotFound, "%s", _PATH_BSHELL); } void serviceSignal(struct Service *service, int signal) { @@ -266,7 +271,11 @@ void serviceReap(pid_t pid, int status) { service->state = Stop; if (WIFEXITED(status)) { int exit = WEXITSTATUS(status); - if (exit == StopExit || setTest(&stopExits, exit)) { + if ( + exit == ExitNotFound || + exit == ExitNoExec || + setTest(&stopExits, exit) + ) { service->intent = Stop; } if (exit) { -- cgit 1.4.1 n>
path: root/compat/arc4random_freebsd.h (unfollow)
Commit message (Expand)Author
2020-08-02build: Strip down buildJune McEnroed colspan='3' class='logmsg'> These don't really go together, but...
2021-01-19Match tab following escaped newline in make assignmentsJune McEnroe
Otherwise it ends up going into Shell state.
2021-01-18Allow matching lexers using first input lineJune McEnroe