newlib: tests for sigchld
This commit is contained in:
parent
f6d44667f2
commit
559e5429ed
@ -4,13 +4,40 @@
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
void sighup(); /* routines child will call upon sigtrap */
|
||||
void sigint();
|
||||
void sigquit();
|
||||
int child, cstatus;
|
||||
|
||||
void sighup() {
|
||||
signal(SIGHUP,sighup); /* reset signal */
|
||||
printf("CHILD: I have received a SIGHUP\n");
|
||||
}
|
||||
|
||||
void sigint() {
|
||||
signal(SIGINT,sigint); /* reset signal */
|
||||
printf("CHILD: I have received a SIGINT\n");
|
||||
}
|
||||
|
||||
void sigquit() {
|
||||
printf("My DADDY has Killed me!!!\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void sigchld() {
|
||||
printf("PARENT: got SIGCHLD\n");
|
||||
#ifdef WITH_SIGCHLD
|
||||
child = wait(&cstatus);
|
||||
if(cstatus == 0)
|
||||
exit(0);
|
||||
else
|
||||
{
|
||||
printf("PARENT: child exited with status %d\n", cstatus);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main() {
|
||||
int pid, p[2], child, cstatus;
|
||||
int pid, p[2];
|
||||
char dummy[1];
|
||||
|
||||
/* get child process */
|
||||
@ -37,6 +64,7 @@ main() {
|
||||
}
|
||||
else /* parent */
|
||||
{
|
||||
signal(SIGCHLD,sigchld);
|
||||
close(p[1]);
|
||||
if(read(p[0], &dummy, 1) > 0){
|
||||
printf("sync read received data");
|
||||
@ -51,6 +79,11 @@ main() {
|
||||
sleep(3); /* pause for 3 secs */
|
||||
printf("\nPARENT: sending SIGQUIT\n\n");
|
||||
kill(pid,SIGQUIT);
|
||||
|
||||
#ifdef WITH_SIGCHLD
|
||||
sleep(10000);
|
||||
exit(1);
|
||||
#else
|
||||
child = wait(&cstatus);
|
||||
if(child == pid && cstatus == 0)
|
||||
exit(0);
|
||||
@ -59,20 +92,6 @@ main() {
|
||||
printf("PARENT: child exited with status %d\n", cstatus);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void sighup() {
|
||||
signal(SIGHUP,sighup); /* reset signal */
|
||||
printf("CHILD: I have received a SIGHUP\n");
|
||||
}
|
||||
|
||||
void sigint() {
|
||||
signal(SIGINT,sigint); /* reset signal */
|
||||
printf("CHILD: I have received a SIGINT\n");
|
||||
}
|
||||
|
||||
void sigquit() {
|
||||
printf("My DADDY has Killed me!!!\n");
|
||||
exit(0);
|
||||
}
|
||||
|
@ -54,6 +54,7 @@
|
||||
"/arch/$ARCH/lib/newlib/libg.a",
|
||||
"-I", "/sys/posix/newlib",
|
||||
"-O2",
|
||||
"-DWITH_SIGCHLD",
|
||||
"-std=gnu11"
|
||||
],
|
||||
"Oflags": [
|
||||
|
45
qa/lib/newlib/libposix_sigchld.c
Normal file
45
qa/lib/newlib/libposix_sigchld.c
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of Jehanne.
|
||||
*
|
||||
* Copyright (C) 2017 Giacomo Tesio <giacomo@tesio.it>
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* Jehanne is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <posix.h>
|
||||
|
||||
static char*
|
||||
qa_exit_translator(int status)
|
||||
{
|
||||
if(jehanne_getpid() == jehanne_getmainpid()){
|
||||
/* the QA test may fork, but only the main process
|
||||
* should return PASS/FAIL
|
||||
*/
|
||||
if(status == 0){
|
||||
jehanne_print("PASS\n");
|
||||
return "PASS";
|
||||
} else {
|
||||
jehanne_print("FAIL: " __POSIX_EXIT_PREFIX "%d\n", status);
|
||||
return "FAIL";
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
void
|
||||
__application_newlib_init(void)
|
||||
{
|
||||
libposix_translate_exit_status(qa_exit_translator);
|
||||
libposix_emulate_SIGCHLD();
|
||||
}
|
Loading…
Reference in New Issue
Block a user