famzah / popen-noshell

A much faster popen() and system() implementation for Linux
68 stars 13 forks source link

Calling exit vs. _exit in the child process #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The original user comment can be found here:
http://blog.famzah.net/2009/11/20/a-much-faster-popen-and-system-implementation-
for-linux/#comment-2078

The referred page (http://www.unixguide.net/unix/programming/1.1.3.shtml) says 
that _exit() must be used, instead of exit(), in situations like ours. All this 
sounds reasonable, but there are a few more things to consider:
  * we use exit() only for error termination -- testing will require that we manage to fail in the respective code blocks
  * we also use err() to exit on errors -- it must be tested whether it uses exit() or _exit(), and be replaced with a custom macro if exit() is used
  * this needs testing -- I've never had a test scenario where this has caused a problem

Resolution for now is 'do-nothing' until a practical test is shown, where 
exit() gives problems.

Original issue reported on code.google.com by ivan.zah...@gmail.com on 12 Mar 2011 at 11:38

GoogleCodeExporter commented 9 years ago
Hi, I was the one posting on this issue on your blog.

I managed to get a crash when I compile popen_noshell.c in c++ (just a few 
malloc conversions are needed). 
See attached files for details, and
"g++ mytest.cpp popen_noshell.cpp -o mytest && ./mytest"
should lead to a segfault.

Note that if you compile popen_noshell.c as a pure C library and link it with 
mytests.cpp, there is no problem. Obviously there is no such thing as "call 
global object's destructors" in the C version of exit().

Original comment by devoud....@gmail.com on 13 Mar 2011 at 9:07

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thank you for the attached examples. I've fixed the exit() vs. _exit() issue. 
It turned out that err() and errx() are using exit() too, so they needed to be 
wrapped.

Reference: Committed revision 5.

Original comment by ivan.zah...@gmail.com on 18 Mar 2011 at 9:40