int main(int argc, char *argv[]) { printf("%s: Task Monitoring Service\n", NAME); if (event_subscribe(EVENT_FAULT, 0) != EOK) { printf("%s: Error registering fault notifications.\n", NAME); return -1; } async_set_interrupt_received(fault_event); task_retval(0); async_manager(); return 0; }
int main(int argc, char **argv) { uint64_t mousefd; mousefd = fs_find("/dev/mouse"); if (!mousefd) { fprintf(stderr, "%s: couldn't find mouse\n", argv[0]); return 1; } event_subscribe(mousefd); event_hook("mouse", mouse_event); _done(); return 0; }
int EventInit(char *server) { char buf[BUFSIZ], ipbuf[BUFSIZ]; struct hostent *he; struct in_addr myip; char *ipaddr; address_tuple_t tuple; if (server == NULL) { warning("no event server specified"); return 1; } if (gethostname(buf, sizeof(buf)) < 0) { pwarning("could not get hostname"); return 1; } if ((he = gethostbyname(buf)) == NULL) { warning("could not get IP address from hostname"); return 1; } memcpy((char *)&myip, he->h_addr, he->h_length); strcpy(ipbuf, inet_ntoa(myip)); ipaddr = ipbuf; /* * Hideous Hack Alert! * * Assume our hostname is of the form 'c-<num>.<domain>' * and use <num> to determine our client number. * We use that number later to compare to the MAXCLIENTS * field to determine if we should process an event. */ if (sscanf(buf, "c-%d.", &clientnum) != 1) { warning("could not determine client number from hostname %s", buf); return 1; } else if (debug) log("client number %d for event handling", clientnum); /* * Convert server/port to elvin thing. */ snprintf(buf, sizeof(buf), "elvin://%s", server); server = buf; /* * Construct an address tuple for subscribing to events for * this node. */ tuple = address_tuple_alloc(); if (tuple == NULL) { warning("could not allocate an address tuple"); return 1; } tuple->host = ADDRESSTUPLE_ANY; /* ipaddr; */ tuple->site = ADDRESSTUPLE_ANY; tuple->group = ADDRESSTUPLE_ANY; tuple->expt = ADDRESSTUPLE_ANY; tuple->objtype = TBDB_OBJECTTYPE_FRISBEE; tuple->objname = ADDRESSTUPLE_ANY; tuple->eventtype = ADDRESSTUPLE_ANY; /* * Register with the event system. */ ehandle = event_register(server, 0); if (ehandle == NULL) { warning("could not register with event system"); address_tuple_free(tuple); return 1; } /* * Subscribe to the event we specified above. */ if (!event_subscribe(ehandle, callback, tuple, NULL)) { warning("could not subscribe to FRISBEE events"); address_tuple_free(tuple); return 1; } address_tuple_free(tuple); return 0; }
int main(int argc, char **argv) { address_tuple_t tuple; char *progname; char *server = NULL; char *port = NULL; char *myeid = NULL; char *pidfile = NULL; char *vnodeid = NULL; char buf[BUFSIZ], ipaddr[32]; char hostname[MAXHOSTNAMELEN]; struct hostent *he; int c; struct in_addr myip; FILE *fp; progname = argv[0]; while ((c = getopt(argc, argv, "ds:p:e:i:v:")) != -1) { switch (c) { case 'd': debug++; break; case 's': server = optarg; break; case 'p': port = optarg; break; case 'i': pidfile = optarg; break; case 'e': myeid = optarg; break; case 'v': vnodeid = optarg; break; default: usage(progname); } } argc -= optind; argv += optind; if (argc) usage(progname); if (! myeid) fatal("Must provide pid/eid"); if (debug) loginit(0, 0); else { loginit(1, "evproxy"); /* See below for daemonization */ } /* * Get our IP address. Thats how we name this host to the * event System. */ if (gethostname(hostname, MAXHOSTNAMELEN) == -1) { fatal("could not get hostname: %s\n", strerror(errno)); } if (! (he = gethostbyname(hostname))) { fatal("could not get IP address from hostname: %s", hostname); } memcpy((char *)&myip, he->h_addr, he->h_length); strcpy(ipaddr, inet_ntoa(myip)); /* * If server is not specified, then it defaults to EVENTSERVER. * This allows the client to work on either users.emulab.net * or on a client node. */ if (!server) server = "event-server"; /* * XXX Need to daemonize earlier or the threads go away. */ if (!debug) daemon(0, 0); /* * Convert server/port to elvin thing. * * XXX This elvin string stuff should be moved down a layer. */ snprintf(buf, sizeof(buf), "elvin://%s%s%s", server, (port ? ":" : ""), (port ? port : "")); server = buf; /* * Construct an address tuple for generating the event. */ tuple = address_tuple_alloc(); if (tuple == NULL) { fatal("could not allocate an address tuple"); } /* Register with the event system on boss */ bosshandle = event_register(server, 1); if (bosshandle == NULL) { fatal("could not register with remote event system"); } /* Register with the event system on the local node */ localhandle = event_register("elvin://localhost", 1); if (localhandle == NULL) { fatal("could not register with local event system"); } /* * Create a subscription to pass to the remote server. We want * all events for this node, or all events for the experiment * if the node is unspecified (we want to avoid getting events * that are directed at specific nodes that are not us!). */ sprintf(buf, "%s,%s", ADDRESSTUPLE_ALL, ipaddr); tuple->host = buf; tuple->expt = myeid; /* Subscribe to the test event: */ if (! event_subscribe(bosshandle, callback, tuple, "event received")) { fatal("could not subscribe to events on remote server"); } tuple->host = ADDRESSTUPLE_ALL; tuple->scheduler = 1; if (! event_subscribe(localhandle, sched_callback, tuple, NULL)) { fatal("could not subscribe to events on remote server"); } signal(SIGTERM, sigterm); /* * Stash the pid away. */ if (! pidfile) { sprintf(buf, "%s/evproxy.pid", _PATH_VARRUN); pidfile = buf; } fp = fopen(pidfile, "w"); if (fp != NULL) { fprintf(fp, "%d\n", getpid()); (void) fclose(fp); } /* Begin the event loop, waiting to receive event notifications */ while (! stop) { struct timeval tv = { 5, 0 }; select(0, NULL, NULL, NULL, &tv); } unlink(pidfile); /* Unregister with the remote event system: */ if (event_unregister(bosshandle) == 0) { fatal("could not unregister with remote event system"); } /* Unregister with the local event system: */ if (event_unregister(localhandle) == 0) { fatal("could not unregister with local event system"); } return 0; }
int main(int argc, char **argv) { address_tuple_t tuple; char *server = NULL; char *port = NULL; char *keyfile = NULL; char *pidfile = NULL; char *logfile = NULL; char *progname; char c; char buf[BUFSIZ]; extern char build_info[]; pideid = NULL; progname = argv[0]; while ((c = getopt(argc, argv, "s:p:e:l:dk:i:Vu:N:")) != -1) { switch (c) { case 'd': debug++; break; case 's': server = optarg; break; case 'p': port = optarg; break; case 'e': pideid = optarg; break; case 'i': pidfile = optarg; break; case 'l': logfile = optarg; break; case 'k': keyfile = optarg; break; case 'u': swapper = optarg; break; case 'N': nodelocal_dir = optarg; break; case 'V': fprintf(stderr, "%s\n", build_info); exit(0); break; default: usage(progname); } } if (!pideid) usage(progname); if (debug) loginit(0, 0); else { if (logfile) loginit(0, logfile); else loginit(1, "linktest"); /* See below for daemonization */ } /* * 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 events we care about. */ tuple->expt = pideid; tuple->objtype = TBDB_OBJECTTYPE_LINKTEST; tuple->eventtype = TBDB_EVENTTYPE_START "," TBDB_EVENTTYPE_KILL; /* * Register with the event system. */ handle = event_register_withkeyfile(server, 0, keyfile); if (handle == NULL) { fatal("could not register with event system"); } /* * Subscribe to the event we specified above. */ if (! event_subscribe(handle, callback, tuple, NULL)) { fatal("could not subscribe to event"); } tuple->objtype = TBDB_OBJECTTYPE_TIME; tuple->objname = ADDRESSTUPLE_ANY; tuple->eventtype = TBDB_EVENTTYPE_START; /* * Subscribe to the TIME start event we specified above. */ if (! event_subscribe(handle, start_callback, tuple, NULL)) { fatal("could not subscribe to event"); } /* * Do this now, once we have had a chance to fail on the above * event system calls. */ if (!debug) daemon(0, 1); /* * Write out a pidfile if root (after we daemonize). */ if (!getuid()) { FILE *fp; if (pidfile) strcpy(buf, pidfile); else sprintf(buf, "%s/linktest.pid", _PATH_VARRUN); fp = fopen(buf, "w"); if (fp != NULL) { fprintf(fp, "%d\n", getpid()); (void) fclose(fp); } } /* * Initialize variables used to control child execution */ locked = FALSE; if(signal(SIGCHLD,sigchld_handler) == SIG_ERR) { fatal("could not install child handler"); } /* * Begin the event loop, waiting to receive event notifications: */ event_main(handle); /* * Unregister with the event system: */ if (event_unregister(handle) == 0) { fatal("could not unregister with event system"); } return 0; }
void tgevent_init(int argc, char *argv[]) { address_tuple_t tuple; char *server = "localhost"; char *port = NULL; char *ipaddr = NULL; char *myname = NULL; char *keyfile = NULL; char buf[BUFSIZ], ipbuf[BUFSIZ]; struct sockaddr saddr, taddr; int c, gotsaddr = 0; progname = argv[0]; memset(&saddr, 0, sizeof(saddr)); memset(&taddr, 0, sizeof(taddr)); while ((c = getopt(argc, argv, "s:p:S:T:P:R:N:l:E:k:")) != -1) { switch (c) { case 's': server = optarg; break; case 'p': port = optarg; break; case 'S': if (!ipport_atoaddr(optarg, &saddr)) badaddr(); gotsaddr = 1; break; case 'T': if (!ipport_atoaddr(optarg, &taddr)) badaddr(); break; case 'P': prot.prot = find_protocol(optarg); break; case 'R': if (strcmp(optarg, "server") == 0 || strcmp(optarg, "sink") == 0) prot.qos |= QOS_SERVER; break; case 'N': myname = optarg; break; case 'E': myexp = optarg; break; case 'l': logfile = optarg; break; case 'k': keyfile = optarg; break; default: usage(); } } if (prot.prot == NULL) badprot(); if (prot.qos & QOS_SERVER) { prot.src = taddr; prot.qos |= QOS_SRC; } else { prot.dst = taddr; prot.qos |= QOS_DST; /* * Can specify source address to bind local interface * of sender. */ if (gotsaddr) { prot.src = saddr; prot.qos |= QOS_SRC; } } argc -= optind; argv += optind; #ifndef TESTING /* * Get our IP address. Thats how we name ourselves to the * Testbed Event System. */ if (ipaddr == NULL) { struct hostent *he; struct in_addr myip; if (gethostname(buf, sizeof(buf)) < 0) { fatal("could not get hostname"); } if (! (he = gethostbyname(buf))) { fatal("could not get IP address from hostname"); } memcpy((char *)&myip, he->h_addr, he->h_length); strcpy(ipbuf, inet_ntoa(myip)); ipaddr = ipbuf; } /* * 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"); } /* * Do not use the ipaddr if we have a pid/eid. This allows * trafgens to work inside jails that have their own IP. */ if (myexp) { tuple->expt = myexp; tuple->host = ADDRESSTUPLE_ANY; } else { tuple->host = ipaddr; tuple->expt = ADDRESSTUPLE_ANY; } tuple->site = ADDRESSTUPLE_ANY; tuple->group = ADDRESSTUPLE_ANY; tuple->objtype = TBDB_OBJECTTYPE_TRAFGEN; tuple->objname = myname ? myname : ADDRESSTUPLE_ANY; tuple->eventtype = ADDRESSTUPLE_ANY; /* * Register with the event system. */ ehandle = event_register_withkeyfile(server, 0, keyfile); if (ehandle == NULL) { fatal("could not register with event system"); } /* * Subscribe to the event we specified above. */ if (!event_subscribe(ehandle, callback, tuple, NULL)) { fatal("could not subscribe to TRAFGEN events"); } address_tuple_free(tuple); /* * Also subscribe to the start time event which we use to * synchronize connection setup. */ tuple = address_tuple_alloc(); if (tuple == NULL) { fatal("could not allocate an address tuple"); } tuple->host = ADDRESSTUPLE_ANY; tuple->site = ADDRESSTUPLE_ANY; tuple->group = ADDRESSTUPLE_ANY; tuple->expt = myexp ? myexp : ADDRESSTUPLE_ANY; tuple->objtype = TBDB_OBJECTTYPE_TIME; tuple->objname = ADDRESSTUPLE_ANY; tuple->eventtype = ADDRESSTUPLE_ANY; if (!event_subscribe(ehandle, callback, tuple, NULL)) { fatal("could not subscribe to TIME events"); } address_tuple_free(tuple); #endif }