Skip to content

Commit

Permalink
Use pipe instead of sigwait for krad tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greghudson committed Jul 15, 2013
1 parent 6e9ad5c commit 443193a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
29 changes: 11 additions & 18 deletions src/lib/krad/t_daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,39 +51,32 @@ 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;

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;
Expand Down
15 changes: 6 additions & 9 deletions src/lib/krad/t_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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
Expand All @@ -50,27 +50,24 @@ def _HandleAuthPacket(self, pkt):

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()

0 comments on commit 443193a

Please sign in to comment.