Commit d776153b authored by Leigh B Stoller's avatar Leigh B Stoller

Rework the wrapper fork/wait that tries to catch immediate errors. The

shellinaboxd daemon and/or the wrapper is doing something strange that
makes apache unhappy.
parent b27aad2f
#!/usr/bin/perl -w
#
# Copyright (c) 2008-2015 University of Utah and the Flux Group.
# Copyright (c) 2008-2016 University of Utah and the Flux Group.
#
# {{{GENIPUBLIC-LICENSE
#
......@@ -133,6 +133,7 @@ open(KEY, "/usr/testbed/etc/sshauth.key") or
fatal("Could not open sshauth.key");
my $sshauthkey = <KEY>;
chomp($sshauthkey);
close(KEY);
#
# Dig out the authentication object. It is a json object.
......@@ -273,45 +274,25 @@ if ($debug) {
# The point of this is to capture the initial STDERR of shellinaboxd
# and send it out to syslog or file.
#
pipe(READER, WRITER);
WRITER->autoflush(1);
my $pid = fork();
if ($pid) {
close WRITER;
close STDOUT;
close STDIN;
#
# The read seems to get stuck, leaving a defunct child and this
# script hanging out. Not sure why, so cancel the read after a
# a bit and go on.
#
local $SIG{ALRM} = sub {
info("Timed out waiting for $pid to say something");
waitpid($pid, 0);
info("After waitpid: $?");
unlink($tempfile)
if (defined($tempfile));
exit($? >> 0);
};
alarm 30;
while (<READER>) {
open(PIPE,"$cmd 2>&1 |") or
fatal("Could not start '$cmd'");
#
# We better see these two lines, or something went wrong.
#
while (<PIPE>) {
if ($_ =~ /^(.*:\d+)\r$/) {
# This line means good startup, send the session:port to the browser.
print "Content-type: text/plain\n\n";
print $1 . "\n";
close(PIPE);
exit(0);
}
else {
info($_);
}
alarm 0;
info("Before waitpid for $pid");
waitpid($pid, 0);
info("After waitpid: $?");
unlink($tempfile)
if (defined($tempfile));
exit($? >> 0);
}
else {
# Need the parent to run first so it can close STDOUT. Better
# ways to do this of course.
select(undef, undef, undef, 0.2);
close READER;
close STDERR;
open(STDERR, ">&WRITER") || fatal("can't dup to stderr");
close WRITER;
}
exec($cmd);
close(PIPE)
or fatal(($! ?
"Error closing shellinaboxd pipe: $!" :
"Exit status $? from shellinaboxd"));
exit($? >> 0);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment