• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
3  * Created by:  Rusty.Lynch REMOVE-THIS AT intel DOT com
4  * This file is licensed under the GPL license.  For the full content
5  * of this license, see the COPYING file at the top level of this
6  * source tree.
7 
8   Test assertion #11 by verifying that SIGCHLD signals are sent to a parent
9   when their children are continued after being stopped.
10 
11   NOTE: This is only required to work if the XSI options are implemented.
12  * 12/18/02 - Adding in include of sys/time.h per
13  *            rodrigc REMOVE-THIS AT attbi DOT com input that it needs
14  *            to be included whenever the timeval struct is used.
15  *
16 */
17 
18 #include <signal.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <sys/select.h>
22 #include <sys/wait.h>
23 #include <sys/time.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include "posixtest.h"
27 
28 #define NUMSTOPS 2
29 
30 static volatile int child_continued;
31 static volatile int waiting = 1;
32 
handler(int signo PTS_ATTRIBUTE_UNUSED,siginfo_t * info,void * context PTS_ATTRIBUTE_UNUSED)33 static void handler(int signo PTS_ATTRIBUTE_UNUSED, siginfo_t *info,
34 	void *context PTS_ATTRIBUTE_UNUSED)
35 {
36 	if (info && info->si_code == CLD_CONTINUED) {
37 		printf("Child has been stopped\n");
38 		waiting = 0;
39 		child_continued++;
40 	}
41 }
42 
main(void)43 int main(void)
44 {
45 	pid_t pid;
46 	struct sigaction act;
47 	struct timeval tv;
48 
49 	act.sa_sigaction = handler;
50 	act.sa_flags = SA_SIGINFO;
51 	sigemptyset(&act.sa_mask);
52 	sigaction(SIGCHLD, &act, 0);
53 
54 	if ((pid = fork()) < 0) {
55 		printf("fork() did not return success\n");
56 		return PTS_UNRESOLVED;
57 	} else if (pid == 0) {
58 		/* child */
59 		while (1) {
60 			/* wait forever, or until we are
61 			   interrupted by a signal */
62 			tv.tv_sec = 0;
63 			tv.tv_usec = 0;
64 			select(0, NULL, NULL, NULL, &tv);
65 		}
66 		return 0;
67 	} else {
68 		/* parent */
69 		int s;
70 		int i;
71 
72 		/* delay to allow child to get into select call */
73 		tv.tv_sec = 1;
74 		tv.tv_usec = 0;
75 		select(0, NULL, NULL, NULL, &tv);
76 
77 		for (i = 0; i < NUMSTOPS; i++) {
78 			struct timeval tv;
79 			printf("--> Sending SIGSTOP\n");
80 			kill(pid, SIGSTOP);
81 
82 			/*
83 			   Don't let the kernel optimize away queued
84 			   SIGSTOP/SIGCONT signals.
85 			 */
86 			tv.tv_sec = 1;
87 			tv.tv_usec = 0;
88 			select(0, NULL, NULL, NULL, &tv);
89 
90 			printf("--> Sending SIGCONT\n");
91 			waiting = 1;
92 			kill(pid, SIGCONT);
93 			while (waiting) {
94 				tv.tv_sec = 1;
95 				tv.tv_usec = 0;
96 				if (!select(0, NULL, NULL, NULL, &tv))
97 					break;
98 			}
99 
100 		}
101 
102 		kill(pid, SIGKILL);
103 		waitpid(pid, &s, 0);
104 	}
105 
106 	if (child_continued == NUMSTOPS) {
107 		printf("Test PASSED\n");
108 		printf
109 		    ("In the section of the POSIX spec that describes the SA_NOCLDSTOP flag in the sigaction() interface "
110 		     "it is specified that if the SA_NOCLDSTOP flag is not set in sa_flags, then a SIGCHLD and a SIGCHLD "
111 		     "signal **MAY** be generated for the calling process whenever any of its stopped child processes are continued. "
112 		     "Because of that, this test will PASS either way, but note that the signals implementation you are currently "
113 		     "run this test on DOES choose to send a SIGCHLD signal whenever any of its stopped child processes are "
114 		     "continued. Again, this is not a bug because of the existence of the word *MAY* in the spec.\n");
115 		return PTS_PASS;
116 	}
117 
118 	printf("Test PASSED\n");
119 
120 	printf
121 	    ("In the section of the POSIX spec that describes the SA_NOCLDSTOP flag in the sigaction() interface "
122 	     "it is specified that if the SA_NOCLDSTOP flag is not set in sa_flags, then a SIGCHLD and a SIGCHLD "
123 	     "signal **MAY** be generated for the calling process whenever any of its stopped child processes are continued. "
124 	     "Because of that, this test will PASS either way, but note that the signals implementation you are currently "
125 	     "run this test on chooses NOT TO send a SIGCHLD signal whenever any of its stopped child processes are "
126 	     "continued. Again, this is not a bug because of the existence of the word *MAY* in the spec.\n");
127 	return PTS_PASS;
128 }
129