static int logging_cleanup(void **state) { sr_logger_cleanup(); return 0; }
static int teardown(void **state) { sm_ctx_t *ctx = *state; sm_cleanup(ctx); sr_logger_cleanup(); return 0; }
static int rp_teardown(void **state) { rp_ctx_t *rp_ctx = *state; assert_non_null(rp_ctx); rp_cleanup(rp_ctx); sr_logger_cleanup(); return 0; }
static int cm_teardown(void **state) { cm_ctx_t *ctx = *state; assert_non_null(ctx); cm_stop(ctx); cm_cleanup(ctx); sr_logger_cleanup(); return 0; }
static int test_teardown(void **state) { test_ctx_t *test_ctx = *state; assert_non_null(test_ctx); test_rp_session_cleanup(test_ctx->rp_ctx, test_ctx->rp_session_ctx); test_rp_ctx_cleanup(test_ctx->rp_ctx); free(test_ctx); sr_logger_cleanup(); return 0; }
/** * @brief Main routine of the sysrepo daemon. */ int main(int argc, char* argv[]) { sr_pd_ctx_t ctx = { 0, }; pid_t parent_pid = 0; int pidfile_fd = -1; int c = 0; bool debug_mode = false; int log_level = -1; int rc = SR_ERR_OK; while ((c = getopt (argc, argv, "hvdDl:")) != -1) { switch (c) { case 'v': sr_pd_print_version(); return 0; break; case 'd': debug_mode = true; break; case 'D': connect_options |= SR_CONN_DAEMON_START; break; case 'l': log_level = atoi(optarg); break; default: sr_pd_print_help(); return 0; } } /* init logger */ sr_logger_init("sysrepo-plugind"); /* daemonize the process */ parent_pid = sr_daemonize(debug_mode, log_level, SR_PLUGIN_DAEMON_PID_FILE, &pidfile_fd); SR_LOG_DBG_MSG("Sysrepo plugin daemon initialization started."); /* init the event loop */ ctx.event_loop = ev_loop_new(EVFLAG_AUTO); /* init signal watchers */ ev_signal_init(&ctx.signal_watcher[0], sr_pd_signal_cb, SIGTERM); ev_signal_start(ctx.event_loop, &ctx.signal_watcher[0]); ev_signal_init(&ctx.signal_watcher[1], sr_pd_signal_cb, SIGINT); ev_signal_start(ctx.event_loop, &ctx.signal_watcher[1]); /* init timers */ ev_timer_init(&ctx.health_check_timer, sr_pd_health_check_timer_cb, SR_PLUGIN_HEALTH_CHECK_TIMEOUT, SR_PLUGIN_HEALTH_CHECK_TIMEOUT); ctx.health_check_timer.data = &ctx; ev_timer_init(&ctx.init_retry_timer, sr_pd_init_retry_timer_cb, SR_PLUGIN_INIT_RETRY_TIMEOUT, SR_PLUGIN_INIT_RETRY_TIMEOUT); ctx.init_retry_timer.data = &ctx; /* connect to sysrepo */ rc = sr_connect("sysrepo-plugind", connect_options, &ctx.connection); CHECK_RC_LOG_GOTO(rc, cleanup, "Unable to connect to sysrepod: %s", sr_strerror(rc)); /* start the session */ rc = sr_session_start(ctx.connection, SR_DS_STARTUP, SR_SESS_DEFAULT, &ctx.session); CHECK_RC_LOG_GOTO(rc, cleanup, "Unable to connect to sysrepo: %s", sr_strerror(rc)); /* tell the parent process that we are okay */ if (!debug_mode) { sr_daemonize_signal_success(parent_pid); } /* load the plugins */ rc = sr_pd_load_plugins(&ctx); SR_LOG_INF_MSG("Sysrepo plugin daemon initialized successfully."); /* start health check timer */ ev_timer_start(ctx.event_loop, &ctx.health_check_timer); /* run the event loop */ ev_run(ctx.event_loop, 0); ev_loop_destroy(ctx.event_loop); /* check whether the session is still valid & reconnect if needed */ sr_pd_session_check(&ctx); cleanup: sr_pd_cleanup_plugins(&ctx); if (NULL != ctx.session) { sr_session_stop(ctx.session); } if (NULL != ctx.connection) { sr_disconnect(ctx.connection); } SR_LOG_INF_MSG("Sysrepo plugin daemon terminated."); sr_logger_cleanup(); unlink(SR_PLUGIN_DAEMON_PID_FILE); if (-1 != pidfile_fd) { close(pidfile_fd); } exit((SR_ERR_OK == rc) ? EXIT_SUCCESS : EXIT_FAILURE); }