Menu

#1 Failed exec of external commands leaves child procs

v1.5b
open-accepted
Other (1)
5
2007-07-22
2007-07-22
No

There seems to be a problem with incorrect error handling of failed exec() calls within logsurfer.

I a configuration file is using external commands (e.g. by using the "exec" or "report" keyword) but this external commands does not exist then an error message is created during runtime.
Depending on the used keyword you'll either see "can't exec cmd: ..." or "can't exec reprt-cmd:". Checking the ps output will now show additional logsurfer processes which won't terminate.

This has been reported on Solaris 10.

The used example configuration file (log.conf) for testing (/bin/cat has been replaced by the not existant /bin/nocat):
---------------------------------------------------
'.*' - - - 0 continue open '.*' - 100 10800 1800 ignore
'finish' - - - 0 report '/bin/nocat' '.*'
---------------------------------------------------

The used input file for testing:
---------------------------------------------------
line 1
line 2
finish
foo
bar
finish
---------------------------------------------------

Invocation of logsurfer:
---------------------------------------------------
/usr/local/bin/logsurfer -c log.conf -f input
can't exec reprt-cmd: /bin/nocat
can't exec reprt-cmd: /bin/nocat
can't exec reprt-cmd: /bin/nocat
---------------------------------------------------

As a result the following processes are visible:
---------------------------------------------------
1564 csh
2401 /usr/local/bin/logsurfer -c log.conf -f input
2402 /usr/local/bin/logsurfer -c log.conf -f input
2403 /usr/local/bin/logsurfer -c log.conf -f input
2404 /usr/local/bin/logsurfer -c log.conf -f input
---------------------------------------------------

Discussion

  • Wolfgang Ley

    Wolfgang Ley - 2007-07-22

    patch for exec problem

     
  • Wolfgang Ley

    Wolfgang Ley - 2007-07-22

    Logged In: YES
    user_id=1028391
    Originator: YES

    The bug is in src/exec.c and src/report.c when execv() is being called in the new created child. If the execv() fails (for whatever reasons) the child process will simply return instead of using _exit.

    Adding the _exit() call to the three relevant code paths with execv() solved the problem with dangling child processes but revealed another problem with handling pipes (used by the "pipe" and "report" actions). The default signal action of a SIGPIPE causes logsurfer to exit if we try to communicate with the non-existant external command. I also changed logsurfer to ignore SIGPIPE.

    The problem now is to get these changes back in the source without loosing compatiblity with certain OS releases (e.g. we currently don't use errno.h and the external errno variable as this is not defined by all supported platforms).
    I've attachad a quick and dirty fix for logsurfer 1.5b to address the issue. The final fix might be slightly different to handle the errno issue.

    To patch logsurfer: download the attached patchfile, go in the extracted source, invoke "patch < exec-patch" and recompile logsurfer.
    File Added: exec-patch

     
  • Wolfgang Ley

    Wolfgang Ley - 2007-07-22
    • assigned_to: nobody --> drusus
    • status: open --> open-accepted
     

Log in to post a comment.

MongoDB Logo MongoDB