/*--------------------------------------------------------------*/ int main(int argc, char *argv[]) { register int i; int status, count, child, kidpid; int core, sig, ex; char *msg; if ((msg = parse_opts(argc, argv, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } #ifdef UCLINUX maybe_run_child(&do_child, ""); #endif setup(); /* temp file is now open */ /*--------------------------------------------------------------*/ for (i = 0; i < ITER; i++) { if ((kidpid = FORK_OR_VFORK()) == 0) { #ifdef UCLINUX if (self_exec(argv[0], "")) { terror("self_exec failed (may be OK if under stress)"); if (instress()) ok_exit(); forkfail(); } #else do_child(); #endif } if (kidpid < 0) { terror("Fork failed (may be OK if under stress)"); if (instress()) ok_exit(); forkfail(); } count = 0; while ((child = wait(&status)) > 0) { count++; } if (count != 1) { fprintf(temp, "\twrong # children waited on.\n"); fprintf(temp, "\tgot %d, expected %d\n", count, 1); fail_exit(); } /* sig = status & 0177; core = status & 0200; ex = (status & 0xFF00) >> 8; */ /***** LTP Port *****/ sig = WTERMSIG(status); #ifdef WCOREDUMP core = WCOREDUMP(status); #endif ex = WIFEXITED(status); /**************/ if (!core) { fprintf(temp, "\tChild did not return core bit set!\n"); fprintf(temp, "\t iteration %d, exit stat = 0x%x\n", i, status); fprintf(temp, "\tCore = %d, sig = %d, ex = %d\n", core, sig, ex); local_flag = FAILED; } if (sig != SIGIOT) { fprintf(temp, "\tChild did not exit with SIGIOT (%d)\n", SIGIOT); fprintf(temp, "\t iteration %d, exit stat = 0x%x\n", i, status); fprintf(temp, "\tCore = %d, sig = %d, ex = %d\n", core, sig, ex); local_flag = FAILED; } if (local_flag == FAILED) break; } /*--------------------------------------------------------------*/ /* Clean up any files created by test before call to anyfail. */ unlink("core"); anyfail(); /* THIS CALL DOES NOT RETURN - EXITS!! */ return 0; }
/*--------------------------------------------------------------------*/ int main(int argc, char **argv) { /***** BEGINNING OF MAIN. *****/ int pid, npid; int nsig, exno, nexno, status; int ret_val = 0; int core; void chsig(); #ifdef UCLINUX tst_parse_opts(argc, argv, NULL, NULL); maybe_run_child(&do_child, "dd", &temp, &sig); #endif setup(); //tempdir(); /* move to new directory */ 12/20/2003 blenter(); exno = 1; if (sigset(SIGCHLD, chsig) == SIG_ERR) { fprintf(temp, "\tsigset failed, errno = %d\n", errno); fail_exit(); } for (sig = 1; sig < 14; sig++) { fflush(temp); chflag = 0; pid = FORK_OR_VFORK(); if (pid < 0) { forkfail(); } if (pid == 0) { #ifdef UCLINUX if (self_exec(argv[0], "dd", temp, sig) < 0) { tst_brkm(TBROK, NULL, "self_exec FAILED - " "terminating test."); } #else do_child(); #endif } else { //fprintf(temp, "Testing signal %d\n", sig); while (!chflag) /* wait for child */ sleep(1); kill(pid, sig); /* child should ignroe this sig */ kill(pid, SIGCHLD); /* child should exit */ #ifdef BCS while ((npid = wait(&status)) != pid || (npid == -1 && errno == EINTR)) ; if (npid != pid) { fprintf(temp, "wait error: wait returned wrong pid\n"); ret_val = 1; } #else while ((npid = waitpid(pid, &status, 0)) != -1 || errno == EINTR) ; #endif /* nsig = status & 0177; core = status & 0200; nexno = (status & 0xff00) >> 8; */ /***** LTP Port *****/ nsig = WTERMSIG(status); #ifdef WCOREDUMP core = WCOREDUMP(status); #endif nexno = WIFEXITED(status); /***** ** ** *****/ /* nsig is the signal number returned by wait it should be 0, except when sig = 9 */ if ((sig == 9) && (nsig != sig)) { fprintf(temp, "wait error: unexpected signal" " returned when the signal sent was 9" " The status of the process is %d \n", status); ret_val = 1; } if ((sig != 9) && (nsig != 0)) { fprintf(temp, "wait error: unexpected signal " "returned, the status of the process is " "%d \n", status); ret_val = 1; } /* nexno is the exit number returned by wait it should be 1, except when sig = 9 */ if (sig == 9) if (nexno != 0) { fprintf(temp, "signal error: unexpected" " exit number returned when" " signal sent was 9, the status" " of the process is %d \n", status); ret_val = 1; } else; else if (nexno != 1) { fprintf(temp, "signal error: unexpected exit " "number returned,the status of the" " process is %d\n", status); ret_val = 1; } } } if (ret_val) local_flag = FAILED; /*--------------------------------------------------------------------*/ anyfail(); tst_exit(); } /******** END OF MAIN. ********/
/*--------------------------------------------------------------------*/ int main(int argc, char **argv) { /***** BEGINNING OF MAIN. *****/ int core; int pid, npid; int nsig, exno, nexno, status; /*SIGIOT is 6, but since linux doesn't have SIGEMT, just using SIGIOT for place filling */ int signum[15]; int j; int ret_val = 0; #ifdef UCLINUX const char *msg; #endif signum[1] = SIGHUP; signum[2] = SIGINT; signum[3] = SIGQUIT; signum[4] = SIGILL; signum[5] = SIGTRAP; signum[6] = SIGABRT; signum[7] = SIGIOT; signum[8] = SIGFPE; signum[9] = SIGKILL; signum[10] = SIGBUS; signum[11] = SIGSEGV; signum[12] = SIGSYS; signum[13] = SIGPIPE; signum[14] = SIGALRM; #ifdef UCLINUX if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); maybe_run_child(&do_child, "dd", &temp, &sig); #endif setup(); // tempdir(); /* move to new directory */ blenter(); exno = 1; unlink("core"); for (j = 1; j < sizeof(signum) / sizeof(*signum); j++) { sig = signum[j]; if (sig != SIGKILL) #ifndef BCS if (sig != SIGSTOP) #endif if (sigset(sig, SIG_DFL) == SIG_ERR) { fprintf(temp, "\tsigset(%d,,) fails\n", sig); local_flag = FAILED; fail_exit(); } fflush(temp); pid = FORK_OR_VFORK(); if (pid < 0) { forkfail(); } /* * Child process sleeps for up to 3 minutes giving the * parent process a chance to kill it. */ if (pid == 0) { #ifdef UCLINUX if (self_exec(argv[0], "dd", temp, sig) < 0) { tst_resm(TBROK, "self_exec FAILED - " "terminating test."); tst_exit(); tst_exit(); } #else do_child(); #endif } /* * Parent process sends signal to child. */ //fprintf(temp, "Testing signal %d\n", sig); 12/12/02 kill(pid, sig); npid = wait(&status); if (npid != pid) { fprintf(temp, "wait error: unexpected pid returned\n"); ret_val = 1; } /* 12/20/02. nsig = status & 0177; core = status & 0200; nexno = (status & 0xff00) >> 8; */ /***** LTP Port *****/ nsig = WTERMSIG(status); #ifdef WCOREDUMP core = WCOREDUMP(status); #endif nexno = WIFEXITED(status); /***** ** ** *****/ //printf("nsig=%x, core=%x, status=%x\n", nsig,core, status); 12/12/2002 /* to check if the core dump bit has been set, bit # 7 */ /***** LTP Port *****/ /* 12/12/02: [email protected] * SIGILL when is not caught or not ignored it causes * a core dump and program termination. So moved the condition to * else part of the program. * SIGQUIT like SIGABRT normally causes a program to quit and * and dumps core. So moved the condition to else part of the * program. */ /***** ** ** *****/ if (core) { if ((sig == 1) || (sig == 2) /*|| (sig == 3) || */ /*(sig == 4) */ || (sig == 9) || (sig == 13) || (sig == 14) || (sig == 15)) { fprintf(temp, "signal error: core dump bit set for exception number %d\n", sig); ret_val = 1; } } else { if ((sig == 3) || (sig == 4) || (sig == 5) || (sig == 6) || (sig == 7) || (sig == 8) || (sig == 10) || (sig == 11) || (sig == 12)) { fprintf(temp, "signal error: core dump bit not set for exception number %d\n", sig); ret_val = 1; } } /* nsig is the signal number returned by wait */ if (nsig != sig) { fprintf(temp, "wait error: unexpected signal %d returned, expected %d\n", nsig, sig); ret_val = 1; } /* nexno is the exit number returned by wait */ if (nexno != 0) { fprintf(temp, "signal error: unexpected exit number %d returned, expected 0\n", nexno); ret_val = 1; } } unlink("core"); fflush(temp); if (ret_val) local_flag = FAILED; unlink("core"); tst_rmdir(); /*--------------------------------------------------------------------*/ anyfail(); tst_exit(); }