caplog.in 1.82 KB
Newer Older
1 2 3 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2008 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
use English;
use Getopt::Std;
use POSIX qw(setsid);

#
# Wrapper for caplog program; grab tipacl from XMLRPC server, and feed it
# to the caplog binary.
#
sub usage()
{
    print(STDOUT "Usage: caplog [-/+line] [-f] [-p port] pcXXX\n");
    exit(-1);
}
my @opts = ();

#
# Configure variables
#
my $TB		= "@prefix@";
my $TBOPS       = "@TBOPSEMAIL@";
my $WRAPPER     = "$TB/bin/script_wrapper.py";
my $CAPLOGBIN   = "$TB/bin/caplog.bin";
my $aclfile;

#
# Turn off line buffering on output. Very important for this script!
#
$| = 1;

#
# All args pass right through except the last one.
#
usage()
    if (@ARGV < 1);
my $node = $ARGV[scalar(@ARGV)-1];
@ARGV = @ARGV[0..(scalar(@ARGV)-2)];

#
# Make a temp file for the acl.
#
$ENV{'TMPDIR'} = "/tmp";

my $tempfile = `mktemp -t tipacl`;
if ($?) {
    die("*** $0:\n".
	"    Could not create a temporary file!\n");
}
if ($tempfile =~ /^([-\w\/\.]*)$/) {
    $tempfile = $1;
}
else {
    die("*** $0:\n".
	"    Bad data in tag: $tempfile\n");
}

#
# Ask the XMLRPC server for the tipacl. The current user has to have proper
# permission of course.
#
if (system("$WRAPPER tipacl $node >> $tempfile")) {
    unlink($tempfile);
    die("*** $0:\n".
	"    $WRAPPER failed\n");
}

#
# Do not want to leave the acl file around, and do not want to wait for
# the user to quit the program, so fork a child to wait a moment and remove
# the file. We have the child do it so as to avoid messing with the session
# and tty goo.
#
my $syspid = fork();

# Child delays a moment and exits. 
if (!$syspid) {
    sleep(1);
    unlink($tempfile);
    exit(0);
}
my @cmdargs = ($CAPLOGBIN, "-a", "$tempfile", @ARGV, "$node");
exec(@cmdargs);
die("*** $0:\n".
    "    Exec failure: '@cmdargs'\n");