server: improve child process handling

This commit is contained in:
Shuanglei Tao
2019-12-11 00:09:54 +08:00
parent 397b24f138
commit b67e382ab8
6 changed files with 700 additions and 98 deletions

View File

@@ -4,9 +4,7 @@
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/wait.h>
#ifdef __linux__
// https://github.com/karelzak/util-linux/blob/master/misc-utils/kill.c
@@ -94,22 +92,6 @@ fd_set_cloexec(const int fd) {
return (flags & FD_CLOEXEC) == 0 || fcntl(fd, F_SETFD, flags | FD_CLOEXEC) != -1;
}
int
wait_proc(pid_t in, pid_t *out) {
int stat = 0, pid;
do {
pid = waitpid(in, &stat, WNOHANG);
} while (pid < 0 && errno == EINTR);
if (out != NULL) *out = pid;
int status = -1;
if (WIFEXITED(stat)) {
status = WEXITSTATUS(stat);
} else if (WIFSIGNALED(stat)) {
status = WTERMSIG(stat);
}
return status;
}
int
open_uri(char *uri) {
#ifdef __APPLE__