mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-01 06:53:39 +08:00
Revert "fcntl a little less"
This reverts commits:e5362a4ae5
.dd9a26715d
. These commits were incorrect because they stomped other flags, such as O_NONBLOCK.
This commit is contained in:
parent
13c5f93d63
commit
2c7dc98337
|
@ -441,14 +441,13 @@ int main(int argc, char **argv) {
|
||||||
res = reader_read(STDIN_FILENO, {});
|
res = reader_read(STDIN_FILENO, {});
|
||||||
} else {
|
} else {
|
||||||
char *file = *(argv + (my_optind++));
|
char *file = *(argv + (my_optind++));
|
||||||
#if defined(O_CLOEXEC)
|
|
||||||
int fd = open(file, O_RDONLY | O_CLOEXEC);
|
|
||||||
#else
|
|
||||||
int fd = open(file, O_RDONLY);
|
int fd = open(file, O_RDONLY);
|
||||||
#endif
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
perror(file);
|
perror(file);
|
||||||
} else {
|
} else {
|
||||||
|
// OK to not do this atomically since we cannot have gone multithreaded yet.
|
||||||
|
set_cloexec(fd);
|
||||||
|
|
||||||
wcstring_list_t list;
|
wcstring_list_t list;
|
||||||
for (char **ptr = argv + my_optind; *ptr; ptr++) {
|
for (char **ptr = argv + my_optind; *ptr; ptr++) {
|
||||||
list.push_back(str2wcstring(*ptr));
|
list.push_back(str2wcstring(*ptr));
|
||||||
|
|
|
@ -176,10 +176,17 @@ FILE *wfopen(const wcstring &path, const char *mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool set_cloexec(int fd) {
|
bool set_cloexec(int fd) {
|
||||||
int flags = fcntl(fd, F_SETFD, FD_CLOEXEC);
|
// Note we don't want to overwrite existing flags like O_NONBLOCK which may be set. So fetch the
|
||||||
if (flags == -1) return false;
|
// existing flags and OR in our new one.
|
||||||
|
int flags = fcntl(fd, F_GETFD, 0);
|
||||||
|
if (flags < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (flags & FD_CLOEXEC) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return fcntl(fd, F_SETFD, flags | FD_CLOEXEC) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int wopen_internal(const wcstring &pathname, int flags, mode_t mode, bool cloexec) {
|
static int wopen_internal(const wcstring &pathname, int flags, mode_t mode, bool cloexec) {
|
||||||
ASSERT_IS_NOT_FORKED_CHILD();
|
ASSERT_IS_NOT_FORKED_CHILD();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user