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
This commit is contained in:
parent
1eb6eb6d37
commit
1c4dd05f40
@ -122,8 +122,8 @@ The default list contains the values of
|
|||||||
.Dv EX_CANTCREAT
|
.Dv EX_CANTCREAT
|
||||||
defined in
|
defined in
|
||||||
.Xr sysexits 3 .
|
.Xr sysexits 3 .
|
||||||
The exit status 127
|
The exit statuses 127 and 126
|
||||||
is always treated as a stop exit.
|
are always treated as stop exits.
|
||||||
.
|
.
|
||||||
.It Fl t Ar restart
|
.It Fl t Ar restart
|
||||||
Set the initial interval in milliseconds
|
Set the initial interval in milliseconds
|
||||||
|
1
daemon.h
1
daemon.h
@ -154,7 +154,6 @@ static inline uint32_t setTest(const struct Set256 *set, byte x) {
|
|||||||
return set->bits[x / 32] & (1 << (uint32_t)(x & 31));
|
return set->bits[x / 32] & (1 << (uint32_t)(x & 31));
|
||||||
}
|
}
|
||||||
|
|
||||||
enum { StopExit = 127 };
|
|
||||||
extern struct Set256 stopExits;
|
extern struct Set256 stopExits;
|
||||||
extern struct timespec restartInterval;
|
extern struct timespec restartInterval;
|
||||||
extern struct timespec resetInterval;
|
extern struct timespec resetInterval;
|
||||||
|
19
service.c
19
service.c
@ -34,6 +34,11 @@
|
|||||||
|
|
||||||
#include "daemon.h"
|
#include "daemon.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ExitNotFound = 127,
|
||||||
|
ExitNoExec = 126,
|
||||||
|
};
|
||||||
|
|
||||||
const char *serviceDir = "/";
|
const char *serviceDir = "/";
|
||||||
uid_t serviceUID;
|
uid_t serviceUID;
|
||||||
gid_t serviceGID;
|
gid_t serviceGID;
|
||||||
@ -173,13 +178,13 @@ void serviceStart(struct Service *service) {
|
|||||||
dup2(service->errPipe[1], STDERR_FILENO);
|
dup2(service->errPipe[1], STDERR_FILENO);
|
||||||
|
|
||||||
int error = chdir(serviceDir);
|
int error = chdir(serviceDir);
|
||||||
if (error) err(StopExit, "%s", serviceDir);
|
if (error) err(ExitNoExec, "%s", serviceDir);
|
||||||
|
|
||||||
error = setgid(serviceGID);
|
error = setgid(serviceGID);
|
||||||
if (error) err(StopExit, "setgid");
|
if (error) err(ExitNoExec, "setgid");
|
||||||
|
|
||||||
error = setuid(serviceUID);
|
error = setuid(serviceUID);
|
||||||
if (error) err(StopExit, "setuid");
|
if (error) err(ExitNoExec, "setuid");
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
char command[ARG_MAX];
|
char command[ARG_MAX];
|
||||||
@ -197,7 +202,7 @@ void serviceStart(struct Service *service) {
|
|||||||
_PATH_BSHELL, "-c", command, service->name, NULL,
|
_PATH_BSHELL, "-c", command, service->name, NULL,
|
||||||
serviceEnviron
|
serviceEnviron
|
||||||
);
|
);
|
||||||
err(StopExit, "%s", _PATH_BSHELL);
|
err(ExitNotFound, "%s", _PATH_BSHELL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serviceSignal(struct Service *service, int signal) {
|
void serviceSignal(struct Service *service, int signal) {
|
||||||
@ -266,7 +271,11 @@ void serviceReap(pid_t pid, int status) {
|
|||||||
service->state = Stop;
|
service->state = Stop;
|
||||||
if (WIFEXITED(status)) {
|
if (WIFEXITED(status)) {
|
||||||
int exit = WEXITSTATUS(status);
|
int exit = WEXITSTATUS(status);
|
||||||
if (exit == StopExit || setTest(&stopExits, exit)) {
|
if (
|
||||||
|
exit == ExitNotFound ||
|
||||||
|
exit == ExitNoExec ||
|
||||||
|
setTest(&stopExits, exit)
|
||||||
|
) {
|
||||||
service->intent = Stop;
|
service->intent = Stop;
|
||||||
}
|
}
|
||||||
if (exit) {
|
if (exit) {
|
||||||
|
Loading…
Reference in New Issue
Block a user