• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) Novell Inc. 2011
3  *
4  *   This program is free software;  you can redistribute it and/or modify
5  *   it under the terms in version 2 of the GNU General Public License as
6  *   published by the Free Software Foundation.
7  *
8  *   This program is distributed in the hope that it will be useful,
9  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
11  *   the GNU General Public License for more details.
12  *
13  *   You should have received a copy of the GNU General Public License
14  *   along with this program;  if not, write to the Free Software
15  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  *   Author:  Peter W. Morreale <pmorreale AT novell DOT com>
18  *   Date:    09.07.2011
19  *
20  *
21  * Test assertion 9-1 - Prove that an established alternate signal stack
22  * is not available after an exec.
23  *
24  */
25 
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <limits.h>
30 #include <unistd.h>
31 #include <string.h>
32 #include <errno.h>
33 #include <signal.h>
34 #include "posixtest.h"
35 
36 static stack_t a;
37 
main(int argc,char * argv[])38 int main(int argc, char *argv[])
39 {
40 	int rc;
41 	char path[PATH_MAX + 1];
42 
43 	/* Called with no args, do the exec, otherwise check.  */
44 	if (argc == 1) {
45 		a.ss_flags = 0;
46 		a.ss_size = SIGSTKSZ;
47 		a.ss_sp = malloc(SIGSTKSZ);
48 		if (!a.ss_sp) {
49 			printf("Failed: malloc(SIGSTKSZ) == NULL\n");
50 			exit(PTS_UNRESOLVED);
51 		}
52 
53 		rc = sigaltstack(&a, NULL);
54 		if (rc) {
55 			printf("Failed: sigaltstack() rc: %d errno: %s\n",
56 			       rc, strerror(errno));
57 			exit(PTS_UNRESOLVED);
58 		}
59 
60 		/* Get abs path if needed and exec ourself */
61 		if (*argv[0] != '/') {
62 			getcwd(path, PATH_MAX);
63 			strcat(path, "/");
64 			strcat(path, argv[0]);
65 		} else {
66 			strcpy(path, argv[0]);
67 		}
68 		execl(path, argv[0], "verify", NULL);
69 		printf("Failed: execl() errno: %s\n", strerror(errno));
70 		exit(PTS_UNRESOLVED);
71 
72 	} else if (strcmp(argv[1], "verify")) {
73 		printf("Failed: %s called with unexpected argument: %s\n",
74 		       argv[0], argv[1]);
75 		exit(PTS_UNRESOLVED);
76 	}
77 
78 	/* Verify the alt stack is disabled */
79 	rc = sigaltstack(NULL, &a);
80 	if (rc || a.ss_flags != SS_DISABLE) {
81 		printf("Failed: sigaltstack() rc: %d ss_flags: %u\n",
82 		       rc, a.ss_flags);
83 		exit(PTS_FAIL);
84 	}
85 
86 	printf("Test PASSED\n");
87 	return PTS_PASS;
88 }
89