Commit 7e3a60ff authored by Leigh B Stoller's avatar Leigh B Stoller

Add ExecQuiet() to run a command and capture all output. Used in the

CM to capture the output of varuous commands so that the logs can be
sent to the user, with formatting.

Add subgroup handing in FlipToGeniUser(), and also add ResetGroups()
to change the user's group membership, since the slice experiments are
now created in a subgroup of GeniSlices (named by the user's SA).
parent 8b582e8e
...@@ -44,8 +44,11 @@ sub GENI_PURGEFLAG() { return 1; } ...@@ -44,8 +44,11 @@ sub GENI_PURGEFLAG() { return 1; }
# there is an emulab user context, or many of the scripts we invoke # there is an emulab user context, or many of the scripts we invoke
# will complain and croak. # will complain and croak.
# #
sub FlipToGeniUser() sub FlipToGeniUser(;$)
{ {
my ($default_gid) = @_;
my $glist;
my $unix_uid = getpwnam("$user") or my $unix_uid = getpwnam("$user") or
die("*** $0:\n". die("*** $0:\n".
" No such user $user\n"); " No such user $user\n");
...@@ -53,14 +56,29 @@ sub FlipToGeniUser() ...@@ -53,14 +56,29 @@ sub FlipToGeniUser()
die("*** $0:\n". die("*** $0:\n".
" No such group $group\n"); " No such group $group\n");
$GID = $unix_gid; if (defined($default_gid) && $default_gid != $unix_gid) {
$EGID = "$unix_gid $unix_gid"; $glist = "$default_gid $default_gid $unix_gid";
}
else {
$default_gid = $unix_gid;
$glist = "$unix_gid $unix_gid";
}
$GID = $default_gid;
$EGID = $glist;
$EUID = $UID = $unix_uid; $EUID = $UID = $unix_uid;
$ENV{'USER'} = $user; $ENV{'USER'} = $user;
$ENV{'LOGNAME'} = $user; $ENV{'LOGNAME'} = $user;
return 0; return 0;
} }
sub ResetGroups($)
{
my ($default_gid) = @_;
$EUID = 0;
return FlipToGeniUser($default_gid);
}
# #
# Store up the list of caches to flush # Store up the list of caches to flush
# #
...@@ -104,6 +122,7 @@ sub NewUUID() ...@@ -104,6 +122,7 @@ sub NewUUID()
sub LookupNode($) sub LookupNode($)
{ {
my ($nodeid) = @_; my ($nodeid) = @_;
require Node;
if( GeniHRN::IsValid( $nodeid ) ) { if( GeniHRN::IsValid( $nodeid ) ) {
# Looks like a URN. # Looks like a URN.
...@@ -138,5 +157,24 @@ sub FindHostname($) ...@@ -138,5 +157,24 @@ sub FindHostname($)
return $nodeid . "." . $prefix; return $nodeid . "." . $prefix;
} }
#
# Run a command, being sure to capture all output.
#
sub ExecQuiet($)
{
#
# Use a pipe read, so that we save away the output
#
my ($command) = @_;
my $output = "";
open(PIPE,"$command 2>&1 |") or return -1;
while (<PIPE>) {
$output .= $_;
}
close(PIPE);
return $output;
}
# _Always_ make sure that this 1 is at the end of the file... # _Always_ make sure that this 1 is at the end of the file...
1; 1;
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