Commit 80c86360 authored by Mike Hibler's avatar Mike Hibler

More draconian measures to ensure compliance with the laws of SIGTERM.

Also, rip out all the robot related code. (sorry Dave!)
parent 56a946d9
......@@ -102,10 +102,6 @@ int32_t next_token;
simulator_agent_t primary_simulator_agent;
static pid_t emcd_pid = -1;
static pid_t vmcd_pid = -1;
static pid_t rmcd_pid = -1;
static struct agent ns_sequence_agent; /* Used for list of things to do right after swapin */
static timeline_agent_t ns_sequence;
static struct agent ns_teardown_agent; /* Used during experiment teardown */
......@@ -115,20 +111,37 @@ static timeline_agent_t ns_swapout;
static struct agent ns_timeline_agent; /* Used for timeline in the experiment */
static timeline_agent_t ns_timeline;
static event_handle_t handle;
static sigset_t threadmask;
static pthread_t mainthread;
/*
* Threads are started up mysteriously throughout the lifetime of the
* event scheduler. To avoid total chaos, we only process these exit
* actions in the main thread. All other threads just propagate the
* signal and go back to what they were doing.
*/
static void sigpass(int sig)
{
char tbuf[32];
time_t ts = time(NULL);
info("event-sched[%d]: received signal %d at %s",
getpid(), sig, ctime_r(&ts, tbuf));
pthread_t th = pthread_self();
info("event-sched[%d]: received signal %d in thread %p at %s",
getpid(), sig, th, ctime_r(&ts, tbuf));
/* haven't fired up anything yet, just exit */
if (mainthread == NULL)
exit(0);
if (emcd_pid != -1)
kill(emcd_pid, sig);
if (vmcd_pid != -1)
kill(vmcd_pid, sig);
if (rmcd_pid != -1)
kill(rmcd_pid, sig);
/* whoever we are, we should not process signals after this */
pthread_sigmask(SIG_BLOCK, &threadmask, NULL);
if (th != mainthread) {
info("event-sched[%d]: handled signal in wrong thread!",
getpid());
pthread_kill(th, sig);
return;
}
/* Unregister with the event system: */
if (handle && event_unregister(handle) == 0) {
......@@ -146,77 +159,6 @@ static void sigpanic(int sig)
abort();
}
static void sigchld(int sig)
{
int status;
if (vmcd_pid != -1) {
if (waitpid(vmcd_pid, &status, WNOHANG) != -1) {
vmcd_pid = -1;
}
}
if (rmcd_pid != -1) {
if (waitpid(rmcd_pid, &status, WNOHANG) != -1) {
rmcd_pid = -1;
if (vmcd_pid != -1)
kill(vmcd_pid, SIGTERM);
}
}
}
static char emc_path[256];
static void sighup(int sig)
{
if (emc_path[0] == '\0')
return;
rmcd_pid = fork();
switch (rmcd_pid) {
case -1:
fatal("could not start rmcd");
break;
case 0:
execlp("rmcd",
"rmcd",
"-dd",
"-l",
"logs/rmcd.log",
"-U",
emc_path,
NULL);
exit(0);
break;
default:
break;
}
vmcd_pid = fork();
switch (vmcd_pid) {
case -1:
fatal("could not start vmcd");
break;
case 0:
sleep(1);
execlp("vmcd",
"vmcd",
"-d",
"-S",
"-w",
"5",
"-l",
"logs/vmcd.log",
"-U",
emc_path,
NULL);
exit(0);
break;
default:
break;
}
}
void
usage(void)
{
......@@ -253,7 +195,6 @@ main(int argc, char *argv[])
char *keyfile = NULL;
char buf[BUFSIZ];
int c;
sigset_t mask;
// sleep(600);
......@@ -362,12 +303,13 @@ main(int argc, char *argv[])
if (log)
loginit(0, log);
sigemptyset(&mask);
sigaddset(&mask, SIGTERM);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGQUIT);
sigaddset(&mask, SIGHUP);
sigemptyset(&threadmask);
sigaddset(&threadmask, SIGTERM);
sigaddset(&threadmask, SIGINT);
sigaddset(&threadmask, SIGQUIT);
sigaddset(&threadmask, SIGHUP);
mainthread = pthread_self();
signal(SIGTERM, sigpass);
signal(SIGINT, sigpass);
signal(SIGQUIT, sigpass);
......@@ -375,9 +317,6 @@ main(int argc, char *argv[])
signal(SIGSEGV, sigpanic);
signal(SIGBUS, sigpanic);
signal(SIGCHLD, sigchld);
signal(SIGHUP, sighup);
/*
* Convert server/port to elvin thing.
*
......@@ -393,7 +332,7 @@ main(int argc, char *argv[])
server = buf;
/* XXX make sure we don't catch signals in event (pubsub) dispatcher */
pthread_sigmask(SIG_BLOCK, &mask, NULL);
pthread_sigmask(SIG_BLOCK, &threadmask, NULL);
/* Register with the event system: */
handle = event_register_withkeyfile(server, 1, keyfile);
......@@ -401,7 +340,7 @@ main(int argc, char *argv[])
fatal("could not register with event system");
}
pthread_sigmask(SIG_UNBLOCK, &mask, NULL);
pthread_sigmask(SIG_UNBLOCK, &threadmask, NULL);
/* Make a (not yet populated) list of things to do after initial swapin */
ns_sequence = create_timeline_agent(TA_SEQUENCE);
......@@ -487,96 +426,6 @@ main(int argc, char *argv[])
if (RPC_agentlist(handle, pid, eid))
fatal("Could not get agentlist from RPC server\n");
if (RPC_waitforrobots(handle, pid, eid))
fatal("waitforrobots: RPC failed!");
if (access("tbdata/emcd.config", R_OK) == 0) {
systemf("echo %d > tmp/event-sched.pid", getpid());
snprintf(emc_path,
sizeof(emc_path),
"%s/%s.%s.emcd",
_PATH_TMP,
pid,
eid);
emcd_pid = fork();
switch (emcd_pid) {
case -1:
fatal("could not start emcd");
break;
case 0:
execlp("emcd",
"emcd",
"-d",
"-l",
"logs/emcd.log",
"-c",
"tbdata/emcd.config",
"-e",
pideid,
"-U",
emc_path,
NULL);
exit(0);
break;
default:
break;
}
sleep(2);
rmcd_pid = fork();
switch (rmcd_pid) {
case -1:
fatal("could not start rmcd");
break;
case 0:
execlp("rmcd",
"rmcd",
"-dd",
"-l",
"logs/rmcd.log",
"-U",
emc_path,
NULL);
exit(0);
break;
default:
break;
}
sleep(2);
#if 1
vmcd_pid = fork();
switch (vmcd_pid) {
case -1:
fatal("could not start vmcd");
break;
case 0:
execlp("vmcd",
"vmcd",
"-d",
"-S",
"-w",
"5",
"-l",
"logs/vmcd.log",
"-U",
emc_path,
NULL);
exit(0);
break;
default:
break;
}
#else
systemf("vmcd -d -l logs/vmcd.log -e localhost -p 2626 "
"-c junk.flux.utah.edu -P 6969 &");
#endif
}
/*
* Read the static events list and schedule.
*/
......@@ -1379,45 +1228,6 @@ info("AddEvent called with event of triggertype %s\n", triggertype);
return 0;
}
int
AddRobot(event_handle_t handle,
struct agent *agent,
double init_x,
double init_y,
double init_o)
{
sched_event_t se;
int retval = 0;
assert(agent != NULL);
se.agent.s = agent;
se.notification = event_notification_create(
handle,
EA_Experiment, pideid,
EA_Type, TBDB_OBJECTTYPE_NODE,
EA_Event, TBDB_EVENTTYPE_SETDEST,
EA_Name, agent->name,
EA_ArgFloat, "X", init_x,
EA_ArgFloat, "Y", init_y,
EA_ArgFloat, "ORIENTATION", init_o,
EA_TAG_DONE);
event_notification_put_int32(handle,
se.notification,
"TOKEN",
next_token);
next_token += 1;
memset(&se.time, 0, sizeof(se.time));
se.length = 1;
se.flags = SEF_SENDS_COMPLETE | SEF_SINGLE_HANDLER;
sched_event_prepare(handle, &se);
timeline_agent_append(ns_sequence, &se);
return retval;
}
/*
* Get the static event list from the DB and schedule according to
* the relative time stamps.
......
/*
* Copyright (c) 2004-2014 University of Utah and the Flux Group.
* Copyright (c) 2004-2017 University of Utah and the Flux Group.
*
* {{{EMULAB-LICENSE
*
......@@ -391,88 +391,6 @@ int RPC_notifystart(char *pid, char *eid, char *timeline, int set_or_clear)
emulab::SPA_TAG_DONE);
}
static int
RPC_cameralist(FILE *emcd_config, char *area)
{
emulab::EmulabResponse er;
int lpc, rc;
assert(emcd_config != NULL);
assert(area != NULL);
rc = RPC_invoke("emulab.vision_config",
&er,
emulab::SPA_String, "area", area,
emulab::SPA_TAG_DONE);
if (rc < 0)
return -1;
vector<xmlrpc_c::value> cameras;
cameras = ((xmlrpc_c::value_array)er.getValue()).vectorValueValue();
for (lpc = 0; lpc < cameras.size(); lpc++) {
string tmp;
map<string, xmlrpc_c::value> attr;
int port;
attr = (xmlrpc_c::value_struct)cameras[lpc];
tmp = (xmlrpc_c::value_string)attr["hostname"];
port = (xmlrpc_c::value_int)attr["port"];
fprintf(emcd_config,
"camera %s %s %d %f %f %f %f %f %f\n",
area,
tmp.c_str(),
port,
((double)(xmlrpc_c::value_double)attr["loc_x"]),
((double)(xmlrpc_c::value_double)attr["loc_y"]),
((double)(xmlrpc_c::value_double)attr["width"]),
((double)(xmlrpc_c::value_double)attr["height"]),
((double)(xmlrpc_c::value_double)attr["fixed_x"]),
((double)(xmlrpc_c::value_double)attr["fixed_y"]));
}
return 0;
}
static int
RPC_obstaclelist(FILE *emcd_config, char *area)
{
emulab::EmulabResponse er;
int lpc, rc;
assert(emcd_config != NULL);
assert(area != NULL);
rc = RPC_invoke("emulab.obstacle_config",
&er,
emulab::SPA_String, "area", area,
emulab::SPA_String, "units", "meters",
emulab::SPA_TAG_DONE);
if (rc < 0)
return -1;
vector<xmlrpc_c::value> obstacles =
((xmlrpc_c::value_array)er.getValue()).vectorValueValue();
for (lpc = 0; lpc < obstacles.size(); lpc++) {
map<string, xmlrpc_c::value> attr =
(xmlrpc_c::value_struct)obstacles[lpc];
fprintf(emcd_config,
"obstacle %s %d %f %f %f %f\n",
area,
((int)(xmlrpc_c::value_int)attr["obstacle_id"]),
((double)(xmlrpc_c::value_double)attr["x1"]),
((double)(xmlrpc_c::value_double)attr["y1"]),
((double)(xmlrpc_c::value_double)attr["x2"]),
((double)(xmlrpc_c::value_double)attr["y2"]));
}
return 0;
}
int
RPC_waitforactive(char *pid, char *eid)
{
......@@ -486,113 +404,6 @@ RPC_waitforactive(char *pid, char *eid)
return RPC_invoke(pid, eid, "experiment.waitforactive", &er);
}
int
RPC_waitforrobots(event_handle_t handle, char *pid, char *eid)
{
emulab::EmulabResponse er;
int lpc, rc, retval = 0;
FILE *emcd_config;
unlink("tbdata/emcd.config");
rc = RPC_invoke("experiment.virtual_topology",
&er,
emulab::SPA_String, "proj", pid,
emulab::SPA_String, "exp", eid,
emulab::SPA_String, "tables", "node_startlocs",
emulab::SPA_TAG_DONE);
if (rc < 0)
return rc;
set<string> buildings;
vector<xmlrpc_c::value> top, locs;
map<string, xmlrpc_c::value> tables;
top = ((xmlrpc_c::value_array)er.getValue()).vectorValueValue();
tables = (xmlrpc_c::value_struct)top[0];
tables = ((xmlrpc_c::value_struct)tables["experiment"]);
locs = ((xmlrpc_c::value_array)tables["node_startlocs"]).vectorValueValue();
if (locs.size() == 0)
return 0;
info("info: waiting for robots\n");
if ((emcd_config = fopen("tbdata/emcd.config", "w")) == NULL) {
error("Cannot create emcd.config!\n");
return -1;
}
if (topography_name != NULL) {
fprintf(emcd_config, "topography %s\n", topography_name);
}
for (lpc = 0; lpc < locs.size(); lpc++) {
map<string, xmlrpc_c::value> loc;
emulab::EmulabResponse ner;
string bldg;
double x, y, orientation;
struct agent *agent;
char *vname;
loc = ((xmlrpc_c::value_struct)locs[lpc]);
vname =
(char *)((string)(xmlrpc_c::value_string)loc["vname"]).c_str();
bldg = (xmlrpc_c::value_string)loc["building"];
x = ((xmlrpc_c::value_double)loc["loc_x"]);
y = ((xmlrpc_c::value_double)loc["loc_y"]);
orientation =
((xmlrpc_c::value_double)loc["orientation"]);
if ((agent = (struct agent *)
lnFindName(&agents, vname)) == NULL) {
error("unknown robot %s\n", vname);
return -1;
}
else if ((rc = RPC_invoke(
"node.statewait",
&ner,
emulab::SPA_String, "node", agent->nodeid,
emulab::SPA_Integer, "timeout", ROBOT_TIMEOUT,
emulab::SPA_String, "state", "ISUP",
emulab::SPA_TAG_DONE)) < 0) {
error("robot %s did not come up!\n", agent->name);
return -1;
}
else {
fprintf(emcd_config,
"robot %s %d %s %f %f %f %s\n",
((string)(bldg)).c_str(),
lpc + 1,
agent->nodeid,
x,
y,
orientation * M_PI / 180.0,
agent->name);
buildings.insert((string)bldg);
AddRobot(handle, agent, x, y, orientation);
}
}
for (set<string>::iterator i = buildings.begin();
i != buildings.end();
i++) {
if (RPC_cameralist(emcd_config, (char *)(*i).c_str()) < 0)
return -1;
if (RPC_obstaclelist(emcd_config, (char *)(*i).c_str()) < 0)
return -1;
}
fclose(emcd_config);
emcd_config = NULL;
return retval;
}
int
RPC_agentlist(event_handle_t handle, char *pid, char *eid)
{
......
/*
* Copyright (c) 2004, 2005 University of Utah and the Flux Group.
* Copyright (c) 2004-2017 University of Utah and the Flux Group.
*
* {{{EMULAB-LICENSE
*
......@@ -74,7 +74,6 @@ int RPC_grab(void);
void RPC_drop(void);
int RPC_metadata(char *pid, char *eid);
int RPC_waitforrobots(event_handle_t handle, char *pid, char *eid);
expt_state_t RPC_expt_state(char *pid, char *eid);
int RPC_waitforactive(char *pid, char *eid);
int RPC_notifystart(char *pid, char *eid, char *timeline, int set_or_clear);
......@@ -98,12 +97,6 @@ extern int AddEvent(event_handle_t handle, address_tuple_t tuple,
const char *exargs, const char *objtype, const char *evttype,
const char *parent, const char *triggertype);
extern int AddRobot(event_handle_t handle,
struct agent *agent,
double init_x,
double init_y,
double init_orientation);
extern const char *XMLRPC_ROOT;
#ifdef __cplusplus
}
......
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