summaryrefslogtreecommitdiffstats
path: root/fish/fish.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-03-14 19:30:46 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-03-14 19:30:46 +0000
commit606732d02e678161ff433040a21d54fc2ea8bb43 (patch)
tree7549558e51d1dd45a45e71ce219084e368eb845d /fish/fish.c
parent13e7a1b400b7e2a5e9335d25205b09e74c89d858 (diff)
downloadlibguestfs-606732d02e678161ff433040a21d54fc2ea8bb43.tar.gz
libguestfs-606732d02e678161ff433040a21d54fc2ea8bb43.tar.xz
libguestfs-606732d02e678161ff433040a21d54fc2ea8bb43.zip
Use O_CLOEXEC / SOCK_CLOEXEC for almost all file descriptors.
The presumption is that all file descriptors should be created with the close-on-exec flag set. The only exception are file descriptors that we want passed through to exec'd subprocesses (mainly pipes and stdin/stdout/stderr). For open calls, we pass O_CLOEXEC as an extra flag, eg: fd = open ("foo", O_RDONLY|O_CLOEXEC); This is a Linux-ism, but using a macro we can easily make it portable. For sockets, similarly: sock = socket (..., SOCK_STREAM|SOCK_CLOEXEC, ...); For accepted sockets, we use the Linux accept4 system call which allows flags to be supplied, but we use the Gnulib 'accept4' module to make this portable. For dup, dup2, we use the Linux dup3 system call, and the Gnulib modules 'dup3' and 'cloexec'.
Diffstat (limited to 'fish/fish.c')
-rw-r--r--fish/fish.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/fish/fish.c b/fish/fish.c
index 8bfea325..a83f7021 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -501,7 +501,7 @@ main (int argc, char *argv[])
/* -f (file) parameter? */
if (file) {
close (0);
- if (open (file, O_RDONLY) == -1) {
+ if (open (file, O_RDONLY|O_CLOEXEC) == -1) {
perror (file);
exit (EXIT_FAILURE);
}
@@ -1436,7 +1436,7 @@ cleanup_readline (void)
int fd;
if (histfile[0] != '\0') {
- fd = open (histfile, O_WRONLY|O_CREAT, 0644);
+ fd = open (histfile, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0644);
if (fd == -1) {
perror (histfile);
return;