Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 99526 - after call sigaction(), system() return wrong status
after call sigaction(), system() return wrong status
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2003-07-21 12:57 EDT by Kun Wei
Modified: 2016-11-24 09:57 EST (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2003-07-22 16:37:46 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Kun Wei 2003-07-21 12:57:27 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461; .NET 
CLR 1.0.3705; .NET CLR 1.1.4322)

Description of problem:
I notice since RH9, the return value of system() doesn't work correctly. The 
following code will print out return 0 or -1 randomly, please help me how to 
solve this problem because I need to check if return value is 0 or -1 to make 
sure system call is fine or not.

It happens since RH9, and it works fine before with all the previous verion 
RedHat. We use RedHat as platform for our world wide services, and hope this 
problem in RH9 can't fixed.

> #include <signal.h>
> main()
> {
>         struct sigaction v_sig;
>         #if !defined(linux)
>                 v_sig.sa_flags =  SA_NOCLDWAIT;
>         #else
>                 v_sig.sa_handler = SIG_IGN;
>         #endif
>         sigaction(SIGCHLD, &v_sig, 0);
>         printf("return %d\n", system("ls -l > /dev/null"));
>         return (0);
> }

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Run the example code above
2. and you will see

Additional info: gnu guys ask me to ask RedHat first because they don't have 
control on glibc.
Comment 1 Jakub Jelinek 2003-07-22 07:33:01 EDT
Setting SIGCHLD to SIG_IGN means children will be automatically reapped.
This includes the child created in system (3), so if waitpid in system happens
to be run when the child is already gone, system will return -1.
Comment 2 Kun Wei 2003-07-22 12:01:17 EDT
The code is to solve the problem of [defunt] because we have a lot of fork in our software, and 
it works well under previous verion of Red Hat - 6.x, 7.x, 8.0. It only has problem in RH9. 
Please let me how I can work around this? I need expert advise. Thanks.
Comment 3 Roland McGrath 2003-07-22 16:37:46 EDT
There is no way to disable SIGCHLD generation and zombie conversion for some
child  processes but not others.  system creates children using fork just as
your program does, so its children are treated the same way.  system failing
with errno set to ECHILD is correct for this case.  If you want children created
by system to have their exit status reported by system, you must reset SIGCHLD
to other than SIG_IGN before calling system.

Note You need to log in before you can comment on or make changes to this bug.