From 443193a040b9c2fa8668ca85fda505c92d3facfe Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Sun, 14 Jul 2013 21:17:39 -0400 Subject: 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 7c345a629..cbcb13253 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 71e70dde2..dcda0050b 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() -- cgit