int main(int argc, char **argv) { log_t* loghandle; void* libhandle; int retcode; struct sigaction sa_quit; handler_api_t handler_api; sys_config_t* system_config; system_config = sys_get_config(); mcp_parse_arguments(argc, argv, system_config); if(system_config->debug == LOG_NOFLAGS && util_file_stat(system_config->pidfile) != 0) { fprintf(stderr, "%s: PID file %s exists! Not starting.\n", argv[0], system_config->pidfile); exit(EXIT_FAILURE); } libhandle = dlopen(system_config->libfile, RTLD_NOW); if(!libhandle) { fprintf(stderr, "%s: Could not load handler library: %s\n", argv[0], dlerror()); exit(EXIT_FAILURE); } if(sys_initapi(libhandle, &handler_api) != 0) { fprintf(stderr, "%s: Specified handler library is invalid", argv[0]); dlclose(libhandle); exit(EXIT_FAILURE); } loghandle = log_open(system_config->logfile, system_config->debug); if(!loghandle) { fprintf(stderr, "%s: Could not open log file: %s\n", argv[0], MCPROXY_LOGFILE); dlclose(libhandle); exit(EXIT_FAILURE); } log_set_default(loghandle); if(system_config->debug == LOG_NOFLAGS) mcp_daemonize(); memset(&sa_quit, 0, sizeof(struct sigaction)); sa_quit.sa_handler = sig_quit; sigaction(SIGTERM, &sa_quit, NULL); sigaction(SIGINT, &sa_quit, NULL); if(system_config->debug == LOG_NOFLAGS) util_file_writepid(system_config->pidfile); retcode = core_main(system_config, &handler_api); log_close(loghandle); dlclose(libhandle); if(system_config->debug == LOG_NOFLAGS) unlink(system_config->pidfile); exit(retcode); }
/** Reset a log type for a subsystem to its default value. * @param[in] from &Client trying to reset the subsystem. * @param[in] fields Array of parameters to reset. * @param[in] count Number of fields in \a fields. * @return -1 to unmark the entry, or zero to leave it alone. */ static int feature_log_reset(struct Client* from, const char* const* fields, int count) { struct LogTypes *desc; char *subsys; assert(0 != from); /* Never called by the .conf parser */ if (count < 1) { /* reset default facility */ log_set_default(0); return -1; /* unmark this entry */ } else if (count < 2) need_more_params(from, "RESET"); else if (!(subsys = log_canon(fields[0]))) /* no such subsystem */ send_reply(from, ERR_BADLOGSYS, fields[0]); else if ((desc = feature_log_desc(from, fields[1]))) /* reset value */ (*desc->set)(fields[0], 0); /* default should always be accepted */ return 0; }
/** Set the value of a log output type for a log subsystem. * @param[in] from &Client trying to set the log type, or NULL. * @param[in] fields Array of parameters to set. * @param[in] count Number of parameters in \a fields. * @return -1 to clear the mark, 0 to leave the mask alone, 1 to set the mask. */ static int feature_log_set(struct Client* from, const char* const* fields, int count) { struct LogTypes *desc; char *subsys; if (count < 2) { /* set default facility */ if (log_set_default(count < 1 ? 0 : fields[0])) { assert(count >= 1); /* should always accept default */ if (from) /* send an error */ send_reply(from, ERR_BADLOGVALUE, fields[0]); else log_write(LS_CONFIG, L_ERROR, 0, "Bad value \"%s\" for default facility", fields[0]); } else return count < 1 ? -1 : 1; /* tell feature to set or clear mark */ } else if (!(subsys = log_canon(fields[0]))) { /* no such subsystem */ if (from) /* send an error */ send_reply(from, ERR_BADLOGSYS, fields[0]); else log_write(LS_CONFIG, L_ERROR, 0, "No such logging subsystem \"%s\"", fields[0]); } else if ((desc = feature_log_desc(from, fields[1]))) { /* set value */ if ((*desc->set)(fields[0], count < 3 ? 0 : fields[2])) { assert(count >= 3); /* should always accept default */ if (from) /* send an error */ send_reply(from, ERR_BADLOGVALUE, fields[2]); else log_write(LS_CONFIG, L_ERROR, 0, "Bad value \"%s\" for log type %s (subsystem %s)", fields[2], desc->type, subsys); } } return 0; }