I only had a quick glance, but have a couple of questions:

a) is popen() not suitable for some reason? it's a little less efficient 
(since it starts a shell to interpret the command line passed in) but 
your code would be much simpler.

b) are you sure you need to close the file handles and reset signal 
handlers yourself? from the execve() man page:

"execve() does not return on success, and the text, data, bss, and stack 
of the calling process are overwritten by that of the program loaded. 
The program invoked inherits the calling process's PID, and any open 
file descriptors that are not set to close-on-exec. Signals pending on 
the calling process are cleared. Any signals set to be caught by the 
calling process are reset to their default behaviour. The SIGCHLD signal 
(when set to SIG_IGN) may or may not be reset to SIG_DFL."

Sounds like execve is doing both for you. It'd be easy to verify - write 
a little external program that dumps the open fds and signal handlers 
when it starts.

-- Paul

Rainer Gerhards wrote:
> Hi all,
> 
> a forum post made me (again) aware of functionality missing in rsyslog:
> 
> http://kb.monitorware.com/problem-to-migrate-from-syslog-ng-to-rsyslog-t8982.
> html
> 
> That is the execution of a program which receives all log messages passed in
> via stdin. I have now done a first, rough, implementation of "omprog" which
> shall provide this feature. 
> 
> I would appreciate if some could quickly review the code, especially lines 97
> to 135, where I clean up after fork and before I exec the program. The code
> can be found here:
> 
> http://git.adiscon.com/?p=rsyslog.git;a=blob;f=plugins/omprog/omprog.c;h=2a07
> 8a6d862c2230a8caa9a489e08a7b5ea4cb29;hb=refs/heads/omprog#l97
> 
> There are three questions that I have:
> 
> 1. is the method used sufficiently secure?
> 2. is there a better way to close open file handles
> 3. am I resetting the sigaction() correctly?
> 
> Especially #3 puzzles me, because I can not use sigterm to cancel a child
> (via a different bash). Also, waitpid() always returns -1 and tells me "there
> are no children".
> 
> So I am under the impression I am doing something wrong. As I also have
> limited experience in that area of executing external programs, I'd
> appreciate advice from those in the know.
> 
> Feel free to pass this along, if you are able to motivate someone else on
> this topic ;)
> 
> Thanks,
> Rainer
> _______________________________________________
> rsyslog mailing list
> http://lists.adiscon.net/mailman/listinfo/rsyslog
> http://www.rsyslog.com

_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com

Reply via email to