From 8daa83a594a2e98f39d764422bfbdbc62c9efd44 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 19:20:00 +0200 Subject: Adding upstream version 2:4.20.0+dfsg. Signed-off-by: Daniel Baumann --- testsuite/nsswitch/getpwent_r.c | 85 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 testsuite/nsswitch/getpwent_r.c (limited to 'testsuite/nsswitch/getpwent_r.c') diff --git a/testsuite/nsswitch/getpwent_r.c b/testsuite/nsswitch/getpwent_r.c new file mode 100644 index 0000000..5e77491 --- /dev/null +++ b/testsuite/nsswitch/getpwent_r.c @@ -0,0 +1,85 @@ +/* + * Use set/get/endpwent calls from two processes to iterate over the + * password database. This checks the multithreaded stuff works. + */ + +#include +#include +#include +#include +#include +#include +#include + +void dump_pwent(char *id) +{ + struct passwd *pw; + char fname[255]; + FILE *fptr; + + /* Open results file */ + + sprintf(fname, "/tmp/getpwent_r-%s.out-%d", id, getpid()); + + if ((fptr = fopen(fname, "w")) == 0) { + fprintf(stderr, "ERROR: could not open file %s: %s\n", fname, + sys_errlist[errno]); + return; + } + + /* Dump passwd database */ + + setpwent(); + + while((pw = getpwent()) != NULL) { + fprintf(fptr,"%s:%s:%s:%d:%d\n", pw->pw_name, pw->pw_passwd, + pw->pw_gecos, pw->pw_uid, pw->pw_gid); + } + + endpwent(); + + /* Close results file */ + + fclose(fptr); +} + +#define NUM_FORKS 2 + +int main(int argc, char **argv) +{ + pid_t pids[NUM_FORKS]; + int i, status; + + /* Check args */ + + if (argc != 2) { + printf("ERROR: must specify output file identifier\n"); + return 1; + } + + for(i = 0; i < NUM_FORKS; i++) { + + /* Fork off lots */ + + if ((pids[i] = fork()) == -1) { + perror("fork"); + return 1; + } + + /* Child does tests */ + + if (pids[i] == 0) { + dump_pwent(argv[1]); + return 0; + } + } + + /* Wait for everyone to finish */ + + for (i = 0; i < NUM_FORKS; i++) { + waitpid(pids[i], &status, 0); + } + + printf("PASS: getpwent_r.c\n"); + return 0; +} -- cgit v1.2.3