diff options
author | Andreas Schneider <asn@samba.org> | 2014-04-10 11:54:03 +0200 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2014-04-14 15:29:18 +0200 |
commit | d242129438adb6560f9c31383981cad46588bd90 (patch) | |
tree | 582c2f3c318be4b3375a2527f1c820ad07c3ecdc /tests/echo_srv.c | |
parent | 32c9508b13218d4594c9991d218c93eff1545c86 (diff) | |
download | socket_wrapper-d242129438adb6560f9c31383981cad46588bd90.tar.gz socket_wrapper-d242129438adb6560f9c31383981cad46588bd90.tar.xz socket_wrapper-d242129438adb6560f9c31383981cad46588bd90.zip |
echo_srv: Improve reopening low fds.
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Reviewed-by: Simo Sorce <idra@samba.org>
Diffstat (limited to 'tests/echo_srv.c')
-rw-r--r-- | tests/echo_srv.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/tests/echo_srv.c b/tests/echo_srv.c index 59d5680..9102a87 100644 --- a/tests/echo_srv.c +++ b/tests/echo_srv.c @@ -89,6 +89,7 @@ static int become_daemon(struct echo_srv_opts *opts) int ret; pid_t child_pid; int fd; + int i; if (getppid() == 1) { return 0; @@ -126,14 +127,22 @@ static int become_daemon(struct echo_srv_opts *opts) close(fd); } - fd = open("/dev/null", O_RDWR); - if (fd == -1) { - ret = errno; - perror("open"); - return ret; + for (i = 0; i < 3; i++) { + fd = open("/dev/null", O_RDWR, 0); + if (fd < 0) { + fd = open("/dev/null", O_WRONLY, 0); + } + if (fd < 0) { + ret = errno; + perror("Can't open /dev/null"); + return ret; + } + if (fd != i) { + perror("Didn't get correct fd"); + close(fd); + return EINVAL; + } } - dup(fd); - dup(fd); umask(0177); return 0; |