mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
Audit ec25051: service logging support
- Must check return value from open(), found by Coverity Scan - Minor refactor (and cleanup) to reduce code complexity Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
f74a73be20
commit
00e5a8f5d9
1 file changed
+37
-18
@@ -181,27 +181,46 @@ static int service_start(svc_t *svc)
|
|||||||
dup2(STDIN_FILENO, STDERR_FILENO);
|
dup2(STDIN_FILENO, STDERR_FILENO);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (svc->log) {
|
if (svc->log) {
|
||||||
/* Open PTY to connect to logger (A pty isn't buffered like a pipe, and it eats newlines so they aren't logged) */
|
int fd;
|
||||||
int fd = posix_openpt(O_RDWR);
|
|
||||||
|
/*
|
||||||
|
* Open PTY to connect to logger. A pty isn't buffered
|
||||||
|
* like a pipe, and it eats newlines so they aren't logged
|
||||||
|
*/
|
||||||
|
fd = posix_openpt(O_RDWR);
|
||||||
|
if (fd == -1) {
|
||||||
|
svc->log = 0;
|
||||||
|
goto logger_err;
|
||||||
|
}
|
||||||
|
if (grantpt(fd) == -1 || unlockpt(fd) == -1) {
|
||||||
|
close(fd);
|
||||||
|
svc->log = 0;
|
||||||
|
goto logger_err;
|
||||||
|
}
|
||||||
|
|
||||||
/* SIGCHLD is still blocked for grantpt() and fork() */
|
/* SIGCHLD is still blocked for grantpt() and fork() */
|
||||||
sigprocmask(SIG_BLOCK, &nmask, NULL);
|
sigprocmask(SIG_BLOCK, &nmask, NULL);
|
||||||
if (fd >= 0 && grantpt(fd) == 0 && unlockpt(fd) == 0) {
|
pid = fork();
|
||||||
pid = fork();
|
if (pid == 0) {
|
||||||
if (pid == 0) {
|
int fds = open(ptsname(fd), O_RDONLY);
|
||||||
int fds = open(ptsname(fd), O_RDONLY);
|
|
||||||
close(fd);
|
|
||||||
dup2(fds, STDIN_FILENO);
|
|
||||||
|
|
||||||
/* Reset signals */
|
|
||||||
sig_unblock();
|
|
||||||
|
|
||||||
exit(execlp("logger", "logger", "-t", strlen(svc->desc) > 0 ? svc->desc : svc->cmd, (char*)NULL));
|
|
||||||
}
|
|
||||||
dup2(fd, STDOUT_FILENO);
|
|
||||||
dup2(fd, STDERR_FILENO);
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
if (fds == -1)
|
||||||
|
_exit(0);
|
||||||
|
dup2(fds, STDIN_FILENO);
|
||||||
|
|
||||||
|
/* Reset signals */
|
||||||
|
sig_unblock();
|
||||||
|
|
||||||
|
execlp("logger", "logger", "-t", strlen(svc->desc) > 0 ? svc->desc : svc->cmd, NULL);
|
||||||
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dup2(fd, STDOUT_FILENO);
|
||||||
|
dup2(fd, STDERR_FILENO);
|
||||||
|
close(fd);
|
||||||
} else if (debug) {
|
} else if (debug) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
@@ -212,7 +231,7 @@ static int service_start(svc_t *svc)
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger_err:
|
||||||
sig_unblock();
|
sig_unblock();
|
||||||
|
|
||||||
if (svc->inetd.cmd)
|
if (svc->inetd.cmd)
|
||||||
@@ -229,9 +248,9 @@ static int service_start(svc_t *svc)
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (svc->log) {
|
if (svc->log)
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
}
|
|
||||||
exit(status);
|
exit(status);
|
||||||
} else if (debug) {
|
} else if (debug) {
|
||||||
char buf[CMD_SIZE] = "";
|
char buf[CMD_SIZE] = "";
|
||||||
|
|||||||
Reference in new issue
Block a user