示例#1
0
int main(int argc, char *argv[]) {
        sd_bus *bus = NULL;
        int r;

        setlocale(LC_ALL, "");
        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        r = bus_connect_transport(arg_transport, arg_host, false, &bus);
        if (r < 0) {
                log_error_errno(r, "Failed to create bus connection: %m");
                goto finish;
        }

        r = timedatectl_main(bus, argc, argv);

finish:
        sd_bus_flush_close_unref(bus);
        pager_close();

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
示例#2
0
int main(int argc, char*argv[]) {
        sd_bus *bus = NULL;
        int r;

        setlocale(LC_ALL, "");
        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        r = bus_connect_transport(arg_transport, arg_host, false, &bus);
        if (r < 0) {
                log_error_errno(r, "Failed to create bus connection: %m");
                goto finish;
        }

        r = localectl_main(bus, argc, argv);

finish:
        /* make sure we terminate the bus connection first, and then close the
         * pager, see issue #3543 for the details. */
        sd_bus_flush_close_unref(bus);
        pager_close();

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
示例#3
0
static int acquire_bus(sd_bus **bus) {
        int r;

        assert(bus);

        if (*bus)
                return 0;

        r = bus_connect_transport(arg_transport, arg_host, false, bus);
        if (r < 0)
                return log_error_errno(r, "Failed to connect to bus: %m");

        (void) sd_bus_set_allow_interactive_authorization(*bus, arg_ask_password);

        return 0;
}
示例#4
0
static int run(int argc, char *argv[]) {
        _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
        int r;

        setlocale(LC_ALL, "");
        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                return r;

        r = bus_connect_transport(arg_transport, arg_host, false, &bus);
        if (r < 0)
                return log_error_errno(r, "Failed to create bus connection: %m");

        return timedatectl_main(bus, argc, argv);
}
示例#5
0
文件: run.c 项目: pszewczyk/systemd
int main(int argc, char* argv[]) {
    _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
    _cleanup_free_ char *description = NULL, *command = NULL;
    int r, retval = EXIT_SUCCESS;

    log_parse_environment();
    log_open();

    r = parse_argv(argc, argv);
    if (r <= 0)
        goto finish;

    if (argc > optind && arg_transport == BUS_TRANSPORT_LOCAL) {
        /* Patch in an absolute path */

        r = find_binary(argv[optind], &command);
        if (r < 0) {
            log_error_errno(r, "Failed to find executable %s: %m", argv[optind]);
            goto finish;
        }

        argv[optind] = command;
    }

    if (!arg_description) {
        description = strv_join(argv + optind, " ");
        if (!description) {
            r = log_oom();
            goto finish;
        }

        if (arg_unit && isempty(description)) {
            r = free_and_strdup(&description, arg_unit);
            if (r < 0)
                goto finish;
        }

        arg_description = description;
    }

    /* If --wait is used connect via the bus, unconditionally, as ref/unref is not supported via the limited direct
     * connection */
    if (arg_wait)
        r = bus_connect_transport(arg_transport, arg_host, arg_user, &bus);
    else
        r = bus_connect_transport_systemd(arg_transport, arg_host, arg_user, &bus);
    if (r < 0) {
        log_error_errno(r, "Failed to create bus connection: %m");
        goto finish;
    }

    if (arg_scope)
        r = start_transient_scope(bus, argv + optind);
    else if (with_timer())
        r = start_transient_timer(bus, argv + optind);
    else
        r = start_transient_service(bus, argv + optind, &retval);

finish:
    strv_free(arg_environment);
    strv_free(arg_property);
    strv_free(arg_timer_property);

    return r < 0 ? EXIT_FAILURE : retval;
}