terminal: set the pty fd non blocking

This commit is contained in:
Shuanglei Tao
2019-12-05 23:19:34 +08:00
parent ca91f40048
commit cfd338ea5e
4 changed files with 25 additions and 4 deletions

View File

@@ -5,6 +5,7 @@
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/wait.h>
#ifdef __linux__
@@ -85,6 +86,14 @@ get_sig(const char *sig_name) {
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;