forked from wenjun1055/c
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.2.c
More file actions
37 lines (30 loc) · 708 Bytes
/
10.2.c
File metadata and controls
37 lines (30 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <pwd.h>
#include <string.h>
static void my_alarm(int signo)
{
struct passwd *rootptr;
printf("in signal handler\n");
if (NULL == (rootptr = getpwnam("root"))) {
printf("getpwnam(root) error\n");
exit(-1);
}
alarm(1);
}
int main(void)
{
struct passwd *ptr;
signal(SIGALRM, my_alarm);
alarm(1);
for (; ;) {
if (NULL == (ptr = getpwnam("vagrant"))) {
printf("getpwnam error\n");
exit(-1);
}
if (strcmp(ptr->pw_name, "vagrant") != 0) {
printf("return value corrupted, pw_name = %s\n", ptr->pw_name);
}
}
}