diff options
author | Jeremy Allison <jra@samba.org> | 2013-06-10 13:33:40 -0700 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2013-06-20 13:41:01 +0200 |
commit | d4091c5809f174b68714fa50fa501c99617c016e (patch) | |
tree | bf22be9374d71080945945dc914548a39e57c560 /source3 | |
parent | fc13489c91e790ff8952aff1e7db1e6189894e30 (diff) | |
download | samba-d4091c5809f174b68714fa50fa501c99617c016e.tar.gz samba-d4091c5809f174b68714fa50fa501c99617c016e.tar.bz2 samba-d4091c5809f174b68714fa50fa501c99617c016e.zip |
Fix bug #9166 - Starting smbd or nmbd with stdin from /dev/null results in "EOF on stdin"
Only install the stdin handler if it's a pipe or fifo.
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source3')
-rw-r--r-- | source3/nmbd/nmbd.c | 14 | ||||
-rw-r--r-- | source3/smbd/server.c | 14 | ||||
-rw-r--r-- | source3/winbindd/winbindd.c | 15 |
3 files changed, 40 insertions, 3 deletions
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 12afb00993..42e2b2f6ff 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -130,8 +130,20 @@ static bool nmbd_setup_stdin_handler(struct messaging_context *msg, bool foregro /* if we are running in the foreground then look for EOF on stdin, and exit if it happens. This allows us to die if the parent process dies + Only do this on a pipe or socket, no other device. */ - tevent_add_fd(nmbd_event_context(), nmbd_event_context(), 0, TEVENT_FD_READ, nmbd_stdin_handler, msg); + struct stat st; + if (fstat(0, &st) != 0) { + return false; + } + if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { + tevent_add_fd(nmbd_event_context(), + nmbd_event_context(), + 0, + TEVENT_FD_READ, + nmbd_stdin_handler, + msg); + } } return true; diff --git a/source3/smbd/server.c b/source3/smbd/server.c index f07bd28fb4..d3cd33ec90 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -1558,8 +1558,20 @@ extern void build_options(bool screen); /* if we are running in the foreground then look for EOF on stdin, and exit if it happens. This allows us to die if the parent process dies + Only do this on a pipe or socket, no other device. */ - tevent_add_fd(ev_ctx, parent, 0, TEVENT_FD_READ, smbd_stdin_handler, NULL); + struct stat st; + if (fstat(0, &st) != 0) { + return false; + } + if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { + tevent_add_fd(ev_ctx, + parent, + 0, + TEVENT_FD_READ, + smbd_stdin_handler, + NULL); + } } smbd_parent_loop(ev_ctx, parent); diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index 7a0700dffa..141ca5c7c5 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -308,6 +308,8 @@ bool winbindd_setup_stdin_handler(bool parent, bool foreground) bool *is_parent; if (foreground) { + struct stat st; + is_parent = talloc(winbind_event_context(), bool); if (!is_parent) { return false; @@ -318,8 +320,19 @@ bool winbindd_setup_stdin_handler(bool parent, bool foreground) /* if we are running in the foreground then look for EOF on stdin, and exit if it happens. This allows us to die if the parent process dies + Only do this on a pipe or socket, no other device. */ - tevent_add_fd(winbind_event_context(), is_parent, 0, TEVENT_FD_READ, winbindd_stdin_handler, is_parent); + if (fstat(0, &st) != 0) { + return false; + } + if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { + tevent_add_fd(winbind_event_context(), + is_parent, + 0, + TEVENT_FD_READ, + winbindd_stdin_handler, + is_parent); + } } return true; |