Commit 0dc70563 authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Kill off ERROR/TRACE from the external header file; do not want to

export that stuff.
Add signal handlers to ensure that INT/TERM/HUP signals are caught and
that we exit cleanly (clearing the pid from the DB).
Minor rework for DB table structure and the switch from per-experiment
event tables to a single event table indexed by pid,eid.
parent 01a33700
......@@ -14,6 +14,7 @@
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
......@@ -32,6 +33,7 @@ static char *pid, *eid;
static int get_static_events(event_handle_t handle);
static int debug;
static void cleanup(void);
static void quit(int);
void
usage()
......@@ -84,6 +86,10 @@ main(int argc, char **argv)
pid = argv[0];
eid = argv[1];
signal(SIGINT, quit);
signal(SIGTERM, quit);
signal(SIGHUP, quit);
if (debug)
loginit(0, log);
else
......@@ -96,11 +102,13 @@ main(int argc, char **argv)
return 1;
/*
* Set our pid in the DB.
* Set our pid in the DB. This will fail if there is already
* a non-zero value in the DB (although its okay to set it to
* zero no matter what).
*/
atexit(cleanup);
if (! mydb_seteventschedulerpid(pid, eid, getpid()))
fatal("Could not update DB with process id!");
atexit(cleanup);
/*
* Convert server/port to elvin thing.
......@@ -304,18 +312,19 @@ get_static_events(event_handle_t handle)
char pideid[BUFSIZ];
res = mydb_query("select ex.time,ex.vnode,ex.vname,ex.arguments,"
" ot.type,et.type,i.IP from %s_%s_events as ex "
" ot.type,et.type,i.IP from eventlist as ex "
"left join event_eventtypes as et on "
" ex.eventtype=et.idx "
"left join event_objecttypes as ot on "
" ex.objecttype=ot.idx "
"left join reserved as r on "
" ex.vnode=r.vname and r.pid='%s' and r.eid='%s' "
" ex.vnode=r.vname and ex.pid=r.pid and ex.eid=r.eid "
"left join nodes as n on r.node_id=n.node_id "
"left join node_types as nt on nt.type=n.type "
"left join interfaces as i on "
" i.node_id=r.node_id and i.iface=nt.control_iface",
7, pid, eid, pid, eid);
" i.node_id=r.node_id and i.iface=nt.control_iface "
"where ex.pid='%s' and ex.eid='%s'",
7, pid, eid);
#define EXTIME row[0]
#define EXVNODE row[1]
#define EXVNAME row[2]
......@@ -398,4 +407,13 @@ cleanup(void)
{
if (pid)
mydb_seteventschedulerpid(pid, eid, 0);
pid = NULL;
eid = NULL;
}
static void
quit(int sig)
{
/* cleanup() will be called from atexit() */
exit(0);
}
......@@ -6,7 +6,7 @@
*
* @COPYRIGHT@
*
* $Id: event-sched.h,v 1.3 2002-02-19 17:12:52 stoller Exp $
* $Id: event-sched.h,v 1.4 2002-03-05 16:21:24 stoller Exp $
*/
#ifndef __SCHED_H__
......@@ -15,6 +15,7 @@
#include <stdio.h>
#include <sys/time.h>
#include "event.h"
#include "log.h"
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
......@@ -26,6 +27,16 @@ typedef struct sched_event {
struct timeval time; /* event firing time */
} sched_event_t;
/*
* Debugging and tracing definitions:
*/
#define ERROR(fmt,...) error(__FUNCTION__ ": " fmt, ## __VA_ARGS__)
#ifdef DEBUG
#define TRACE(fmt,...) info(__FUNCTION__ ": " fmt, ## __VA_ARGS__)
#else
#define TRACE(fmt,...)
#endif /* DEBUG */
/*
* Function prototypes:
*/
......
......@@ -263,7 +263,7 @@ sched_event_queue_dump_node_and_descendents(FILE *fp, int index, int level)
static void
sched_event_queue_verify(void)
{
int error, i;
int err, i;
/* Slot 0 should never be used. */
assert(event_queue[0].time.tv_sec == 0 &&
......@@ -271,17 +271,17 @@ sched_event_queue_verify(void)
/* Verify the heap property: The firing time of each node N should
be more recent than the firing time of its children 2N and 2N+1. */
error = 0;
err = 0;
for (i = EVENT_QUEUE_HEAD; i <= event_queue_tail; i++) {
if (2 * i <= event_queue_tail) {
if (!event_is_more_recent(event_queue[i], event_queue[2 * i]))
error = 1;
err = 1;
}
if (2 * i + 1 <= event_queue_tail) {
if (!event_is_more_recent(event_queue[i], event_queue[2 * i + 1]))
error = 1;
err = 1;
}
if (error) {
if (err) {
ERROR("node %d violates the heap property:\n", i);
sched_event_queue_dump_node_and_descendents(stderr, i, 2);
abort();
......
Supports Markdown
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