1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-09 09:57:48 +03:00
Paulo Alcantara 41aa55f492 s3: util: Do not take over stderr when there is no log file
In case we don't have either a /var/log/samba directory, or pass a
non-existent log directory through '-l' option, all commands that are
daemonized with '-D' option hang when executed within a subshell.

An example on how to trigger that:

  # rm -r /var/log/samba
  # s=$(nmbd -D -s /etc/samba/smb.conf -l /foo123)
  (never returns)

So, when the above command is executed within a subshell the following
happens:

  (a) Parent shell creates a pipe, sets write side of it to fd 1
    (stdout), call read() on read-side fd, forks off a new child process
    and then executes nmbd in it.
  (b) nmbd sets up initial logging to go through fd 1 (stdout) by
    calling setup_logging(..., DEBUG_DEFAULT_STDOUT). 'state.fd' is now
    set to 1.
  (c) reopen_logs() is called by the first time which then calls
    reopen_logs_internal()
  (d) in reopen_logs_internal(), it attempts to create log.nmbd file in
    /foo123 directory and fails because directory doesn't exist.
  (e) Regardless whether the log file was created or not, it calls
    dup2(state.fd, 2) which dups fd 1 into fd 2.
  (f) At some point, fd 0 and 1 are closed and set to /dev/null

The problem with that is because parent shell in (a) is still blocked in
read() call and the new write side of the pipe is now fd 2 -- after
dup2() in (e) -- and remains unclosed.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13578

Signed-off-by: Paulo Alcantara <palcantara@suse.de>
Reviewed-by: Jim McDonough <jmcd@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat Aug 18 01:32:25 CEST 2018 on sn-devel-144
2018-08-18 01:32:25 +02:00
..
2016-11-16 12:41:09 +01:00
2016-05-04 01:28:23 +02:00
2016-05-04 01:28:23 +02:00
2017-08-17 08:00:23 +02:00
2016-12-02 09:36:08 +01:00
2015-07-01 17:12:48 +02:00
2017-01-22 18:30:11 +01:00
2018-05-16 07:02:20 +02:00
2015-10-13 04:25:38 +02:00
2015-10-13 04:25:38 +02:00
2017-04-18 22:54:15 +02:00
2017-04-18 22:54:15 +02:00
2017-11-20 21:41:14 +01:00
2016-06-07 14:34:10 +02:00
2017-03-28 17:45:18 +02:00
2018-02-22 06:13:49 +01:00
2017-03-20 12:20:08 +01:00
2015-07-07 23:51:23 +02:00
2017-01-22 18:30:11 +01:00
2017-01-22 18:30:11 +01:00
2015-10-13 01:23:07 +02:00
2015-10-13 01:23:07 +02:00
2015-02-13 23:32:07 +01:00
2015-07-07 23:51:23 +02:00
2015-07-07 23:51:23 +02:00
2017-09-26 04:38:59 +02:00
2014-12-07 00:12:07 +01:00
2011-02-10 06:51:07 +01:00
2017-03-28 17:45:19 +02:00
2016-04-19 09:37:14 +02:00
2017-10-27 20:33:25 +02:00

This directory contains libutil (until we can think of a better name)

The idea is that this library contains simple but useful data structures 
and support functions that are generally useful; not just for Samba but for 
other projects as well. Functions here should not depend on any external 
libraries, just on libc (perhaps partially provided by libreplace).