2 * Use set/get/endpwent calls from two processes to iterate over the
3 * password database. This checks the multithreaded stuff works.
14 void dump_pwent(char *id
)
20 /* Open results file */
22 sprintf(fname
, "/tmp/getpwent_r-%s.out-%d", id
, getpid());
24 if ((fptr
= fopen(fname
, "w")) < 0) {
25 fprintf(stderr
, "ERROR: could not open file %s: %s\n", fname
,
30 /* Dump passwd database */
34 while((pw
= getpwent()) != NULL
) {
35 fprintf(fptr
,"%s:%s:%s:%d:%d\n", pw
->pw_name
, pw
->pw_passwd
,
36 pw
->pw_gecos
, pw
->pw_uid
, pw
->pw_gid
);
41 /* Close results file */
48 int main(int argc
, char **argv
)
50 pid_t pids
[NUM_FORKS
];
56 printf("ERROR: must specify output file identifier\n");
60 for(i
= 0; i
< NUM_FORKS
; i
++) {
64 if ((pids
[i
] = fork()) == -1) {
69 /* Child does tests */
77 /* Wait for everyone to finish */
79 for (i
= 0; i
< NUM_FORKS
; i
++) {
80 waitpid(pids
[i
], &status
, 0);
83 printf("PASS: getpwent_r.c\n");