Missing Npth test

Uldis Anšmits uldis.ansmits at tieto.com
Thu Feb 11 14:19:04 CET 2016


Hello!

I believe, npth project is missing test for resource locking after for.
Please see patch at the end of message.

gnupg-2.1.11 tests fail on AIX. gpg-agent fails on semaphore operations
during startup.

Following important npth library functions are executed by gpg-agent on
startup:
1. npth_init
2. npth_unportect
3. npth_protect
4. fork
5. npth_pselect <- here things go wrong

Tested on following AIX versions

AIX 5.3 ---------
$ oslevel -s
5300-12-02-1036
$ truss -f gpg-agent --daemon 2>&1 |grep -E '(sem|SIGHUP|fork)'
413790: sem_init(0x09001000A0276C60, 0, 1)              = 0
413790: _sem_wait(0x09001000A0276C60, 0x0000000000000000, 0) = 0
413790: sem_post(0x09001000A0276C60)                    = 0
413790: _sem_wait(0x09001000A0276C60, 0x0000000000000000, 0) = 0
413790: kfork()                                         = 3621076
3621076:         L`kfork()              (returning as child ...)        = 0
3621076:        4710521: sem_post(0x09001000A0276C60)           =
0xFFFFFFFFFFFFFFFF

npth test output:
PASS: t-mutex
PASS: t-thread
Assertion failed: res == 0, file  ../../npth-1.2/src/npth.c, line 123
FAIL: t-fork

AIX 7.1 --------
$ oslevel -s
7100-00-03-1115

$ truss -f gpg-agent --daemon 2>&1 |grep -E '(sem|SIGHUP|fork)'
46858388: 36372657: sem_init(0x09001000A0B243A8, 0, 1)  = 0
46858388: 36372657: _sem_wait(0x09001000A0B243A8, 0x0000000000000000, 0) = 0
46858388: 36372657: sem_post(0x09001000A0B243A8)                = 0
46858388: 36372657: _sem_wait(0x09001000A0B243A8, 0x0000000000000000, 0) = 0
46858388: 36372657: kfork()                             = 54132990
54132990:       kfork()         (returning as child ...)        = 0
54132990:       69140619: sem_post(0x09001000A0B243A8)          Err#13
EACCES

npth test output:
PASS: t-mutex
PASS: t-thread
Assertion failed: __EX, file  ../../npth-1.2/src/npth.c, line 123
FAIL: t-fork

AIX 7.1 --------
$ oslevel -s
7100-00-10-1334

$ truss -f gpg-agent --daemon 2>&1 |grep -E '(sem|SIGHUP|fork)'
41353330: 69599333: sem_init(0x09001000A06C3BD8, 0, 1)  = 0
41353330: 69599333: _sem_wait(0x09001000A06C3BD8, 0x0000000000000000, 0) = 0
41353330: 69599333: sem_post(0x09001000A06C3BD8)                = 0
41353330: 69599333: _sem_wait(0x09001000A06C3BD8, 0x0000000000000000, 0) = 0
41353330: 69599333: kfork()                             = 44892354
44892354:       kfork()         (returning as child ...)        = 0
44892354:           Received signal #1, SIGHUP [default]

For reason unknown to me, on last machine child receives SIGHUP soon after
fork.
Workaround for this is to set signal handler right after fork but this is
nothing to do with Npth.

npth test output:
PASS: t-mutex
PASS: t-thread
Assertion failed: __EX, file  ../../npth-1.2/src/npth.c, line 123
FAIL: t-fork

If i change sem_init(,pshared=1,) in npth_init, semaphore operations works.

Please consider following patch for testing Npth behaviour after fork.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0dd436e..4b39ff6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,7 +28,7 @@

 ## Process this file with automake to produce Makefile.in

-TESTS = t-mutex t-thread
+TESTS = t-mutex t-thread t-fork

 # We explicitly require POSIX.1-2001 so that pthread_rwlock_t is
 # available when build with c99.
diff --git a/tests/t-fork.c b/tests/t-fork.c
new file mode 100644
index 0000000..b6a0a17
--- /dev/null
+++ b/tests/t-fork.c
@@ -0,0 +1,49 @@
+/* t-mutex.c
+ * Copyright 2011, 2012 g10 Code GmbH
+ *
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include "t-support.h"
+
+
+int
+main (int argc, char *argv[])
+{
+  int rc;
+
+  rc = npth_init ();
+  fail_if_err (rc);
+  npth_unprotect ();
+  npth_protect ();
+  pid_t pid;
+  npth_sigev_init ();
+  npth_sigev_add (SIGHUP);
+  npth_sigev_fini ();
+  pid = fork ();
+  if (pid == (pid_t)-1)
+    {
+      fail_msg ("fork failed");
+      exit (1);
+    }
+  else if (pid)
+   {
+     int status;
+     info_msg("forked");
+     waitpid(-1,&status,0);
+     if(status) {
+       exit(1);
+     }
+   } else {
+     npth_unprotect ();
+     info_msg("child exit");
+     exit(0);
+   }
+  return 0;
+}

Thank you.
Uldis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/attachments/20160211/27446668/attachment.html>


More information about the Gnupg-devel mailing list