Commit 57b1c156 authored by David Anderson's avatar David Anderson
Browse files

Initial skeleton code for linktest daemon.

parent 1079131b
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#
SRCDIR = @srcdir@
TESTBED_SRCDIR = @top_srcdir@
OBJDIR = ../..
SUBDIR = event/linktest
SYSTEM := $(shell uname -s)
TESTS = linktest
include $(OBJDIR)/Makeconf
all: $(TESTS)
include $(TESTBED_SRCDIR)/GNUmakerules
CFLAGS += -DDEBUG
CFLAGS += -O -g -static -Wall
CFLAGS += -I. -I${OBJDIR} -I$(SRCDIR)/../lib -I$(TESTBED_SRCDIR)/lib/libtb
CFLAGS += `elvin-config --cflags vin4c`
LDFLAGS += -static -L../lib -L${OBJDIR}/lib/libtb
LIBS += -levent -ltb
LIBS += `elvin-config --libs vin4c`
ifeq ($(SYSTEM),Linux)
LIBS += -ldl
endif
linktest: linktest.o
$(CC) $(LDFLAGS) -o $@ linktest.o $(LIBS)
$(TESTS): ../lib/libevent.a ../lib/event.h
install:
client-install:
$(INSTALL_TEST) linktest \
$(DESTDIR)$(CLIENT_BINDIR)/linktest
clean:
/bin/rm -f *.o $(TESTS)
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2003 University of Utah and the Flux Group.
* All rights reserved.
*/
/*
* This is a program agent to manage programs from the event system.
*
* You can start, stop, and kill (signal) programs.
*/
#include <stdio.h>
#include <ctype.h>
#include <netdb.h>
#include <unistd.h>
#include <paths.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <pwd.h>
#include <time.h>
#include "tbdefs.h"
#include "log.h"
#include "event.h"
static void callback(event_handle_t handle,
event_notification_t notification, void *data);
void
usage(char *progname)
{
fprintf(stderr,
"Usage: %s [-s server] [-p port] [-l logfile] -e pid/eid\n",
progname);
exit(-1);
}
int main(int argc, char **argv) {
event_handle_t handle;
address_tuple_t tuple;
char *server = NULL;
char *port = NULL;
char *pideid = NULL;
char *logfile = NULL;
char *progname;
char c;
char buf[BUFSIZ];
progname = argv[0];
while ((c = getopt(argc, argv, "s:p:e:")) != -1) {
switch (c) {
case 's':
server = optarg;
break;
case 'p':
port = optarg;
break;
case 'e':
pideid = optarg;
break;
case 'l':
logfile = optarg;
break;
default:
usage(progname);
}
}
if (!pideid)
usage(progname);
info("starting up\n");
loginit(0, logfile);
/*
* Convert server/port to elvin thing.
*
* XXX This elvin string stuff should be moved down a layer.
*/
if (server) {
snprintf(buf, sizeof(buf), "elvin://%s%s%s",
server,
(port ? ":" : ""),
(port ? port : ""));
server = buf;
}
/*
* Construct an address tuple for subscribing to events for
* this node.
*/
tuple = address_tuple_alloc();
if (tuple == NULL) {
fatal("could not allocate an address tuple");
}
/*
* Ask for just the program agents we care about.
*/
tuple->expt = pideid;
tuple->objtype = TBDB_OBJECTTYPE_LINKTEST;
tuple->objname = "linktest";
tuple->eventtype = ADDRESSTUPLE_ANY;
/*
* Register with the event system.
*/
info("event_register...\n");
handle = event_register(server, 0);
if (handle == NULL) {
fatal("could not register with event system");
}
info("registered with event system\n");
/*
* Subscribe to the event we specified above.
*/
if (! event_subscribe(handle, callback, tuple, NULL)) {
fatal("could not subscribe to event");
}
info("subscribed to event\n");
/*
* Begin the event loop, waiting to receive event notifications:
*/
info("starting main event loop\n");
event_main(handle);
info("end main event loop\n");
/*
* Unregister with the event system:
*/
if (event_unregister(handle) == 0) {
fatal("could not unregister with event system");
}
return 0;
}
/*
* Handle the events.
*/
static void
callback(event_handle_t handle, event_notification_t notification, void *data)
{
char objname[TBDB_FLEN_EVOBJTYPE];
char event[TBDB_FLEN_EVEVENTTYPE];
char args[BUFSIZ];
struct timeval now;
gettimeofday(&now, NULL);
info("got a callback\n");
if (! event_notification_get_objname(handle, notification,
objname, sizeof(objname))) {
error("Could not get objname from notification!\n");
return;
}
if (! event_notification_get_eventtype(handle, notification,
event, sizeof(event))) {
error("Could not get event from notification!\n");
return;
}
event_notification_get_arguments(handle,
notification, args, sizeof(args));
info("Event: %lu:%d %s %s %s\n", now.tv_sec, now.tv_usec,
objname, event, args);
}
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