• 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 #define _XOPEN_SOURCE 600
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <limits.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <signal.h>
35 #include "posixtest.h"
36 
37 static stack_t a;
38 
main(int argc,char * argv[])39 int main(int argc, char *argv[])
40 {
41 	int rc;
42 	char path[PATH_MAX + 1];
43 
44 	/* Called with no args, do the exec, otherwise check.  */
45 	if (argc == 1) {
46 		a.ss_flags = 0;
47 		a.ss_size = SIGSTKSZ;
48 		a.ss_sp = malloc(SIGSTKSZ);
49 		if (!a.ss_sp) {
50 			printf("Failed: malloc(SIGSTKSZ) == NULL\n");
51 			exit(PTS_UNRESOLVED);
52 		}
53 
54 		rc = sigaltstack(&a, NULL);
55 		if (rc) {
56 			printf("Failed: sigaltstack() rc: %d errno: %s\n",
57 			       rc, strerror(errno));
58 			exit(PTS_UNRESOLVED);
59 		}
60 
61 		/* Get abs path if needed and exec ourself */
62 		if (*argv[0] != '/') {
63 			getcwd(path, PATH_MAX);
64 			strcat(path, "/");
65 			strcat(path, argv[0]);
66 		} else {
67 			strcpy(path, argv[0]);
68 		}
69 		execl(path, argv[0], "verify", NULL);
70 		printf("Failed: execl() errno: %s\n", strerror(errno));
71 		exit(PTS_UNRESOLVED);
72 
73 	} else if (strcmp(argv[1], "verify")) {
74 		printf("Failed: %s called with unexpected argument: %s\n",
75 		       argv[0], argv[1]);
76 		exit(PTS_UNRESOLVED);
77 	}
78 
79 	/* Verify the alt stack is disabled */
80 	rc = sigaltstack(NULL, &a);
81 	if (rc || a.ss_flags != SS_DISABLE) {
82 		printf("Failed: sigaltstack() rc: %d ss_flags: %u\n",
83 		       rc, a.ss_flags);
84 		exit(PTS_FAIL);
85 	}
86 
87 	printf("Test PASSED\n");
88 	return PTS_PASS;
89 }
90