1 /* test 3 - library routines rather than system calls */
4 #include <sys/utsname.h>
19 char el_weirdo
[] = "\n\t\\\e@@!!##\e\e\n\n";
21 _PROTOTYPE(int main
, (int argc
, char *argv
[]));
22 _PROTOTYPE(void test3a
, (void));
23 _PROTOTYPE(void test3b
, (void));
24 _PROTOTYPE(void test3c
, (void));
25 _PROTOTYPE(void test3d
, (void));
26 _PROTOTYPE(void test3e
, (void));
27 _PROTOTYPE(void quit
, (void));
28 _PROTOTYPE(void e
, (int n
));
34 char buffer
[PATH_MAX
+ 1];
39 if (geteuid() == 0 || getuid() == 0) {
40 realpath(argv
[0], buffer
);
41 execl("/usr/bin/su", "/usr/bin/su", "-", "ast", "-c", buffer
, NULL
);
42 printf("Test 3 cannot run as root; test aborted\n");
46 if (argc
== 2) m
= atoi(argv
[1]);
49 fflush(stdout
); /* have to flush for child's benefit */
51 system("rm -rf DIR_03; mkdir DIR_03");
54 for (i
= 0; i
< ITERATIONS
; i
++) {
55 if (m
& 0001) test3a();
56 if (m
& 0002) test3b();
57 if (m
& 0004) test3c();
58 if (m
& 0010) test3d();
59 if (m
& 0020) test3e();
62 return(-1); /* impossible */
68 /* Signal set manipulation. */
73 errno
= -1000; /* None of these calls set errno. */
74 if (sigemptyset(&s
) != 0) e(1);
75 if (sigemptyset(&s1
) != 0) e(2);
76 if (sigaddset(&s
, SIGABRT
) != 0) e(3);
77 if (sigaddset(&s
, SIGALRM
) != 0) e(4);
78 if (sigaddset(&s
, SIGFPE
) != 0) e(5);
79 if (sigaddset(&s
, SIGHUP
) != 0) e(6);
80 if (sigaddset(&s
, SIGILL
) != 0) e(7);
81 if (sigaddset(&s
, SIGINT
) != 0) e(8);
82 if (sigaddset(&s
, SIGKILL
) != 0) e(9);
83 if (sigaddset(&s
, SIGPIPE
) != 0) e(10);
84 if (sigaddset(&s
, SIGQUIT
) != 0) e(11);
85 if (sigaddset(&s
, SIGSEGV
) != 0) e(12);
86 if (sigaddset(&s
, SIGTERM
) != 0) e(13);
87 if (sigaddset(&s
, SIGUSR1
) != 0) e(14);
88 if (sigaddset(&s
, SIGUSR2
) != 0) e(15);
90 if (sigismember(&s
, SIGABRT
) != 1) e(16);
91 if (sigismember(&s
, SIGALRM
) != 1) e(17);
92 if (sigismember(&s
, SIGFPE
) != 1) e(18);
93 if (sigismember(&s
, SIGHUP
) != 1) e(19);
94 if (sigismember(&s
, SIGILL
) != 1) e(20);
95 if (sigismember(&s
, SIGINT
) != 1) e(21);
96 if (sigismember(&s
, SIGKILL
) != 1) e(22);
97 if (sigismember(&s
, SIGPIPE
) != 1) e(23);
98 if (sigismember(&s
, SIGQUIT
) != 1) e(24);
99 if (sigismember(&s
, SIGSEGV
) != 1) e(25);
100 if (sigismember(&s
, SIGTERM
) != 1) e(26);
101 if (sigismember(&s
, SIGUSR1
) != 1) e(27);
102 if (sigismember(&s
, SIGUSR2
) != 1) e(28);
104 if (sigdelset(&s
, SIGABRT
) != 0) e(29);
105 if (sigdelset(&s
, SIGALRM
) != 0) e(30);
106 if (sigdelset(&s
, SIGFPE
) != 0) e(31);
107 if (sigdelset(&s
, SIGHUP
) != 0) e(32);
108 if (sigdelset(&s
, SIGILL
) != 0) e(33);
109 if (sigdelset(&s
, SIGINT
) != 0) e(34);
110 if (sigdelset(&s
, SIGKILL
) != 0) e(35);
111 if (sigdelset(&s
, SIGPIPE
) != 0) e(36);
112 if (sigdelset(&s
, SIGQUIT
) != 0) e(37);
113 if (sigdelset(&s
, SIGSEGV
) != 0) e(38);
114 if (sigdelset(&s
, SIGTERM
) != 0) e(39);
115 if (sigdelset(&s
, SIGUSR1
) != 0) e(40);
116 if (sigdelset(&s
, SIGUSR2
) != 0) e(41);
120 if (sigaddset(&s
, SIGILL
) != 0) e(43);
123 if (sigfillset(&s
) != 0) e(45);
124 if (sigismember(&s
, SIGABRT
) != 1) e(46);
125 if (sigismember(&s
, SIGALRM
) != 1) e(47);
126 if (sigismember(&s
, SIGFPE
) != 1) e(48);
127 if (sigismember(&s
, SIGHUP
) != 1) e(49);
128 if (sigismember(&s
, SIGILL
) != 1) e(50);
129 if (sigismember(&s
, SIGINT
) != 1) e(51);
130 if (sigismember(&s
, SIGKILL
) != 1) e(52);
131 if (sigismember(&s
, SIGPIPE
) != 1) e(53);
132 if (sigismember(&s
, SIGQUIT
) != 1) e(54);
133 if (sigismember(&s
, SIGSEGV
) != 1) e(55);
134 if (sigismember(&s
, SIGTERM
) != 1) e(56);
135 if (sigismember(&s
, SIGUSR1
) != 1) e(57);
136 if (sigismember(&s
, SIGUSR2
) != 1) e(58);
138 /* Test error returns. */
139 if (sigaddset(&s
, -1) != -1) e(59);
140 if (sigaddset(&s
, -1) != -1) e(60);
141 if (sigismember(&s
, -1) != -1) e(61);
142 if (sigaddset(&s
, 10000) != -1) e(62);
143 if (sigaddset(&s
, 10000) != -1) e(63);
144 if (sigismember(&s
, 10000) != -1) e(64);
152 struct utsname u
; /* contains all kinds of system ids */
156 errno
= -2000; /* None of these calls set errno. */
157 if (uname(&u
) != 0) e(1);
158 if (strcmp(u
.sysname
, "MINIX") != 0
159 && strcmp(u
.sysname
, "Minix") != 0) e(2); /* only one defined */
165 /* Test getenv. Asume HOME, PATH, and LOGNAME exist (not strictly required).*/
170 errno
= -3000; /* None of these calls set errno. */
171 if ( (p
= getenv("HOME")) == NULL
) { fprintf(stderr
, "Please have $HOME set properly.\n"); e(1); }
172 if (*p
!= '/') { fprintf(stderr
, "Please have $HOME point to an abolute path.\n"); e(2); } /* path must be absolute */
173 if ( (p
= getenv("PATH")) == NULL
) { fprintf(stderr
, "Please have $PATH set properly.\n"); e(3); }
174 if ( (p
= getenv("LOGNAME")) == NULL
) { fprintf(stderr
, "Please have $LOGNAME set properly.\n"); e(5); }
175 strcpy(name
, p
); /* save it, since getlogin might wipe it out */
177 if (strcmp(p
, name
) != 0) { fprintf(stderr
, "Please have $LOGNAME set to your real username. (su - instead of su?)\n"); e(6); }
179 /* The following test could fail in a legal POSIX system. However, if it
180 * does, you deserve it to fail.
182 if (getenv(el_weirdo
) != NULL
) e(7);
187 /* Test ctermid, ttyname, and isatty. */
190 char *p
, name
[L_ctermid
];
193 errno
= -4000; /* None of these calls set errno. */
195 /* Test ctermid first. */
196 if ( (p
= ctermid(name
)) == NULL
) e(1);
197 if (strcmp(p
, name
) != 0) e(2);
198 if (strncmp(p
, "/dev/tty", 8) != 0) e(3); /* MINIX convention */
200 if ( (p
= ttyname(0)) == NULL
) e(4);
201 if (strncmp(p
, "/dev/tty", 8) != 0 && strcmp(p
, "/dev/console") != 0) e(5);
202 if ( (p
= ttyname(3)) != NULL
) e(6);
203 if (ttyname(5000) != NULL
) e(7);
204 if ( (fd
= creat("T3a", 0777)) < 0) e(8);
205 if (ttyname(fd
) != NULL
) e(9);
207 if (isatty(0) != 1) e(10);
208 if (isatty(3) != 0) e(11);
209 if (isatty(fd
) != 0) e(12);
210 if (close(fd
) != 0) e(13);
211 if (ttyname(fd
) != NULL
) e(14);
216 /* Test ctermid, ttyname, and isatty. */
219 errno
= -5000; /* None of these calls set errno. */
221 if (sysconf(_SC_ARG_MAX
) < _POSIX_ARG_MAX
) e(1);
222 if (sysconf(_SC_CHILD_MAX
) < _POSIX_CHILD_MAX
) e(2);
223 if (sysconf(_SC_NGROUPS_MAX
) < 0) e(3);
224 if (sysconf(_SC_OPEN_MAX
) < _POSIX_OPEN_MAX
) e(4);
226 /* The rest are MINIX specific */
227 if (sysconf(_SC_JOB_CONTROL
) >= 0) e(5); /* no job control! */
233 system("rm -rf DIR*");
239 printf("%d errors\n", errct
);
247 int err_num
= errno
; /* save errno in case printf clobbers it */
249 printf("Subtest %d, error %d errno=%d ", subtest
, n
, errno
);
250 errno
= err_num
; /* restore errno, just in case */
252 if (errct
++ > MAX_ERROR
) {
253 printf("Test aborted. Too many errors: ");
255 system("rm -rf DIR*");