Bug 99526 - after call sigaction(), system() return wrong status
Summary: after call sigaction(), system() return wrong status
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 9
Hardware: i686
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-07-21 16:57 UTC by Kun Wei
Modified: 2016-11-24 14:57 UTC (History)
3 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2003-07-22 20:37:46 UTC
Embargoed:


Attachments (Terms of Use)

Description Kun Wei 2003-07-21 16:57:27 UTC
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):
glibc-2.3.2-27.9

How reproducible:
Always

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

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 11:33:01 UTC
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 16:01:17 UTC
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 20:37:46 UTC
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.