From f3b882ba4aff22fe2076028b50a6d469b7da0715 Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Fri, 8 Sep 2017 00:15:12 +0200 Subject: [PATCH] qa: add setsid test to newlib --- qa/lib/newlib/050-setsid.c | 53 +++++++++++++++++++++++++++++++++ qa/lib/newlib/050-setsid.runner | 15 ++++++++++ qa/lib/newlib/build.json | 1 + 3 files changed, 69 insertions(+) create mode 100644 qa/lib/newlib/050-setsid.c create mode 100755 qa/lib/newlib/050-setsid.runner diff --git a/qa/lib/newlib/050-setsid.c b/qa/lib/newlib/050-setsid.c new file mode 100644 index 0000000..5b7f846 --- /dev/null +++ b/qa/lib/newlib/050-setsid.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + pid_t pid; + int p[2], ppgrp, opgrp, npgrp; + char c = '?'; + + if (pipe(p) != 0) + perror("pipe() error"); + else { + ppgrp = getpgrp(); + printf("parent's pid %d; process group id %d\n", getpid(), ppgrp); + if ((pid = fork()) == 0) { + opgrp = getpgrp(); + printf("child's pid %d; process group id %d\n", getpid(), opgrp); + write(p[1], &c, 1); + setsid(); + npgrp = getpgrp(); + if(opgrp == npgrp){ + printf("FAIL: setsid did not changed child's process group id\n"); + exit(EXIT_FAILURE); + } + printf("child's process group id is now %d\n", npgrp); + sleep(5); + exit(EXIT_SUCCESS); + } else { + read(p[0], &c, 1); + sleep(3); + if(ppgrp != getpgrp()){ + printf("FAIL: parent's process group id changed from %d to %d\n", ppgrp, getpgrp()); + exit(EXIT_FAILURE); + } + +#ifndef WITH_SIGCHLD + npgrp = getsid(pid); + if(npgrp < 0){ + printf("FAIL: parent's getsid(%d) failed with errno %d\n", pid, errno); + exit(EXIT_FAILURE); + } + if(npgrp == ppgrp){ + printf("FAIL: parent's getsid(%d) returned old process group id that should be changed\n", pid); + exit(EXIT_FAILURE); + } +#endif + } + } +} diff --git a/qa/lib/newlib/050-setsid.runner b/qa/lib/newlib/050-setsid.runner new file mode 100755 index 0000000..b20c4b5 --- /dev/null +++ b/qa/lib/newlib/050-setsid.runner @@ -0,0 +1,15 @@ +#!/cmd/rc +runner=$0 +test = `{echo $runner|sed 's/.runner//'} +test_output = /tmp/output-`{basename $test} + +if ( test -e $test_output) rm $test_output + +$test $test_output > /dev/null +if ( cat $test_output | grep 'FAIL' > /dev/null ) { + cat $test_output + echo FAIL + exit FAIL +} +echo PASS +exit PASS diff --git a/qa/lib/newlib/build.json b/qa/lib/newlib/build.json index 67356f2..dd65d59 100644 --- a/qa/lib/newlib/build.json +++ b/qa/lib/newlib/build.json @@ -37,6 +37,7 @@ "030-pause.c", "031-setjmp.c", "040-gettimeofday.c", + "050-setsid.c", "100-files.c", "101-files.c", "102-files.c",