mtest01/mtest01: break test if fork failed
PATCH 1/1 mtest01/mtest01: break test if fork failed
Please review this patch. Thanks.
Or a lot of processes will be killed when -1 being passed as pid to kill().
Signed-off-by Han Pingtian <[email protected]>
--- testcases/kernel/mem/mtest01/mtest01.c | 35 +++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
testcases/kernel/mem/mtest01/mtest01.c +26 -9
@@ -52,6 +52,7 @@ char *TCID = "mtest01";int TST_TOTAL =1 ;static sig_atomic_t pid_count;static sig_atomic_t sigchld_count; +static pid_t *pid_list;static void handler (int signo) {
@@ -60,6 +61,18 @@ static void handler(int signo) pid_count++; } +static void cleanup (void ) +{ +int i =0 ; + +while (pid_list[i] >0 ) { +kill (pid_list[i],9 ); + i++; + } + +free (pid_list); +} +int main (int argc,char *argv[]) {int c;
@@ -73,7 +86,7 @@ int main(int argc, char *argv[])int chunksize =1024 *1024 ;/* one meg at a time by default */ struct sysinfo sstats;int i, pid_cntr; -pid_t pid, *pid_list; +pid_t pid;struct sigaction act; act.sa_handler = handler;
@@ -177,15 +190,20 @@ int main(int argc, char *argv[]) i =0 ; pid_cntr =0 ; pid =fork (); -if (pid !=0 ) +if (pid <0 ) +tst_brkm (TBROK |TERRNO , cleanup,"fork failed" ); +if (pid !=0 ) { pid_cntr++; - pid_list[i] = pid; + pid_list[i] = pid; + }#if defined (_s390_)/* s390's 31bit addressing requires smaller chunks */ while (pid !=0 && maxbytes >FIVE_HUNDRED_MB ) { i++; maxbytes -=FIVE_HUNDRED_MB ; pid =fork (); +if (pid <0 ) +tst_brkm (TBROK |TERRNO , cleanup,"fork failed" );if (pid !=0 ) { pid_cntr++; pid_list[i] = pid;
@@ -201,6 +219,8 @@ int main(int argc, char *argv[]) i++; maxbytes -=ONE_GB ; pid =fork (); +if (pid <0 ) +tst_brkm (TBROK |TERRNO , cleanup,"fork failed" );if (pid !=0 ) { pid_cntr++; pid_list[i] = pid;
@@ -216,6 +236,8 @@ int main(int argc, char *argv[]) i++; maxbytes -=THREE_GB ; pid =fork (); +if (pid <0 ) +tst_brkm (TBROK |TERRNO , cleanup,"fork failed" );if (pid !=0 ) { pid_cntr++; pid_list[i] = pid;
@@ -257,7 +279,6 @@ int main(int argc, char *argv[])while (1 )sleep (1 ); }else { - i =0 ;sysinfo (&sstats);if (dowrite) {
@@ -295,11 +316,7 @@ int main(int argc, char *argv[]) original_maxbytes / 1024); } -while (pid_list[i] !=0 ) { -kill (pid_list[i],SIGKILL ); - i++; - } } -free (pid_list); +cleanup ();tst_exit (); }
Signature · 1 line
1.9.3
PATCH 1/1 mtest01/mtest01: break test if fork failed
Hi!
testcases/kernel/mem/mtest01/mtest01.c static void handler(int signo) · line 69
Quoted 2 lines
testcases/kernel/mem/mtest01/mtest01.c +2
-0+while (pid_list[i] >0 ) { +kill (pid_list[i],9 );
^
I've changed this back to SIGKILL and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]