summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-07-29 20:42:18 +0200
committerJeremy Allison <jra@samba.org>2014-08-01 22:11:46 +0200
commitb310ea63536dd81fee6c5c94dac4666aa7080f1f (patch)
tree32929083b5ef4a8b34d0b2f6004d12349de9c0f0 /lib
parent2dd8b6b25c76bd426ea0ed9fa9cce6cc09297503 (diff)
downloadsamba-b310ea63536dd81fee6c5c94dac4666aa7080f1f.tar.gz
lib: Use close_low_fd in close_low_fds
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/util/become_daemon.c52
1 files changed, 19 insertions, 33 deletions
diff --git a/lib/util/become_daemon.c b/lib/util/become_daemon.c
index eba0cae579e..d940cd7d33e 100644
--- a/lib/util/become_daemon.c
+++ b/lib/util/become_daemon.c
@@ -77,42 +77,28 @@ _PUBLIC_ int close_low_fd(int fd)
_PUBLIC_ void close_low_fds(bool stdin_too, bool stdout_too, bool stderr_too)
{
-#ifndef VALGRIND
- int fd;
- int i;
-
- if (stdin_too)
- close(0);
- if (stdout_too)
- close(1);
-
- if (stderr_too)
- close(2);
-
- /* try and use up these file descriptors, so silly
- library routines writing to stdout etc won't cause havoc */
- for (i=0;i<3;i++) {
- if (i == 0 && !stdin_too)
- continue;
- if (i == 1 && !stdout_too)
- continue;
- if (i == 2 && !stderr_too)
- continue;
-
- fd = open("/dev/null",O_RDWR,0);
- if (fd < 0)
- fd = open("/dev/null",O_WRONLY,0);
- if (fd < 0) {
- DEBUG(0,("Can't open /dev/null\n"));
- return;
+
+ if (stdin_too) {
+ int ret = close_low_fd(0);
+ if (ret != 0) {
+ DEBUG(0, ("%s: close_low_fd(0) failed: %s\n",
+ __func__, strerror(ret)));
}
- if (fd != i) {
- DEBUG(0,("Didn't get file descriptor %d\n",i));
- close(fd);
- return;
+ }
+ if (stdout_too) {
+ int ret = close_low_fd(1);
+ if (ret != 0) {
+ DEBUG(0, ("%s: close_low_fd(1) failed: %s\n",
+ __func__, strerror(ret)));
+ }
+ }
+ if (stderr_too) {
+ int ret = close_low_fd(2);
+ if (ret != 0) {
+ DEBUG(0, ("%s: close_low_fd(2) failed: %s\n",
+ __func__, strerror(ret)));
}
}
-#endif
}
/****************************************************************************