diff options
author | Rob Landley <rob@landley.net> | 2014-10-14 14:16:34 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-10-14 14:16:34 -0500 |
commit | 784eb9c2d2cbd8ec49ff40dbaba17f4407f3b85a (patch) | |
tree | 56c9c74095322626deecff444d10f2d706a32306 /lib | |
parent | 1796626d9e7a4df3705ef83dbf278d248756692b (diff) | |
download | toybox-784eb9c2d2cbd8ec49ff40dbaba17f4407f3b85a.tar.gz toybox-784eb9c2d2cbd8ec49ff40dbaba17f4407f3b85a.tar.bz2 toybox-784eb9c2d2cbd8ec49ff40dbaba17f4407f3b85a.zip |
Use O_CLOEXEC instead of O_RDONLY to signal loopfiles_rw() to close filehandles.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lib.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -421,8 +421,8 @@ void poke(void *ptr, uint64_t val, int size) // flags is O_RDONLY, stdout otherwise. An empty argument list calls // function() on just stdin/stdout. // -// Note: read only filehandles are automatically closed when function() -// returns, but writeable filehandles must be close by function() +// Note: pass O_CLOEXEC to automatically close filehandles when function() +// returns, otherwise filehandles must be closed by function() void loopfiles_rw(char **argv, int flags, int permissions, int failok, void (*function)(int fd, char *name)) { @@ -441,14 +441,14 @@ void loopfiles_rw(char **argv, int flags, int permissions, int failok, continue; } function(fd, *argv); - if (flags == O_RDONLY) close(fd); + if (flags & O_CLOEXEC) close(fd); } while (*++argv); } -// Call loopfiles_rw with O_RDONLY and !failok (common case). +// Call loopfiles_rw with O_RDONLY|O_CLOEXEC and !failok (common case). void loopfiles(char **argv, void (*function)(int fd, char *name)) { - loopfiles_rw(argv, O_RDONLY, 0, 0, function); + loopfiles_rw(argv, O_RDONLY|O_CLOEXEC, 0, 0, function); } // Slow, but small. |