aboutsummaryrefslogtreecommitdiff
path: root/testcases/open_posix_testsuite/conformance/interfaces/sigwaitinfo/8-1.c
blob: d603f59f7eefb6b94754c6ea5f1b56dc2fc50914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
 * This file is licensed under the GPL license.  For the full content
 * of this license, see the COPYING file at the top level of this
 * source tree.

 This program tests the assertion that if there aren't any more queued signals
 for the selected signal, then the pending indication of that signal is
 reset.

 Steps:
 - Register for myhandler to be called when SIGTOTEST is called, and make
   sure SA_SIGINFO is set.
 - Block signal SIGTOTEST from the process.
 - Using sigqueue(), send NUMCALLS instances of SIGTOTEST to the current
   process.
 - Call sigwaitinfo() NUMCALLS times, and verify that the pending indication
   for signal SIGTOTEST has been reset.

 */

#define _XOPEN_REALTIME 1
#define SIGTOTEST SIGRTMIN
#define NUMCALLS 5

#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include "posixtest.h"

void myhandler(int signo LTP_ATTRIBUTE_UNUSED,
	siginfo_t *info LTP_ATTRIBUTE_UNUSED,
	void *context LTP_ATTRIBUTE_UNUSED)
{
	printf("Just a dummy handler\n");
}

int main(void)
{
	int pid, i;
	union sigval value;
	struct sigaction act;
	sigset_t selectset, pendingset;
	siginfo_t info;

	act.sa_flags = SA_SIGINFO;
	act.sa_sigaction = myhandler;
	sigemptyset(&act.sa_mask);
	sigaction(SIGTOTEST, &act, 0);

	pid = getpid();

	sighold(SIGTOTEST);

	for (i = NUMCALLS; i > 0; i--) {
		value.sival_int = i;
		if (sigqueue(pid, SIGTOTEST, value) != 0) {
			printf
			    ("Test FAILED: call to sigqueue did not return success\n");
			return PTS_FAIL;
		}
	}

	sigemptyset(&selectset);
	sigaddset(&selectset, SIGTOTEST);

	for (i = NUMCALLS; i > 0; i--) {
		if (sigwaitinfo(&selectset, &info) != SIGTOTEST) {
			perror
			    ("sigwaitinfo() returned signal other than SIGTOTEST\n");
			return PTS_UNRESOLVED;
		}
	}

	sigemptyset(&pendingset);
	sigpending(&pendingset);
	if (sigismember(&pendingset, SIGTOTEST) != 0) {
		printf
		    ("Test FAILED: Signal %d still pending even after call to sigwaitinfo()\n",
		     SIGTOTEST);
		return PTS_FAIL;
	}

	return PTS_PASS;
}