Commit 33657c40 authored by Mike Hibler's avatar Mike Hibler

Minor cleanups.

Pass in the user id to run as via the new -U arg. This may be moot if the
disk-agent has to run as root ultimately.
parent 5fa8f4a9
......@@ -27,7 +27,7 @@ CFLAGS += -DCLIENT_BINDIR='"$(CLIENT_BINDIR)"'
LDFLAGS += -g -L${TESTBED_LIBOBJDIR}/event -L${TESTBED_LIBOBJDIR}/libtb
LIBS += -levent -ltb -lcrypto -ldevmapper
LIBS += -L/usr/local/lib -lpubsub -ldevmapper
LIBS += -L/usr/local/lib -lpubsub
LDFLAGS += $(LDSTATIC)
# Make sure we have libdevmapper
......
......@@ -33,6 +33,7 @@
#include <ctype.h>
extern "C" {
#include "libdevmapper.h"
#include "be_user.h"
}
#ifdef HAVE_ELVIN
......@@ -330,15 +331,14 @@ void readArgs(int argc, char * argv[])
string subscription;
string vnode;
string group;
string user;
string LOGDIR = "/local/logs";
int isops, isplab;
// Prevent getopt from printing an error message.
opterr = 0;
/* get params from the optstring */
char const * argstring = "hds:p:l:u:i:e:c:k:o:g:v:t:P";
char const * argstring = "hds:p:l:u:i:e:c:k:o:g:v:t:U:";
int option = getopt(argc, argv, argstring);
while (option != -1)
{
......@@ -383,15 +383,13 @@ void readArgs(int argc, char * argv[])
break;
case 'v':
vnode = optarg;
if(!(vnode == "ops"))
isops = 1;
break;
case 'P':
isplab = 1;
break;
case 'g':
group = optarg;
break;
case 'U':
user = optarg;
break;
default:
usage(argv[0]);
break;
......@@ -400,9 +398,11 @@ void readArgs(int argc, char * argv[])
}
/*Check if all params are specified, otherwise, print usage and exit*/
if(server == "" || g::experimentName == "")
if(server == "" || user == "" || g::experimentName == "")
usage(argv[0]);
be_user(const_cast<char *>(user.c_str()));
/* if(g::debug)
loginit(0, logfile);
else {
......@@ -426,7 +426,7 @@ void readArgs(int argc, char * argv[])
void usage(char * name)
{
cerr << "Usage: " << name << " -e proj/exp -s server [-h][-d] [-p port] "
cerr << "Usage: " << name << " -e proj/exp -s server -U user [-h][-d] [-p port] "
<< "[-l logfile] [-c config file] [-i pidFile] [-k keyFile] [-u subscription] [-g group]" << endl;
exit(-1);
}
......
......@@ -41,7 +41,7 @@ use librc;
use libtestbed qw(TBBackGround);
# Script specific goo.
my $LOGFILE = LOGDIR() . "/diskgent.debug";
my $LOGFILE = LOGDIR() . "/diskagent.debug";
my $WRAPLOG = LOGDIR() . "/diskwrap.debug";
my $PIDFILE = (FAKEJAILED() ? CONFDIR() : "/var/run") . "/diskagent.pid";
my $CONFIG = CONFDIR() . "/diskagents";
......@@ -144,26 +144,19 @@ sub doboot()
unlink $CONFIG;
#
# We want to run disk-agent even if there are currently no
# registered agents. But to do that, we need a UID which we
# get from the TMCC creator command. Note that if we do not
# get a UID, we just exit normally without starting the agent.
# This is backward compatible and enables us to boot up unallocated
# nodes (though I am not sure they would ever reach this script).
# Find out who to run as
#
if (@agents == 0) {
my @tmccresults;
if (tmcc(TMCCCMD_CREATOR, undef, \@tmccresults) < 0) {
fatal("Could not get UID for progagent from server!");
}
if ($tmccresults[0] =~ / SWAPPER=([-\w]*)/) {
push(@agents, "UID=$1\n");
} elsif ($tmccresults[0] =~ /^CREATOR=([-\w]*)/) {
push(@agents, "UID=$1\n");
} else {
warning("Cannot determine UID for program agent, not running");
exit(0);
}
my @tmccresults;
if (tmcc(TMCCCMD_CREATOR, undef, \@tmccresults) < 0) {
fatal("Could not get UID for disk agent from server!");
}
if ($tmccresults[0] =~ / SWAPPER=([-\w]*)/) {
$runas = $1;
} elsif ($tmccresults[0] =~ /^CREATOR=([-\w]*)/) {
$runas = $1;
} else {
warning("Cannot determine UID for program agent, not running");
exit(0);
}
#
......@@ -193,8 +186,8 @@ sub doboot()
$server = "event-server.${domain}";
}
system("$DAGENT -e $pid/$eid -s $server -p $port -l $LOGFILE ".
"-v $vname -t $TOKEN ".
system("$DAGENT -e $pid/$eid -s $server $port -l $LOGFILE ".
"-v $vname -t $TOKEN -U $runas ".
"-d -i $PIDFILE -k " . TMEVENTKEY() . " -c $CONFIG");
exit(0)
if (! $?);
......
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