summaryrefslogtreecommitdiff
path: root/testsuite/nsswitch/getgrent_r.c
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2000-05-12 06:55:09 +0000
committerTim Potter <tpot@samba.org>2000-05-12 06:55:09 +0000
commit75ebfc6f7a7692d772b729b2d83038a9054b4f90 (patch)
tree031b445348b62fdf40489fb2526c46506ee2c3ba /testsuite/nsswitch/getgrent_r.c
parent053322d0ca6b68be638c2d5f4caa9909a19c1646 (diff)
downloadsamba-75ebfc6f7a7692d772b729b2d83038a9054b4f90.tar.gz
samba-75ebfc6f7a7692d772b729b2d83038a9054b4f90.tar.bz2
samba-75ebfc6f7a7692d772b729b2d83038a9054b4f90.zip
Merge from TNG.
(This used to be commit af5ded9f17addb4bc89ecb762b9b99d2f99463ab)
Diffstat (limited to 'testsuite/nsswitch/getgrent_r.c')
-rw-r--r--testsuite/nsswitch/getgrent_r.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/testsuite/nsswitch/getgrent_r.c b/testsuite/nsswitch/getgrent_r.c
new file mode 100644
index 0000000000..3eac8aa218
--- /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 <stdio.h>
+#include <grp.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <wait.h>
+
+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")) < 0) {
+ 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:%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;
+}