[posix] close files on exec (#3977)

This commit adds the *_CLOEXEC flags when opening files. This ensures
files are closed when spawning new processes.

* use LOG_DAEMON as syslog facility
* remove setenv() when forkpty
This commit is contained in:
Yakun Xu
2019-07-12 09:40:06 -07:00
committed by Jonathan Hui
parent cac09b7a70
commit ae014b3f6d
11 changed files with 77 additions and 72 deletions
+6 -6
View File
@@ -1138,7 +1138,7 @@ static bool setup_spi_dev(const char *path)
int ret;
sSpiDevPath = path;
fd = open(path, O_RDWR);
fd = open(path, O_RDWR | O_CLOEXEC);
if (fd < 0)
{
perror("open");
@@ -1212,7 +1212,7 @@ static bool setup_res_gpio(const char *path)
goto bail;
}
setup_fd = open(dir_path, O_WRONLY);
setup_fd = open(dir_path, O_WRONLY | O_CLOEXEC);
if (setup_fd >= 0)
{
@@ -1223,7 +1223,7 @@ static bool setup_res_gpio(const char *path)
}
}
sResGpioValueFd = open(value_path, O_WRONLY);
sResGpioValueFd = open(value_path, O_WRONLY | O_CLOEXEC);
bail:
@@ -1308,7 +1308,7 @@ static bool setup_int_gpio(const char *path)
goto bail;
}
setup_fd = open(dir_path, O_WRONLY);
setup_fd = open(dir_path, O_WRONLY | O_CLOEXEC);
if (setup_fd >= 0)
{
@@ -1322,7 +1322,7 @@ static bool setup_int_gpio(const char *path)
close(setup_fd);
}
setup_fd = open(edge_path, O_WRONLY);
setup_fd = open(edge_path, O_WRONLY | O_CLOEXEC);
if (setup_fd >= 0)
{
@@ -1339,7 +1339,7 @@ static bool setup_int_gpio(const char *path)
setup_fd = -1;
}
sIntGpioValueFd = open(value_path, O_RDONLY);
sIntGpioValueFd = open(value_path, O_RDONLY | O_CLOEXEC);
bail: