uv_signal_start(&pss->watcher, child_cb, SIGCHLD);
+ // ensure the lws socket fd close-on-exec
+ fd_set_cloexec(lws_get_socket_fd(pss->wsi));
+
+ // create process with pseudo-tty
pss->pid = pty_fork(&pss->pty, argv[0], argv, server->terminal_type);
if (pss->pid < 0) {
lwsl_err("pty_fork: %d (%s)\n", errno, strerror(errno));
#include <pty.h>
#endif
+#include "utils.h"
+
pid_t
pty_fork(int *pty, const char *file, char *const argv[], const char *term) {
pid_t pid = forkpty(pty, NULL, NULL, NULL);
}
}
- // set the file descriptor close-on-exec
- int status_flags = fcntl(*pty, F_GETFL);
- if (status_flags != -1) {
- fcntl(*pty, F_SETFD, status_flags | FD_CLOEXEC);
+ // set the file descriptor non blocking
+ int flags = fcntl(*pty, F_GETFL);
+ if (flags != -1) {
+ fcntl(*pty, F_SETFD, flags | O_NONBLOCK);
}
+ // set the file descriptor close-on-exec
+ fd_set_cloexec(*pty);
return pid;
}
#include <string.h>
#include <signal.h>
#include <errno.h>
+#include <fcntl.h>
#include <sys/wait.h>
#ifdef __linux__
return atoi(sig_name);
}
+bool
+fd_set_cloexec(const int fd) {
+ int flags = fcntl(fd, F_GETFD);
+ if (flags < 0)
+ return false;
+ 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;
int
get_sig(const char *sig_name);
+// Set the given file descriptor close-on-exec
+bool
+fd_set_cloexec(const int fd);
+
// waitpid with WNOHANG and return the status
int
wait_proc(pid_t in, pid_t *out);