1 #include <signal.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <errno.h>
6 #include <sys/types.h>
7 #include "posixtest.h"
8
9 /*
10 * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
11 * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com
12 * This file is licensed under the GPL license. For the full content
13 * of this license, see the COPYING file at the top level of this
14 * source tree.
15
16 * Test that when the null signal is sent to kill(), error checking is
17 * still performed.
18 * 1) Send a signal to generate an ESRCH error.
19 * ==> Send a signal to PID 999999
20 * 2) Verify ESRCH error received and kill() returned -1.
21 * 3) Send a signal to generate an EPERM error.
22 * ==> Set UID to 1 and send a signal to init (pid = 1)
23 * 4) Verify EPERM error received and kill() returned -1.
24 *
25 * Note: These tests make the assumptions that:
26 * - They will be running as root.
27 * - The PID 999999 can never exist.
28 * - The UID 1 is available for assignment and cannot sent
29 * signals to root.
30 * *** I need to check to see if these assumptions are always valid.
31 */
32
main(void)33 int main(void)
34 {
35 int failure = 0;
36
37 /*
38 * ESRCH
39 */
40 if (-1 == kill(999999, 0)) {
41 if (ESRCH == errno) {
42 printf("ESRCH error received\n");
43 } else {
44 printf
45 ("kill() failed on ESRCH errno not set correctly\n");
46 failure = 1;
47 }
48 } else {
49 printf("kill() did not fail on ESRCH\n");
50 failure = 1;
51 }
52
53 /*
54 * EPERM
55 */
56 /* this is added incase user is root. If user is normal user, then it
57 * has no effect on the tests */
58 if (setuid(1)) {
59 perror("setuid");
60 return PTS_UNRESOLVED;
61 }
62
63 if (-1 == kill(1, 0)) {
64 if (EPERM == errno) {
65 printf("EPERM error received\n");
66 } else {
67 printf
68 ("kill() failed on EPERM errno not set correctly\n");
69 failure = 1;
70 }
71 } else {
72 printf("kill() did not fail on EPERM\n");
73 failure = 1;
74 }
75
76 if (failure) {
77 printf("At least one test FAILED -- see output for status\n");
78 return PTS_FAIL;
79 } else {
80 printf("Test PASSED\n");
81 return PTS_PASS;
82 }
83 }
84