static void initialize(void) { if (!dsme_log_open(LOG_METHOD_STDOUT, 7, false, " ", 0, 0, "")) { fatal("dsme_log_open() failed"); } setenv("DSME_RD_FLAGS_ENV", rd_mode, true); }
static void initialize(void) { if (!dsme_log_open(LOG_METHOD_STDOUT, 7, false, " ", 0, 0, "")) { fatal("dsme_log_open() failed"); } initialize_dbus_stub(); }
/** @todo Possibility to alter priority of initial module somehow */ int main(int argc, char *argv[]) { GSList* module_names = 0; signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); signal(SIGHUP, signal_handler); signal(SIGPIPE, signal_handler); /* protect DSME from oom; notice that this must be done before any * calls to pthread_create() in order to have all threads protected */ if (!protect_from_oom()) { fprintf(stderr, ME "Couldn't protect from oom: %s\n", strerror(errno)); } /* Set static priority for RT-scheduling */ int scheduler; struct sched_param param; scheduler = sched_getscheduler(0); if(sched_getparam(0, ¶m) == 0) { param.sched_priority = sched_get_priority_min(scheduler); if(sched_setparam(0, ¶m) != 0) { fprintf(stderr, ME "Couldn't set static priority: %s\n", strerror(errno)); } } else { fprintf(stderr, ME "Couldn't get scheduling params: %s\n", strerror(errno)); } /* Set nice value for cases when dsme-server is not under RT-scheduling*/ if (setpriority(PRIO_PROCESS, 0, DSME_PRIORITY) != 0) { fprintf(stderr, ME "Couldn't set dynamic priority: %s\n", strerror(errno)); } parse_options(argc, argv, &module_names); if (!module_names) { usage(argv[0]); return EXIT_FAILURE; } #ifdef DSME_LOG_ENABLE dsme_log_open(logging_method, logging_verbosity, 0, "DSME", 0, 0, "/var/log/dsme.log"); #endif /* load modules */ if (!modulebase_init(module_names)) { g_slist_free(module_names); #ifdef DSME_LOG_ENABLE dsme_log_close(); #endif return EXIT_FAILURE; } g_slist_free(module_names); /* init socket communication */ if (dsmesock_listen(receive_and_queue_message) == -1) { dsme_log(LOG_CRIT, "Error creating DSM socket: %s", strerror(errno)); #ifdef DSME_LOG_ENABLE dsme_log_close(); #endif return EXIT_FAILURE; } /* set running directory */ if (chdir("/") == -1) { dsme_log(LOG_CRIT, "chdir failed: %s", strerror(errno)); return EXIT_FAILURE; } #ifdef DSME_SYSTEMD_ENABLE /* Inform main process that we are ready * Main process will inform systemd */ if (signal_systemd) { kill(getppid(), SIGUSR1); } #endif dsme_log(LOG_DEBUG, "Entering main loop"); dsme_main_loop_run(process_message_queue); dsme_log(LOG_CRIT, "Exited main loop, quitting"); dsmesock_shutdown(); modulebase_shutdown(); #ifdef DSME_LOG_ENABLE dsme_log_close(); #endif return dsme_main_loop_exit_code(); }