cluster-wrapper.pl.in 4.09 KB
Newer Older
1 2
#!/usr/bin/perl -w
#
3
# Copyright (c) 2008-2017 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
# 
# {{{GENIPUBLIC-LICENSE
# 
# GENI Public License
# 
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and/or hardware specification (the "Work") to
# deal in the Work without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Work, and to permit persons to whom the Work
# is furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Work.
# 
# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
# IN THE WORK.
# 
# }}}
#

#
# Simple CGI interface to the GENI xmlrpc interface. This script is invoked
# from the web server. The certificate information is in the environment
# set up by apache.
#
use strict;
use English;
use Data::Dumper;
use FCGI;

#
# Turn off line buffering on output
#
$| = 1;

# Normal taint check requirement.
BEGIN {
    $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
    delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
}

# Testbed libraries.
use lib '@prefix@/lib';
use ClusterWrapper;

#
# Sanity check.
#
if ($EUID != 0) {
    print STDERR "Server configuration error; we are not setuid!"
}
ClusterWrapper::Initialize();

#
# Normally one would use CGI::Fast->new() to get the next request, but
# that is a layer on CGI, which does not grok purely XML postdata, it
# wants to parse it, and of course that fails. Frontier::Responder() has
# the same problem. So we do what it does; bypass CGI and just read the
# blob of XML from STDIN.
#
my $FCGI_Handle = FCGI::Request();

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
#
# If we abort logging and want to send stream data back to apache.
# See  GeniCMV2::SecureImageDownload();
#
my $logaborted = 0;

#
# This is a whacky kludge. 
#
my $GENI_ISCLRHOUSE;

#
# Set process title
#
if (exists($ENV{'MODULE'})) {
    my $module = $ENV{'MODULE'};
    if ($module =~ /^(\w+)$/) {
	$0 = $0 . " $1";
    }
}

#
# Loop until dead, what is dead will never die. 
#
97 98 99 100 101 102 103 104 105 106 107
while ($FCGI_Handle->Accept() >= 0) {
    my $request = undef;
    read(STDIN, $request, $ENV{CONTENT_LENGTH});

    #
    # We have to do this here again, since mod_fcgid sets the
    # environment back to its original value, between each call.
    #
    $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
    delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

108 109
    $logaborted = 0;

110 111 112 113 114 115 116 117
    #
    # We need to "detach" cause mod_fcgid has a bad "tie" implementation,
    # and so most calls to open fail. detaching is fine, we have the request,
    # and nothing goes back to apache until ClusterWrapper returns.
    # When it does, we can reattach and print the output to apache. 
    #
    $FCGI_Handle->Detach();
    my $response = ClusterWrapper->Start($request);
118 119 120 121 122 123

    # If we aborted (attached) earlier and sent stream data,
    # nothing more to do.
    next
	if ($logaborted);
	
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    $FCGI_Handle->Attach();
    if ($response) {
	print "Content-Type: text/xml \n\n" . $response;
    }
}

#
# These used to be in protogeni-wrapper.pl and accessed as upcalls
# from the libraries with main:: but now they are down one level.
# Need to change all the code at some point.
#
sub WrapperFork() {
    return ClusterWrapper::WrapperFork();
}
sub AddLogfileMetaData($$) {
    return ClusterWrapper::AddLogfileMetaData($_[0],$_[1]);
}
sub AddLogfileMetaDataFromSlice($) {
    return ClusterWrapper::AddLogfileMetaDataFromSlice($_[0]);
}
sub AddLogfileMetaDataFromSpeaksFor($) {
    return ClusterWrapper::AddLogfileMetaDataFromSpeaksFor($_[0]);
}
147 148 149 150 151
sub AbortLogging() {
    $logaborted = 1;
    $FCGI_Handle->Attach();
    return ClusterWrapper::AbortLogging();
}