int ifmonitor_cb(int b, int index, unsigned short type, const char *name) { if (!name) return 0; struct interface_state *iface, *prev = NULL; for(iface = interface; iface; iface = iface->next) { if(strcmp(iface->name, name)) continue; if(!b) drop_interface(iface); goto exit; } if(!b) goto exit; if(is_iface_available(netlink, name)) add_interface(name); exit: return 0; }
void set_condemn_building( string building ) { object ob; if( ob = single_present(building, environment(this_player())) ) { string bname = ob->query_distant(); if( !ob->query_is_building() ) { msg( "That's not a building, and may not be condemned." ); return; } if( ob->query_name() == "foundstone" ) { msg( "Condemnation signs may not be used to destroy a foundstone." ); return; } condemn_time = time() + 2 * 365 * 24 * 120; // 120 seconds per hour on Walraven... condemn_time = (condemn_time/2880) * 2880; // Round to an even date. condemn_obj = to_objectref(ob); drop_interface(); set_message( "This building, "+ob->query_distant()+", was ~CWRNcondemned~CDEF by ~CBRT" + capitalize(this_player()->query_name()) + "~CDEF on " + "/daemon/time"->query_date() + ". To remove " "the condemnation, simply raze this sign. To enforce the condemnation, you " "should ~CCOMuse sign~CDEF after the warning time expires. Warning expires two years from the date posted." ); msg( "OK, you'll condemn " + bname + ". Come back when the warning expires!" ) ; return; } else if( building == "cancel" ) { msg( "Never mind, then." ); destruct(this_object()); return; } else { msg( "Couldn't identify that building. Try again, or type 'cancel' to quit." ); return; } }
void work(void) { fd_set fds; int sigfd; static char log_ident[256]; snprintf(log_ident, sizeof(log_ident), "ifplugd"); daemon_log_ident = log_ident; daemon_log(LOG_INFO, "ifplugd "VERSION" initializing, using NETLINK device monitoring"); if (daemon_pid_file_create() < 0) { daemon_log(LOG_ERR, "Could not create PID file %s.", daemon_pid_file_proc()); goto finish; } if (daemon_signal_init(SIGINT, SIGTERM, SIGQUIT, SIGHUP, SIGCHLD, SIGUSR1, SIGUSR2, -1) < 0) { daemon_log(LOG_ERR, "Could not register signal handler: %s", strerror(errno)); goto finish; } if ((netlink = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) { daemon_log(LOG_ERR, "socket(): %s", strerror(errno)); goto finish; } rbus = rbus_init("unix!/tmp/ifplugd.9p"); rbus->rbus.childs = &root_children[0]; discover(netlink); if (nlapi_open(RTMGRP_LINK) < 0) goto finish; if (ifmonitor_init(ifmonitor_cb) < 0) goto finish; FD_ZERO(&fds); sigfd = daemon_signal_fd(); FD_SET(sigfd, &fds); FD_SET(nlapi_fd, &fds); for (;;) { struct interface_state *iface; fd_set qfds = fds; struct timeval tv; IxpConn *c; for(c = rbus->srv->conn; c; c = c->next) { if(c->read) { FD_SET(c->fd, &qfds); } } tv.tv_sec = polltime; tv.tv_usec = 0; if (select(FD_SETSIZE, &qfds, NULL, NULL, &tv) < 0) { if (errno == EINTR) continue; daemon_log(LOG_ERR, "select(): %s", strerror(errno)); goto finish; } //daemon_log(LOG_INFO, "select()"); for(c = rbus->srv->conn; c; c = c->next) { if(c->read && FD_ISSET(c->fd, &qfds)) { c->read(c); } } if (FD_ISSET(nlapi_fd, &qfds)) { if (nlapi_work(0) < 0) goto finish; } for(iface = interface; iface; iface=iface->next) { if(! is_iface_available(netlink, iface->name)) { drop_interface(iface); continue; } detect_beat(netlink, iface); status_change(iface); } if (FD_ISSET(sigfd, &qfds)) { int sig; if ((sig = daemon_signal_next()) < 0) { daemon_log(LOG_ERR, "daemon_signal_next(): %s", strerror(errno)); goto finish; } switch (sig) { case SIGINT: case SIGTERM: goto cleanup; case SIGQUIT: goto finish; case SIGCHLD: break; case SIGHUP: break; default: daemon_log(LOG_INFO, "Ignoring unknown signal %s", strsignal(sig)); break; } } } cleanup: finish: if (netlink >= 0) close(netlink); nlapi_close(); daemon_pid_file_remove(); daemon_signal_done(); daemon_log(LOG_INFO, "Exiting."); }