krb5 commit: Use pipe instead of sigwait for krad tests

Greg Hudson ghudson at MIT.EDU
Mon Jul 15 00:43:08 EDT 2013


https://github.com/krb5/krb5/commit/443193a040b9c2fa8668ca85fda505c92d3facfe
commit 443193a040b9c2fa8668ca85fda505c92d3facfe
Author: Greg Hudson <ghudson at mit.edu>
Date:   Sun Jul 14 21:17:39 2013 -0400

    Use pipe instead of sigwait for krad tests
    
    We've never used sigwait() before, and it has some problems on Solaris
    10 (a nonconformant prototype by default, and experimentally it didn't
    seem to work correctly with _POSIX_PTHREAD_SEMANTICS defined).  Use a
    pipe instead.  Make t_daemon.py less chatty on stdout to avoid filling
    the pipe buffer.

 src/lib/krad/t_daemon.h  |   29 +++++++++++------------------
 src/lib/krad/t_daemon.py |   15 ++++++---------
 2 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/src/lib/krad/t_daemon.h b/src/lib/krad/t_daemon.h
index 7c345a6..cbcb132 100644
--- a/src/lib/krad/t_daemon.h
+++ b/src/lib/krad/t_daemon.h
@@ -51,8 +51,8 @@ daemon_stop(void)
 static krb5_boolean
 daemon_start(int argc, const char **argv)
 {
-    sigset_t set;
-    int sig;
+    int fds[2];
+    char buf[1];
 
     if (argc != 3 || argv == NULL)
         return FALSE;
@@ -60,30 +60,23 @@ daemon_start(int argc, const char **argv)
     if (daemon_pid != 0)
         return TRUE;
 
-    if (sigemptyset(&set) != 0)
-        return FALSE;
-
-    if (sigaddset(&set, SIGUSR1) != 0)
-        return FALSE;
-
-    if (sigaddset(&set, SIGCHLD) != 0)
-        return FALSE;
-
-    if (sigprocmask(SIG_BLOCK, &set, NULL) != 0)
+    if (pipe(fds) != 0)
         return FALSE;
 
+    /* Start the child process with the write end of the pipe as stdout. */
     daemon_pid = fork();
     if (daemon_pid == 0) {
-        close(STDOUT_FILENO);
-        open("/dev/null", O_WRONLY);
+        dup2(fds[1], STDOUT_FILENO);
+        close(fds[0]);
+        close(fds[1]);
         exit(execlp(argv[1], argv[1], argv[2], NULL));
     }
+    close(fds[1]);
 
-    if (sigwait(&set, &sig) != 0 || sig == SIGCHLD) {
-        daemon_stop();
-        daemon_pid = 0;
+    /* The child will write a sentinel character when it is listening. */
+    if (read(fds[0], buf, 1) != 1 || *buf != '~')
         return FALSE;
-    }
+    close(fds[0]);
 
     atexit(daemon_stop);
     return TRUE;
diff --git a/src/lib/krad/t_daemon.py b/src/lib/krad/t_daemon.py
index 71e70dd..dcda005 100644
--- a/src/lib/krad/t_daemon.py
+++ b/src/lib/krad/t_daemon.py
@@ -33,7 +33,7 @@ import signal
 try:
     from pyrad import dictionary, packet, server
 except ImportError:
-    sys.stdout.write("pyrad not found!\n")
+    sys.stderr.write("pyrad not found!\n")
     sys.exit(0)
 
 # We could use a dictionary file, but since we need
@@ -50,27 +50,24 @@ class TestServer(server.Server):
 
         passwd = []
 
-        print "Request: "
         for key in pkt.keys():
             if key == "User-Password":
                 passwd = map(pkt.PwDecrypt, pkt[key])
-                print "\t%s\t%s" % (key, passwd)
-            else:
-                print "\t%s\t%s" % (key, pkt[key])
 
         reply = self.CreateReplyPacket(pkt)
         if passwd == ['accept']:
             reply.code = packet.AccessAccept
-            print "Response: %s" % "Access-Accept"
         else:
             reply.code = packet.AccessReject
-            print "Response: %s" % "Access-Reject"
-        print
         self.SendReplyPacket(pkt.fd, reply)
 
 srv = TestServer(addresses=["localhost"],
                  hosts={"127.0.0.1":
                         server.RemoteHost("127.0.0.1", "foo", "localhost")},
                  dict=dictionary.Dictionary(StringIO.StringIO(DICTIONARY)))
-os.kill(os.getppid(), signal.SIGUSR1)
+
+# Write a sentinel character to let the parent process know we're listening.
+sys.stdout.write("~")
+sys.stdout.flush()
+
 srv.Run()


More information about the cvs-krb5 mailing list