Example #1
0
int main(int argc, char *argv[]) {
        Context context = {};
        _cleanup_event_unref_ sd_event *event = NULL;
        _cleanup_bus_close_unref_ sd_bus *bus = NULL;
        int r;

        log_set_target(LOG_TARGET_AUTO);
        log_parse_environment();
        log_open();

        umask(0022);
        mac_selinux_init("/etc");

        if (argc != 1) {
                log_error("This program takes no arguments.");
                r = -EINVAL;
                goto finish;
        }

        if (argc != 1) {
                log_error("This program takes no arguments.");
                r = -EINVAL;
                goto finish;
        }

        r = sd_event_default(&event);
        if (r < 0) {
                log_error_errno(r, "Failed to allocate event loop: %m");
                goto finish;
        }

        sd_event_set_watchdog(event, true);

        r = connect_bus(&context, event, &bus);
        if (r < 0)
                goto finish;

        r = context_read_data(&context);
        if (r < 0) {
                log_error_errno(r, "Failed to read hostname and machine information: %m");
                goto finish;
        }

        r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1", DEFAULT_EXIT_USEC, NULL, NULL);
        if (r < 0) {
                log_error_errno(r, "Failed to run event loop: %m");
                goto finish;
        }

finish:
        context_free(&context);

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
Example #2
0
/* We attach libsystemd's mainloop to Soletta's on the first time we need to
 * connect to the bus. Any fail on getting connected to the bus means the
 * mainloop terminates.
 */
SOL_API sd_bus *
sol_bus_get(int (*bus_initialized)(sd_bus *bus))
{
    int r;

    if (!_ctx.bus) {
        if (!_ctx.mainloop_source) {
            r = event_attach_mainloop();
            SOL_INT_CHECK_GOTO(r, < 0, fail);
        }

        r = connect_bus();
        SOL_INT_CHECK_GOTO(r, < 0, fail);
        sol_ptr_vector_init(&_ctx.clients);
    }
Example #3
0
static int run(int argc, char *argv[]) {
        _cleanup_(context_clear) Context context = {};
        _cleanup_(sd_event_unrefp) sd_event *event = NULL;
        _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
        int r;

        log_setup_service();

        umask(0022);
        mac_selinux_init();

        if (argc != 1) {
                log_error("This program takes no arguments.");
                return -EINVAL;
        }

        assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0);

        r = sd_event_default(&event);
        if (r < 0)
                return log_error_errno(r, "Failed to allocate event loop: %m");

        (void) sd_event_set_watchdog(event, true);

        r = sd_event_add_signal(event, NULL, SIGINT, NULL, NULL);
        if (r < 0)
                return log_error_errno(r, "Failed to install SIGINT handler: %m");

        r = sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL);
        if (r < 0)
                return log_error_errno(r, "Failed to install SIGTERM handler: %m");

        r = connect_bus(&context, event, &bus);
        if (r < 0)
                return r;

        r = context_read_data(&context);
        if (r < 0)
                return log_error_errno(r, "Failed to read hostname and machine information: %m");

        r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1", DEFAULT_EXIT_USEC, NULL, NULL);
        if (r < 0)
                return log_error_errno(r, "Failed to run event loop: %m");

        return 0;
}
Example #4
0
 * mainloop terminates.
 */
SOL_API sd_bus *
sol_bus_get(void (*bus_initialized)(sd_bus *bus))
{
    int r;

    if (_ctx.bus)
        return _ctx.bus;

    if (!_ctx.mainloop_source) {
        r = event_attach_mainloop();
        SOL_INT_CHECK_GOTO(r, < 0, fail);
    }

    r = connect_bus();
    SOL_INT_CHECK_GOTO(r, < 0, fail);

    sol_ptr_vector_init(&_ctx.clients);

    if (bus_initialized)
        bus_initialized(_ctx.bus);

    return _ctx.bus;

fail:
    SOL_WRN("D-Bus requested but connection could not be made");
    sol_quit();

    return NULL;
}