Example #1
0
static bool busname_supported(void) {
        static int supported = -1;

        if (supported < 0)
                supported = is_kdbus_available();

        return supported;
}
Example #2
0
static int help(void) {

        printf("%s [OPTIONS...]\n\n"
               "Connect STDIO to a given bus address.\n\n"
               "  -h --help               Show this help\n"
               "     --version            Show package version\n"
               "     --machine=MACHINE    Connect to specified machine\n"
               "     --address=ADDRESS    Connect to the bus specified by ADDRESS\n"
               "                          (default: %s)\n",
               program_invocation_short_name,
               is_kdbus_available() ? KERNEL_SYSTEM_BUS_ADDRESS : UNIX_SYSTEM_BUS_ADDRESS);

        return 0;
}
Example #3
0
int main(int argc, char *argv[]) {
        const char *path, *type, *units;
        int r, q;

        if (argc > 1 && argc != 4) {
                log_error("This program takes three or no arguments.");
                return EXIT_FAILURE;
        }

        if (argc > 1) {
                arg_dest = argv[1];
                arg_dest_late = argv[3];
        }

        log_set_target(LOG_TARGET_SAFE);
        log_parse_environment();
        log_open();

        umask(0022);

        if (!is_kdbus_available())
                return 0;

        r = cg_pid_get_owner_uid(0, NULL);
        if (r >= 0) {
                path = "/usr/share/dbus-1/services";
                type = "session";
                units = USER_DATA_UNIT_PATH;
        } else if (r == -ENXIO) {
                path = "/usr/share/dbus-1/system-services";
                type = "system";
                units = SYSTEM_DATA_UNIT_PATH;
        } else
                return log_error_errno(r, "Failed to determine whether we are running as user or system instance: %m");

        r = parse_dbus_fragments(path, type);

        /* FIXME: One day this should just be pulled in statically from basic.target */
        q = link_busnames_target(units);
        if (q < 0)
                r = q;

        q = link_compatibility(units);
        if (q < 0)
                r = q;

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
Example #4
0
static int parse_argv(int argc, char *argv[]) {

        enum {
                ARG_VERSION = 0x100,
                ARG_ADDRESS,
                ARG_MACHINE,
        };

        static const struct option options[] = {
                { "help",            no_argument,       NULL, 'h'                 },
                { "version",         no_argument,       NULL, ARG_VERSION         },
                { "address",         required_argument, NULL, ARG_ADDRESS         },
                { "machine",         required_argument, NULL, ARG_MACHINE         },
                {},
        };

        int c;

        assert(argc >= 0);
        assert(argv);

        while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)

                switch (c) {

                case 'h':
                        help();
                        return 0;

                case ARG_VERSION:
                        puts(PACKAGE_STRING);
                        puts(SYSTEMD_FEATURES);
                        return 0;

                case ARG_ADDRESS: {
                        char *a;

                        a = strdup(optarg);
                        if (!a)
                                return log_oom();

                        free(arg_address);
                        arg_address = a;
                        break;
                }

                case ARG_MACHINE: {
                        _cleanup_free_ char *e = NULL;
                        char *a;

                        e = bus_address_escape(optarg);
                        if (!e)
                                return log_oom();

                        a = strjoin("x-machine-kernel:machine=", e, ";x-machine-unix:machine=", e, NULL);
                        if (!a)
                                return log_oom();

                        free(arg_address);
                        arg_address = a;

                        break;
                }

                case '?':
                        return -EINVAL;

                default:
                        assert_not_reached("Unhandled option");
                }

        /* If the first command line argument is only "x" characters
         * we'll write who we are talking to into it, so that "ps" is
         * explanatory */
        arg_command_line_buffer = argv[optind];
        if (argc > optind + 1 || (arg_command_line_buffer && !in_charset(arg_command_line_buffer, "x"))) {
                log_error("Too many arguments");
                return -EINVAL;
        }

        if (!arg_address) {
                arg_address = strdup(is_kdbus_available() ? KERNEL_SYSTEM_BUS_ADDRESS : UNIX_SYSTEM_BUS_ADDRESS);
                if (!arg_address)
                        return log_oom();
        }

        return 1;
}