• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 	setuid(1);
59 
60 	if (-1 == kill(1, 0)) {
61 		if (EPERM == errno) {
62 			printf("EPERM error received\n");
63 		} else {
64 			printf
65 			    ("kill() failed on EPERM errno not set correctly\n");
66 			failure = 1;
67 		}
68 	} else {
69 		printf("kill() did not fail on EPERM\n");
70 		failure = 1;
71 	}
72 
73 	if (failure) {
74 		printf("At least one test FAILED -- see output for status\n");
75 		return PTS_FAIL;
76 	} else {
77 		printf("Test PASSED\n");
78 		return PTS_PASS;
79 	}
80 }
81