naemon / naemon-core

Networks, Applications and Event Monitor
http://www.naemon.io/
GNU General Public License v2.0
154 stars 63 forks source link

naemon doesn't properly close stdout/stderr/stdin #401

Closed datamuc closed 2 years ago

datamuc commented 2 years ago

Hi,

i think the faulty commit is fa9c19dbf8cc37e3d81b8bb223a81e08ef4bc151.

there are some close(0) .. close(2) lines, they where moved from daemon_init to main. daemon_init is called before init_worker but now the fds are closed after init_worker, so they are only closed in the main process and not in the workers. That leads to the following problem:

code like this does not return:

output=$( ./src/naemon/naemon  -du sample-config/naemon.cfg )

in reality i'm doing output=$( omd restart ) and that doesn't work anymore.

Before this commit it works as expected.

So I think in init_worker you also need to close the fds?

datamuc commented 2 years ago

Before the commit:

$ ./src/naemon/naemon  -du sample-config/naemon.cfg > testdir/output 2>&1
$ fuser testdir/output 
$ 

After this commit:

$ ./src/naemon/naemon  -du sample-config/naemon.cfg > testdir/output 2>&1
$ fuser testdir/output 
/home/danielt/vc/git/naemon-core/testdir/output:  7843  7844  7845  7846  7847  7848  7849  7850  7851
$ ps -fp 7843 
UID        PID  PPID  C STIME TTY          TIME CMD
danielt   7843  7842  0 09:06 ?        00:00:00 /home/danielt/vc/git/naemon-core/src/naemon/.libs/naemon --worker /home/danielt/tmp/naemon/var/naemon.qh
# the others are also workers
sni commented 2 years ago

should be fine now, thanks