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/getgrent_r.c | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 testsuite/nsswitch/getgrent_r.c (limited to 'testsuite/nsswitch/getgrent_r.c') diff --git a/testsuite/nsswitch/getgrent_r.c b/testsuite/nsswitch/getgrent_r.c new file mode 100644 index 0000000..883c897 --- /dev/null +++ b/testsuite/nsswitch/getgrent_r.c @@ -0,0 +1,84 @@ +/* + * Use set/get/endgrent 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_grent(char *id) +{ + struct group *gr; + char fname[255]; + FILE *fptr; + + /* Open results file */ + + sprintf(fname, "/tmp/getgrent_r-%s.out-%d", id, getpid()); + + if ((fptr = fopen(fname, "w")) == NULL) { + fprintf(stderr, "ERROR: could not open file %s: %s\n", fname, + sys_errlist[errno]); + return; + } + + /* Dump group database */ + + setgrent(); + + while((gr = getgrent()) != NULL) { + fprintf(fptr,"%s:%s:%d\n", gr->gr_name, gr->gr_passwd, + gr->gr_gid); + } + + endgrent(); + + /* Close results file */ + + fclose(fptr); +} + +int main(int argc, char **argv) +{ + pid_t pid; + + /* Check args */ + + if (argc != 2) { + printf("ERROR: must specify output file identifier\n"); + return 1; + } + + /* Fork child process */ + + if ((pid = fork()) == -1) { + printf("ERROR: unable to fork\n"); + return 1; + } + + /* Handle test case */ + + if (pid > 0) { + int status; + + /* Parent */ + + dump_grent(argv[1]); + wait(&status); + + } else { + + /* Child */ + + dump_grent(argv[1]); + return 0; + } + + printf("PASS: run getgrent_r.c\n"); + return 0; +} -- cgit v1.2.3