6-1.c revision 0dc076565f772bb1953209fb69ea150b494aaa40
1/*
2 * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
3 * Created by:  salwan.searty 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 This program verifies that if the value of pid causes signo to be
9 generated for the sending process, and if signo is not blocked for
10 the calling thread and if no other thread has signo unblocked or is
11 waiting in a sigwait( ) function for signo, then signal SIGTOTEST
12 is delivered to the calling thread before the sigqueue( ) function returns.
13
14 Steps:
15 - Register for myhandler to be called when SIGTOTEST is called, and make
16   sure SA_SIGINFO is set.
17 - Using sigqueue(), send SIGTOTEST to the current process.
18 - Inside handler, verify that the global return_val variable has not been
19   set yet to the return value of sigqueue. If it has, then that means that
20   sigqueu has returned before the handler finished executing, and thus is
21   a FAILED test.
22 - Also before the program ends, verify that the handler
23   has been called.
24 */
25
26#define _XOPEN_SOURCE 600
27#define _XOPEN_REALTIME 1
28#define SIGTOTEST SIGRTMIN
29#define NUMCALLS 5
30
31#include <signal.h>
32#include <stdio.h>
33#include <unistd.h>
34#include <stdlib.h>
35#include <errno.h>
36#include "posixtest.h"
37
38int return_val = 1;
39int handler_called = 0;
40
41void myhandler(int signo, siginfo_t *info, void *context) {
42	handler_called = 1;
43	if (return_val != 1) {
44		printf("Test FAILED: sigqueue() seems to have returned before handler finished executing.\n");
45		exit(1);
46	}
47}
48
49int main()
50{
51	int pid;
52	union sigval value;
53	struct sigaction act;
54
55	act.sa_flags = SA_SIGINFO;
56	act.sa_sigaction = myhandler;
57	sigemptyset(&act.sa_mask);
58	sigaction(SIGTOTEST, &act, 0);
59
60	value.sival_int = 0;	/* 0 is just an arbitrary value */
61	pid = getpid();
62
63	if ((return_val = sigqueue(pid, SIGTOTEST, value)) != 0) {
64		printf("Test UNRESOLVED: call to sigqueue did not return success\n");
65		return PTS_UNRESOLVED;
66	}
67
68	if (handler_called != 1) {
69		printf("Test FAILED: signal was not delivered to process\n");
70		return PTS_FAIL;
71	}
72	return PTS_PASS;
73}
74
75