mirror of
https://github.com/tsl0922/ttyd.git
synced 2026-01-10 12:54:22 +01:00
protocol: cleanup process without hanging
This commit is contained in:
18
src/utils.c
18
src/utils.c
@@ -4,6 +4,8 @@
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#ifdef __linux__
|
||||
// https://github.com/karelzak/util-linux/blob/master/misc-utils/kill.c
|
||||
@@ -83,6 +85,22 @@ get_sig(const char *sig_name) {
|
||||
return atoi(sig_name);
|
||||
}
|
||||
|
||||
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(status)) {
|
||||
status = WTERMSIG(stat);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int
|
||||
open_uri(char *uri) {
|
||||
#ifdef __APPLE__
|
||||
|
||||
Reference in New Issue
Block a user