Beispiel #1
0
int main(int argc, char *argv[]) {
        _cleanup_free_ char *bus_name = NULL, *address = NULL;
        uint8_t *p;
        sd_bus *a, *b;
        int r, bus_ref;
        sd_bus_message *m;
        sd_memfd *f;
        uint64_t sz;
        uint32_t u32;
        size_t i, l;
        char *s;

        log_set_max_level(LOG_DEBUG);

        bus_ref = bus_kernel_create("deine-mutter", &bus_name);
        if (bus_ref == -ENOENT)
                return EXIT_TEST_SKIP;

        assert_se(bus_ref >= 0);

        address = strappend("kernel:path=", bus_name);
        assert_se(address);

        r = sd_bus_new(&a);
        assert_se(r >= 0);

        r = sd_bus_new(&b);
        assert_se(r >= 0);

        r = sd_bus_set_address(a, address);
        assert_se(r >= 0);

        r = sd_bus_set_address(b, address);
        assert_se(r >= 0);

        r = sd_bus_start(a);
        assert_se(r >= 0);

        r = sd_bus_start(b);
        assert_se(r >= 0);

        r = sd_bus_message_new_method_call(b, ":1.1", "/a/path", "an.inter.face", "AMethod", &m);
        assert_se(r >= 0);

        r = sd_bus_message_open_container(m, 'r', "aysay");
        assert_se(r >= 0);

        r = sd_bus_message_append_array_space(m, 'y', FIRST_ARRAY, (void**) &p);
        assert_se(r >= 0);

        memset(p, 'L', FIRST_ARRAY);

        r = sd_memfd_new_and_map(&f, STRING_SIZE, (void**) &s);
        assert_se(r >= 0);

        for (i = 0; i < STRING_SIZE-1; i++)
                s[i] = '0' + (i % 10);

        s[STRING_SIZE-1] = 0;
        munmap(s, STRING_SIZE);

        r = sd_memfd_get_size(f, &sz);
        assert_se(r >= 0);
        assert_se(sz == STRING_SIZE);

        r = sd_bus_message_append_string_memfd(m, f);
        assert_se(r >= 0);

        sd_memfd_free(f);

        r = sd_memfd_new_and_map(&f, SECOND_ARRAY, (void**) &p);
        assert_se(r >= 0);

        memset(p, 'P', SECOND_ARRAY);
        munmap(p, SECOND_ARRAY);

        r = sd_memfd_get_size(f, &sz);
        assert_se(r >= 0);
        assert_se(sz == SECOND_ARRAY);

        r = sd_bus_message_append_array_memfd(m, 'y', f);
        assert_se(r >= 0);

        sd_memfd_free(f);

        r = sd_bus_message_close_container(m);
        assert_se(r >= 0);

        r = sd_bus_message_append(m, "u", 4711);
        assert_se(r >= 0);

        r = bus_message_seal(m, 55);
        assert_se(r >= 0);

        bus_message_dump(m, stdout, true);

        r = sd_bus_send(b, m, NULL);
        assert_se(r >= 0);

        sd_bus_message_unref(m);

        r = sd_bus_process(a, &m);
        assert_se(r > 0);

        bus_message_dump(m, stdout, true);
        sd_bus_message_rewind(m, true);

        r = sd_bus_message_enter_container(m, 'r', "aysay");
        assert_se(r > 0);

        r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);
        assert_se(r > 0);
        assert_se(l == FIRST_ARRAY);

        for (i = 0; i < l; i++)
                assert_se(p[i] == 'L');

        r = sd_bus_message_read(m, "s", &s);
        assert_se(r > 0);

        for (i = 0; i < STRING_SIZE-1; i++)
                assert_se(s[i] == (char) ('0' + (i % 10)));
        assert_se(s[STRING_SIZE-1] == 0);

        r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);
        assert_se(r > 0);
        assert_se(l == SECOND_ARRAY);

        for (i = 0; i < l; i++)
                assert_se(p[i] == 'P');

        r = sd_bus_message_exit_container(m);
        assert_se(r > 0);

        r = sd_bus_message_read(m, "u", &u32);
        assert_se(r > 0);
        assert_se(u32 == 4711);

        sd_bus_message_unref(m);

        sd_bus_unref(a);
        sd_bus_unref(b);

        return 0;
}
Beispiel #2
0
static int set_options(struct udev *udev,
                       int argc, char **argv,
                       char *maj_min_dev)
{
        int option;

        /*
         * optind is a global extern used by getopt. Since we can call
         * set_options twice (once for command line, and once for config
         * file) we have to reset this back to 1.
         */
        optind = 1;
        while ((option = getopt_long(argc, argv, "d:f:gp:uvVxhbs:", options, NULL)) >= 0)
                switch (option) {
                case 'b':
                        all_good = false;
                        break;

                case 'd':
                        dev_specified = true;
                        strscpy(maj_min_dev, MAX_PATH_LEN, optarg);
                        break;

                case 'f':
                        strscpy(config_file, MAX_PATH_LEN, optarg);
                        break;

                case 'g':
                        all_good = true;
                        break;

                case 'h':
                        help();
                        exit(EXIT_SUCCESS);

                case 'p':
                        if (streq(optarg, "0x80"))
                                default_page_code = PAGE_80;
                        else if (streq(optarg, "0x83"))
                                default_page_code = PAGE_83;
                        else if (streq(optarg, "pre-spc3-83"))
                                default_page_code = PAGE_83_PRE_SPC3;
                        else {
                                log_error("Unknown page code '%s'", optarg);
                                return -1;
                        }
                        break;

                case 's':
                        sg_version = atoi(optarg);
                        if (sg_version < 3 || sg_version > 4) {
                                log_error("Unknown SG version '%s'", optarg);
                                return -1;
                        }
                        break;

                case 'u':
                        reformat_serial = true;
                        break;

                case 'v':
                        log_set_target(LOG_TARGET_CONSOLE);
                        log_set_max_level(LOG_DEBUG);
                        log_open();
                        break;

                case 'V':
                        printf("%s\n", PACKAGE_VERSION);
                        exit(EXIT_SUCCESS);

                case 'x':
                        export = true;
                        break;

                case '?':
                        return -1;

                default:
                        assert_not_reached("Unknown option");
                }

        if (optind < argc && !dev_specified) {
                dev_specified = true;
                strscpy(maj_min_dev, MAX_PATH_LEN, argv[optind]);
        }

        return 0;
}
Beispiel #3
0
int main(int argc, char *argv[]) {
        sd_memfd *m;
        char *s, *name;
        uint64_t sz;
        int r, fd;
        FILE *f;
        char buf[3] = {};
        struct iovec iov[3] = {};
        char bufv[3][3] = {};

        log_set_max_level(LOG_DEBUG);

        r = sd_memfd_new(NULL, &m);
        if (r == -ENOENT)
                return EXIT_TEST_SKIP;

        assert_se(r >= 0);

        assert_se(sd_memfd_get_name(m, &name) >= 0);
        log_info("name: %s", name);
        free(name);

        r = sd_memfd_map(m, 0, 12, (void**) &s);
        assert_se(r >= 0);

        strcpy(s, "----- world");

        r = sd_memfd_set_sealed(m, 1);
        assert_se(r == -ETXTBSY);

        assert_se(write(sd_memfd_get_fd(m), "he", 2) == 2);
        assert_se(write(sd_memfd_get_fd(m), "XXX", 3) == 3);
        assert_se(streq(s, "heXXX world"));

        /* fix "hello" */
        assert_se(lseek(sd_memfd_get_fd(m), 2, SEEK_SET) == 2);
        assert_se(write(sd_memfd_get_fd(m), "ll", 2) == 2);

        assert_se(sd_memfd_get_file(m, &f) >= 0);
        fputc('o', f);
        fflush(f);

        /* check content  */
        assert_se(streq(s, "hello world"));

        assert_se(munmap(s, 12) == 0);

        r = sd_memfd_get_sealed(m);
        assert_se(r == 0);

        r = sd_memfd_get_size(m, &sz);
        assert_se(r >= 0);
        assert_se(sz = page_size());

        /* truncate it */
        r = sd_memfd_set_size(m, 6);
        assert_se(r >= 0);

        /* get back new value */
        r = sd_memfd_get_size(m, &sz);
        assert_se(r >= 0);
        assert_se(sz == 6);

        r = sd_memfd_set_sealed(m, 1);
        assert_se(r >= 0);

        r = sd_memfd_get_sealed(m);
        assert_se(r == 1);

        fd = sd_memfd_dup_fd(m);
        assert_se(fd >= 0);

        sd_memfd_free(m);

        /* new sd_memfd, same underlying memfd */
        r = sd_memfd_make(fd, &m);
        assert_se(r >= 0);

        /* we did truncate it to 6 */
        r = sd_memfd_get_size(m, &sz);
        assert_se(r >= 0 && sz == 6);

        /* map it, check content */
        r = sd_memfd_map(m, 0, 12, (void **)&s);
        assert_se(r >= 0);

        /* we only see the truncated size */
        assert_se(streq(s, "hello "));

        /* it was already sealed */
        r = sd_memfd_set_sealed(m, 1);
        assert_se(r == -EALREADY);

        /* we cannot break the seal, it is mapped */
        r = sd_memfd_set_sealed(m, 0);
        assert_se(r == -ETXTBSY);

        /* unmap it; become the single owner */
        assert_se(munmap(s, 12) == 0);

        /* now we can do flip the sealing */
        r = sd_memfd_set_sealed(m, 0);
        assert_se(r == 0);
        r = sd_memfd_get_sealed(m);
        assert_se(r == 0);

        r = sd_memfd_set_sealed(m, 1);
        assert_se(r == 0);
        r = sd_memfd_get_sealed(m);
        assert_se(r == 1);

        r = sd_memfd_set_sealed(m, 0);
        assert_se(r == 0);
        r = sd_memfd_get_sealed(m);
        assert_se(r == 0);

        /* seek at 2, read() 2 bytes */
        assert_se(lseek(fd, 2, SEEK_SET) == 2);
        assert_se(read(fd, buf, 2) == 2);

        /* check content */
        assert_se(memcmp(buf, "ll", 2) == 0);

        /* writev it out*/
        iov[0].iov_base = (char *)"ABC";
        iov[0].iov_len = 3;
        iov[1].iov_base = (char *)"DEF";
        iov[1].iov_len = 3;
        iov[2].iov_base = (char *)"GHI";
        iov[2].iov_len = 3;
        assert_se(pwritev(fd, iov, 3, 0) == 9);

        /* readv it back */
        iov[0].iov_base = bufv[0];
        iov[0].iov_len = 3;
        iov[1].iov_base = bufv[1];
        iov[1].iov_len = 3;
        iov[2].iov_base = bufv[2];
        iov[2].iov_len = 3;
        assert_se(preadv(fd, iov, 3, 0) == 9);

        /* check content */
        assert_se(memcmp(bufv[0], "ABC", 3) == 0);
        assert_se(memcmp(bufv[1], "DEF", 3) == 0);
        assert_se(memcmp(bufv[2], "GHI", 3) == 0);

        sd_memfd_free(m);

        return 0;
}
Beispiel #4
0
int main(int argc, char *argv[])
{
        struct udev *udev;
        static const struct option options[] = {
                { "debug", no_argument, NULL, 'd' },
                { "help", no_argument, NULL, 'h' },
                { "version", no_argument, NULL, 'V' },
                {}
        };
        const char *command;
        unsigned int i;
        int rc = 1;

        udev = udev_new();
        if (udev == NULL)
                goto out;

        log_open();
        udev_set_log_fn(udev, udev_main_log);
        label_init("/dev");

        for (;;) {
                int option;

                option = getopt_long(argc, argv, "+dhV", options, NULL);
                if (option == -1)
                        break;

                switch (option) {
                case 'd':
                        log_set_max_level(LOG_DEBUG);
                        udev_set_log_priority(udev, LOG_DEBUG);
                        break;
                case 'h':
                        rc = adm_help(udev, argc, argv);
                        goto out;
                case 'V':
                        rc = adm_version(udev, argc, argv);
                        goto out;
                default:
                        goto out;
                }
        }
        command = argv[optind];

        if (command != NULL)
                for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++) {
                        if (strcmp(udevadm_cmds[i]->name, command) == 0) {
                                argc -= optind;
                                argv += optind;
                                /* we need '0' here to reset the internal state */
                                optind = 0;
                                rc = run_command(udev, udevadm_cmds[i], argc, argv);
                                goto out;
                        }
                }

        fprintf(stderr, "missing or unknown command\n\n");
        adm_help(udev, argc, argv);
        rc = 2;
out:
        label_finish();
        udev_unref(udev);
        log_close();
        return rc;
}
int main(int argc, char *argv[]) {
        enum {
                MODE_BISECT,
                MODE_CHART,
        } mode = MODE_BISECT;
        int i;
        _cleanup_free_ char *bus_name = NULL, *address = NULL;
        _cleanup_close_ int bus_ref = -1;
        cpu_set_t cpuset;
        size_t result;
        sd_bus *b;
        pid_t pid;
        int r;

        log_set_max_level(LOG_DEBUG);

        for (i = 1; i < argc; i++) {
                if (streq(argv[i], "chart")) {
                        mode = MODE_CHART;
                        continue;
                }

                assert_se(parse_sec(argv[i], &arg_loop_usec) >= 0);
        }

        assert_se(arg_loop_usec > 0);

        bus_ref = bus_kernel_create("deine-mutter", &bus_name);
        if (bus_ref == -ENOENT)
                exit(EXIT_TEST_SKIP);

        assert_se(bus_ref >= 0);

        address = strappend("kernel:path=", bus_name);
        assert_se(address);

        r = sd_bus_new(&b);
        assert_se(r >= 0);

        r = sd_bus_set_address(b, address);
        assert_se(r >= 0);

        r = sd_bus_start(b);
        assert_se(r >= 0);

        sync();
        setpriority(PRIO_PROCESS, 0, -19);

        pid = fork();
        assert_se(pid >= 0);

        if (pid == 0) {
                CPU_ZERO(&cpuset);
                CPU_SET(0, &cpuset);
                pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);

                close_nointr_nofail(bus_ref);
                sd_bus_unref(b);

                switch (mode) {
                case MODE_BISECT:
                        client_bisect(address);
                        break;

                case MODE_CHART:
                        client_chart(address);
                        break;
                }

                _exit(0);
        }

        CPU_ZERO(&cpuset);
        CPU_SET(1, &cpuset);
        pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);

        server(b, &result);

        if (mode == MODE_BISECT)
                printf("Copying/memfd are equally fast at %zu bytes\n", result);

        assert_se(waitpid(pid, NULL, 0) == pid);

        sd_bus_unref(b);

        return 0;
}
int main(int argc, char *argv[]) {
        char t[] = "/tmp/journal-XXXXXX";
        unsigned n;
        JournalFile *f;
        const char *verification_key = argv[1];
        usec_t from = 0, to = 0, total = 0;
        char a[FORMAT_TIMESTAMP_MAX];
        char b[FORMAT_TIMESTAMP_MAX];
        char c[FORMAT_TIMESPAN_MAX];
        struct stat st;
        uint64_t p;

        /* journal_file_open requires a valid machine id */
        if (access("/etc/machine-id", F_OK) != 0)
                return EXIT_TEST_SKIP;

        log_set_max_level(LOG_DEBUG);

        assert_se(mkdtemp(t));
        assert_se(chdir(t) >= 0);

        log_info("Generating...");

        assert_se(journal_file_open("test.journal", O_RDWR|O_CREAT, 0666, true, !!verification_key, NULL, NULL, NULL, &f) == 0);

        for (n = 0; n < N_ENTRIES; n++) {
                struct iovec iovec;
                struct dual_timestamp ts;
                char *test;

                dual_timestamp_get(&ts);

                assert_se(asprintf(&test, "RANDOM=%lu", random() % RANDOM_RANGE));

                iovec.iov_base = (void*) test;
                iovec.iov_len = strlen(test);

                assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);

                free(test);
        }

        journal_file_close(f);

        log_info("Verifying...");

        assert_se(journal_file_open("test.journal", O_RDONLY, 0666, true, !!verification_key, NULL, NULL, NULL, &f) == 0);
        /* journal_file_print_header(f); */
        journal_file_dump(f);

        assert_se(journal_file_verify(f, verification_key, &from, &to, &total, true) >= 0);

        if (verification_key && JOURNAL_HEADER_SEALED(f->header)) {
                log_info("=> Validated from %s to %s, %s missing",
                         format_timestamp(a, sizeof(a), from),
                         format_timestamp(b, sizeof(b), to),
                         format_timespan(c, sizeof(c), total > to ? total - to : 0, 0));
        }

        journal_file_close(f);

        if (verification_key) {
                log_info("Toggling bits...");

                assert_se(stat("test.journal", &st) >= 0);

                for (p = 38448*8+0; p < ((uint64_t) st.st_size * 8); p ++) {
                        bit_toggle("test.journal", p);

                        log_info("[ %"PRIu64"+%"PRIu64"]", p / 8, p % 8);

                        if (raw_verify("test.journal", verification_key) >= 0)
                                log_notice(ANSI_HIGHLIGHT_RED_ON ">>>> %"PRIu64" (bit %"PRIu64") can be toggled without detection." ANSI_HIGHLIGHT_OFF, p / 8, p % 8);

                        bit_toggle("test.journal", p);
                }
        }

        log_info("Exiting...");

        assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);

        return 0;
}
Beispiel #7
0
/**
 * udev_new:
 *
 * Create udev library context. This reads the udev configuration
 * file, and fills in the default values.
 *
 * The initial refcount is 1, and needs to be decremented to
 * release the resources of the udev library context.
 *
 * Returns: a new udev library context
 **/
_public_ struct udev *udev_new(void) {
        struct udev *udev;
        _cleanup_fclose_ FILE *f = NULL;

        udev = new0(struct udev, 1);
        if (udev == NULL)
                return NULL;
        udev->refcount = 1;

        f = fopen("/etc/udev/udev.conf", "re");
        if (f != NULL) {
                char line[UTIL_LINE_SIZE];
                unsigned line_nr = 0;

                while (fgets(line, sizeof(line), f)) {
                        size_t len;
                        char *key;
                        char *val;

                        line_nr++;

                        /* find key */
                        key = line;
                        while (isspace(key[0]))
                                key++;

                        /* comment or empty line */
                        if (key[0] == '#' || key[0] == '\0')
                                continue;

                        /* split key/value */
                        val = strchr(key, '=');
                        if (val == NULL) {
                                log_debug("/etc/udev/udev.conf:%u: missing assignment,  skipping line.", line_nr);
                                continue;
                        }
                        val[0] = '\0';
                        val++;

                        /* find value */
                        while (isspace(val[0]))
                                val++;

                        /* terminate key */
                        len = strlen(key);
                        if (len == 0)
                                continue;
                        while (isspace(key[len-1]))
                                len--;
                        key[len] = '\0';

                        /* terminate value */
                        len = strlen(val);
                        if (len == 0)
                                continue;
                        while (isspace(val[len-1]))
                                len--;
                        val[len] = '\0';

                        if (len == 0)
                                continue;

                        /* unquote */
                        if (val[0] == '"' || val[0] == '\'') {
                                if (len == 1 || val[len-1] != val[0]) {
                                        log_debug("/etc/udev/udev.conf:%u: inconsistent quoting, skipping line.", line_nr);
                                        continue;
                                }
                                val[len-1] = '\0';
                                val++;
                        }

                        if (streq(key, "udev_log")) {
                                int prio;

                                prio = util_log_priority(val);
                                if (prio < 0)
                                        log_debug("/etc/udev/udev.conf:%u: invalid log level '%s', ignoring.", line_nr, val);
                                else
                                        log_set_max_level(prio);
                                continue;
                        }
                }
        }

        return udev;
}
Beispiel #8
0
int main(int argc, char *argv[])
{
        struct udev *udev;
        static const struct option options[] = {
                { "lock-media", no_argument, NULL, 'l' },
                { "unlock-media", no_argument, NULL, 'u' },
                { "eject-media", no_argument, NULL, 'e' },
                { "debug", no_argument, NULL, 'd' },
                { "help", no_argument, NULL, 'h' },
                {}
        };
        bool eject = false;
        bool lock = false;
        bool unlock = false;
        const char *node = NULL;
        int fd = -1;
        int cnt;
        int rc = 0;

        udev = udev_new();
        if (udev == NULL)
                goto exit;

        log_open();
        udev_set_log_fn(udev, log_fn);

        while (1) {
                int option;

                option = getopt_long(argc, argv, "deluh", options, NULL);
                if (option == -1)
                        break;

                switch (option) {
                case 'l':
                        lock = true;
                        break;
                case 'u':
                        unlock = true;
                        break;
                case 'e':
                        eject = true;
                        break;
                case 'd':
                        debug = true;
                        log_set_max_level(LOG_DEBUG);
                        udev_set_log_priority(udev, LOG_DEBUG);
                        break;
                case 'h':
                        printf("Usage: cdrom_id [options] <device>\n"
                               "  --lock-media    lock the media (to enable eject request events)\n"
                               "  --unlock-media  unlock the media\n"
                               "  --eject-media   eject the media\n"
                               "  --debug         debug to stderr\n"
                               "  --help          print this help text\n\n");
                        goto exit;
                default:
                        rc = 1;
                        goto exit;
                }
        }

        node = argv[optind];
        if (!node) {
                log_error("no device");
                fprintf(stderr, "no device\n");
                rc = 1;
                goto exit;
        }

        srand((unsigned int)getpid());
        for (cnt = 20; cnt > 0; cnt--) {
                struct timespec duration;

                fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC|(is_mounted(node) ? 0 : O_EXCL));
                if (fd >= 0 || errno != EBUSY)
                        break;
                duration.tv_sec = 0;
                duration.tv_nsec = (100 * 1000 * 1000) + (rand() % 100 * 1000 * 1000);
                nanosleep(&duration, NULL);
        }
        if (fd < 0) {
                log_debug("unable to open '%s'", node);
                fprintf(stderr, "unable to open '%s'\n", node);
                rc = 1;
                goto exit;
        }
        log_debug("probing: '%s'", node);

        /* same data as original cdrom_id */
        if (cd_capability_compat(udev, fd) < 0) {
                rc = 1;
                goto exit;
        }

        /* check for media - don't bail if there's no media as we still need to
         * to read profiles */
        cd_media_compat(udev, fd);

        /* check if drive talks MMC */
        if (cd_inquiry(udev, fd) < 0)
                goto work;

        /* read drive and possibly current profile */
        if (cd_profiles(udev, fd) != 0)
                goto work;

        /* at this point we are guaranteed to have media in the drive - find out more about it */

        /* get session/track info */
        cd_media_toc(udev, fd);

        /* get writable media state */
        cd_media_info(udev, fd);

work:
        /* lock the media, so we enable eject button events */
        if (lock && cd_media) {
                log_debug("PREVENT_ALLOW_MEDIUM_REMOVAL (lock)");
                media_lock(udev, fd, true);
        }

        if (unlock && cd_media) {
                log_debug("PREVENT_ALLOW_MEDIUM_REMOVAL (unlock)");
                media_lock(udev, fd, false);
        }

        if (eject) {
                log_debug("PREVENT_ALLOW_MEDIUM_REMOVAL (unlock)");
                media_lock(udev, fd, false);
                log_debug("START_STOP_UNIT (eject)");
                media_eject(udev, fd);
        }

        printf("ID_CDROM=1\n");
        if (cd_cd_rom)
                printf("ID_CDROM_CD=1\n");
        if (cd_cd_r)
                printf("ID_CDROM_CD_R=1\n");
        if (cd_cd_rw)
                printf("ID_CDROM_CD_RW=1\n");
        if (cd_dvd_rom)
                printf("ID_CDROM_DVD=1\n");
        if (cd_dvd_r)
                printf("ID_CDROM_DVD_R=1\n");
        if (cd_dvd_rw)
                printf("ID_CDROM_DVD_RW=1\n");
        if (cd_dvd_ram)
                printf("ID_CDROM_DVD_RAM=1\n");
        if (cd_dvd_plus_r)
                printf("ID_CDROM_DVD_PLUS_R=1\n");
        if (cd_dvd_plus_rw)
                printf("ID_CDROM_DVD_PLUS_RW=1\n");
        if (cd_dvd_plus_r_dl)
                printf("ID_CDROM_DVD_PLUS_R_DL=1\n");
        if (cd_dvd_plus_rw_dl)
                printf("ID_CDROM_DVD_PLUS_RW_DL=1\n");
        if (cd_bd)
                printf("ID_CDROM_BD=1\n");
        if (cd_bd_r)
                printf("ID_CDROM_BD_R=1\n");
        if (cd_bd_re)
                printf("ID_CDROM_BD_RE=1\n");
        if (cd_hddvd)
                printf("ID_CDROM_HDDVD=1\n");
        if (cd_hddvd_r)
                printf("ID_CDROM_HDDVD_R=1\n");
        if (cd_hddvd_rw)
                printf("ID_CDROM_HDDVD_RW=1\n");
        if (cd_mo)
                printf("ID_CDROM_MO=1\n");
        if (cd_mrw)
                printf("ID_CDROM_MRW=1\n");
        if (cd_mrw_w)
                printf("ID_CDROM_MRW_W=1\n");

        if (cd_media)
                printf("ID_CDROM_MEDIA=1\n");
        if (cd_media_mo)
                printf("ID_CDROM_MEDIA_MO=1\n");
        if (cd_media_mrw)
                printf("ID_CDROM_MEDIA_MRW=1\n");
        if (cd_media_mrw_w)
                printf("ID_CDROM_MEDIA_MRW_W=1\n");
        if (cd_media_cd_rom)
                printf("ID_CDROM_MEDIA_CD=1\n");
        if (cd_media_cd_r)
                printf("ID_CDROM_MEDIA_CD_R=1\n");
        if (cd_media_cd_rw)
                printf("ID_CDROM_MEDIA_CD_RW=1\n");
        if (cd_media_dvd_rom)
                printf("ID_CDROM_MEDIA_DVD=1\n");
        if (cd_media_dvd_r)
                printf("ID_CDROM_MEDIA_DVD_R=1\n");
        if (cd_media_dvd_ram)
                printf("ID_CDROM_MEDIA_DVD_RAM=1\n");
        if (cd_media_dvd_rw)
                printf("ID_CDROM_MEDIA_DVD_RW=1\n");
        if (cd_media_dvd_plus_r)
                printf("ID_CDROM_MEDIA_DVD_PLUS_R=1\n");
        if (cd_media_dvd_plus_rw)
                printf("ID_CDROM_MEDIA_DVD_PLUS_RW=1\n");
        if (cd_media_dvd_plus_rw_dl)
                printf("ID_CDROM_MEDIA_DVD_PLUS_RW_DL=1\n");
        if (cd_media_dvd_plus_r_dl)
                printf("ID_CDROM_MEDIA_DVD_PLUS_R_DL=1\n");
        if (cd_media_bd)
                printf("ID_CDROM_MEDIA_BD=1\n");
        if (cd_media_bd_r)
                printf("ID_CDROM_MEDIA_BD_R=1\n");
        if (cd_media_bd_re)
                printf("ID_CDROM_MEDIA_BD_RE=1\n");
        if (cd_media_hddvd)
                printf("ID_CDROM_MEDIA_HDDVD=1\n");
        if (cd_media_hddvd_r)
                printf("ID_CDROM_MEDIA_HDDVD_R=1\n");
        if (cd_media_hddvd_rw)
                printf("ID_CDROM_MEDIA_HDDVD_RW=1\n");

        if (cd_media_state != NULL)
                printf("ID_CDROM_MEDIA_STATE=%s\n", cd_media_state);
        if (cd_media_session_next > 0)
                printf("ID_CDROM_MEDIA_SESSION_NEXT=%d\n", cd_media_session_next);
        if (cd_media_session_count > 0)
                printf("ID_CDROM_MEDIA_SESSION_COUNT=%d\n", cd_media_session_count);
        if (cd_media_session_count > 1 && cd_media_session_last_offset > 0)
                printf("ID_CDROM_MEDIA_SESSION_LAST_OFFSET=%llu\n", cd_media_session_last_offset);
        if (cd_media_track_count > 0)
                printf("ID_CDROM_MEDIA_TRACK_COUNT=%d\n", cd_media_track_count);
        if (cd_media_track_count_audio > 0)
                printf("ID_CDROM_MEDIA_TRACK_COUNT_AUDIO=%d\n", cd_media_track_count_audio);
        if (cd_media_track_count_data > 0)
                printf("ID_CDROM_MEDIA_TRACK_COUNT_DATA=%d\n", cd_media_track_count_data);
exit:
        if (fd >= 0)
                close(fd);
        udev_unref(udev);
        log_close();
        return rc;
}
int main(int argc, char *argv[]) {
        _cleanup_close_ int bus_ref = -1;
        _cleanup_free_ char *name = NULL, *bus_name = NULL, *address = NULL;
        _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
        const char *ua = NULL, *ub = NULL, *the_string = NULL;
        sd_bus *a, *b;
        int r, pipe_fds[2];
        const char *nn;

        log_set_max_level(LOG_DEBUG);

        assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid()) >= 0);

        bus_ref = bus_kernel_create_bus(name, false, &bus_name);
        if (bus_ref == -ENOENT)
                return EXIT_TEST_SKIP;

        assert_se(bus_ref >= 0);

        address = strappend("kernel:path=", bus_name);
        assert_se(address);

        r = sd_bus_new(&a);
        assert_se(r >= 0);

        r = sd_bus_new(&b);
        assert_se(r >= 0);

        r = sd_bus_set_name(a, "a");
        assert_se(r >= 0);

        r = sd_bus_set_address(a, address);
        assert_se(r >= 0);

        r = sd_bus_set_address(b, address);
        assert_se(r >= 0);

        assert_se(sd_bus_negotiate_timestamp(a, 1) >= 0);
        assert_se(sd_bus_negotiate_creds(a, _SD_BUS_CREDS_ALL) >= 0);

        assert_se(sd_bus_negotiate_timestamp(b, 1) >= 0);
        assert_se(sd_bus_negotiate_creds(b, _SD_BUS_CREDS_ALL) >= 0);

        r = sd_bus_start(a);
        assert_se(r >= 0);

        r = sd_bus_start(b);
        assert_se(r >= 0);

        r = sd_bus_get_unique_name(a, &ua);
        assert_se(r >= 0);
        printf("unique a: %s\n", ua);

        r = sd_bus_get_name(a, &nn);
        assert_se(r >= 0);
        printf("name of a: %s\n", nn);

        r = sd_bus_get_unique_name(b, &ub);
        assert_se(r >= 0);
        printf("unique b: %s\n", ub);

        r = sd_bus_get_name(b, &nn);
        assert_se(r >= 0);
        printf("name of b: %s\n", nn);

        r = sd_bus_call_method(a, "this.doesnt.exist", "/foo", "meh.mah", "muh", &error, NULL, "s", "yayayay");
        assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_SERVICE_UNKNOWN));
        assert_se(r == -EHOSTUNREACH);

        r = sd_bus_add_match(b, "interface='waldo.com',member='Piep'", NULL, NULL);
        assert_se(r >= 0);

        r = sd_bus_emit_signal(a, "/foo/bar/waldo", "waldo.com", "Piep", "sss", "I am a string", "/this/is/a/path", "and.this.a.domain.name");
        assert_se(r >= 0);

        r = sd_bus_try_close(b);
        assert_se(r == -EBUSY);

        r = sd_bus_process_priority(b, -10, &m);
        assert_se(r == -ENOMSG);

        r = sd_bus_process(b, &m);
        assert_se(r > 0);
        assert_se(m);

        bus_message_dump(m, stdout, true);
        assert_se(sd_bus_message_rewind(m, true) >= 0);

        r = sd_bus_message_read(m, "s", &the_string);
        assert_se(r >= 0);
        assert_se(streq(the_string, "I am a string"));

        sd_bus_message_unref(m);
        m = NULL;

        r = sd_bus_request_name(a, "net.x0pointer.foobar", 0);
        assert_se(r >= 0);

        r = sd_bus_message_new_method_call(b, &m, "net.x0pointer.foobar", "/a/path", "an.inter.face", "AMethod");
        assert_se(r >= 0);

        assert_se(pipe2(pipe_fds, O_CLOEXEC) >= 0);

        assert_se(write(pipe_fds[1], "x", 1) == 1);

        close_nointr_nofail(pipe_fds[1]);
        pipe_fds[1] = -1;

        r = sd_bus_message_append(m, "h", pipe_fds[0]);
        assert_se(r >= 0);

        close_nointr_nofail(pipe_fds[0]);
        pipe_fds[0] = -1;

        r = sd_bus_send(b, m, NULL);
        assert_se(r >= 0);

        for (;;) {
                sd_bus_message_unref(m);
                m = NULL;
                r = sd_bus_process(a, &m);
                assert_se(r > 0);
                assert_se(m);

                bus_message_dump(m, stdout, true);
                assert_se(sd_bus_message_rewind(m, true) >= 0);

                if (sd_bus_message_is_method_call(m, "an.inter.face", "AMethod")) {
                        int fd;
                        char x;

                        r = sd_bus_message_read(m, "h", &fd);
                        assert_se(r >= 0);

                        assert_se(read(fd, &x, 1) == 1);
                        assert_se(x == 'x');
                        break;
                }
        }

        r = sd_bus_release_name(a, "net.x0pointer.foobar");
        assert_se(r >= 0);

        r = sd_bus_release_name(a, "net.x0pointer.foobar");
        assert_se(r == -ESRCH);

        r = sd_bus_try_close(a);
        assert_se(r >= 0);

        sd_bus_unref(a);
        sd_bus_unref(b);

        return 0;
}
Beispiel #10
0
/**
 * udev_set_log_priority:
 * @udev: udev library context
 * @priority: the new log priority
 *
 * This function is deprecated.
 *
 **/
_public_ void udev_set_log_priority(struct udev *udev, int priority) {
        log_set_max_level(priority);
}
int main(int argc, char *argv[]) {
    JournalFile *one, *two, *three;
    char t[] = "/tmp/journal-stream-XXXXXX";
    unsigned i;
    _cleanup_journal_close_ sd_journal *j = NULL;
    char *z;
    const void *data;
    size_t l;

    /* journal_file_open requires a valid machine id */
    if (access("/etc/machine-id", F_OK) != 0)
        return EXIT_TEST_SKIP;

    log_set_max_level(LOG_DEBUG);

    assert_se(mkdtemp(t));
    assert_se(chdir(t) >= 0);

    assert_se(journal_file_open("one.journal", O_RDWR|O_CREAT, 0666, true, false, NULL, NULL, NULL, &one) == 0);
    assert_se(journal_file_open("two.journal", O_RDWR|O_CREAT, 0666, true, false, NULL, NULL, NULL, &two) == 0);
    assert_se(journal_file_open("three.journal", O_RDWR|O_CREAT, 0666, true, false, NULL, NULL, NULL, &three) == 0);

    for (i = 0; i < N_ENTRIES; i++) {
        char *p, *q;
        dual_timestamp ts;
        struct iovec iovec[2];

        dual_timestamp_get(&ts);

        assert_se(asprintf(&p, "NUMBER=%u", i) >= 0);
        iovec[0].iov_base = p;
        iovec[0].iov_len = strlen(p);

        assert_se(asprintf(&q, "MAGIC=%s", i % 5 == 0 ? "quux" : "waldo") >= 0);

        iovec[1].iov_base = q;
        iovec[1].iov_len = strlen(q);

        if (i % 10 == 0)
            assert_se(journal_file_append_entry(three, &ts, iovec, 2, NULL, NULL, NULL) == 0);
        else {
            if (i % 3 == 0)
                assert_se(journal_file_append_entry(two, &ts, iovec, 2, NULL, NULL, NULL) == 0);

            assert_se(journal_file_append_entry(one, &ts, iovec, 2, NULL, NULL, NULL) == 0);
        }

        free(p);
        free(q);
    }

    journal_file_close(one);
    journal_file_close(two);
    journal_file_close(three);

    assert_se(sd_journal_open_directory(&j, t, 0) >= 0);

    assert_se(sd_journal_add_match(j, "MAGIC=quux", 0) >= 0);
    SD_JOURNAL_FOREACH_BACKWARDS(j) {
        _cleanup_free_ char *c;

        assert_se(sd_journal_get_data(j, "NUMBER", &data, &l) >= 0);
        printf("\t%.*s\n", (int) l, (const char*) data);

        assert_se(sd_journal_get_cursor(j, &c) >= 0);
        assert_se(sd_journal_test_cursor(j, c) > 0);
    }

    SD_JOURNAL_FOREACH(j) {
        _cleanup_free_ char *c;

        assert_se(sd_journal_get_data(j, "NUMBER", &data, &l) >= 0);
        printf("\t%.*s\n", (int) l, (const char*) data);

        assert_se(sd_journal_get_cursor(j, &c) >= 0);
        assert_se(sd_journal_test_cursor(j, c) > 0);
    }

    sd_journal_flush_matches(j);

    verify_contents(j, 1);

    printf("NEXT TEST\n");
    assert_se(sd_journal_add_match(j, "MAGIC=quux", 0) >= 0);

    assert_se(z = journal_make_match_string(j));
    printf("resulting match expression is: %s\n", z);
    free(z);

    verify_contents(j, 5);

    printf("NEXT TEST\n");
    sd_journal_flush_matches(j);
    assert_se(sd_journal_add_match(j, "MAGIC=waldo", 0) >= 0);
    assert_se(sd_journal_add_match(j, "NUMBER=10", 0) >= 0);
    assert_se(sd_journal_add_match(j, "NUMBER=11", 0) >= 0);
    assert_se(sd_journal_add_match(j, "NUMBER=12", 0) >= 0);

    assert_se(z = journal_make_match_string(j));
    printf("resulting match expression is: %s\n", z);
    free(z);

    verify_contents(j, 0);

    assert_se(sd_journal_query_unique(j, "NUMBER") >= 0);
    SD_JOURNAL_FOREACH_UNIQUE(j, data, l)
    printf("%.*s\n", (int) l, (const char*) data);

    assert_se(rm_rf_dangerous(t, false, true, false) >= 0);

    return 0;
}
Beispiel #12
0
int main(int argc, char *argv[])
{
	basic_init();

	client::Config &config = g_client_config;

	const char opts[100] = "hs:P:C:U:l:m:";
	const char usagefmt[1000] =
			"Usage: %s [OPTION]...\n"
			"  -h                   Show this help\n"
			"  -s [address]         Specify server address\n"
			"  -P [share_path]      Specify share/ path\n"
			"  -C [cache_path]      Specify cache/ path\n"
			"  -U [urho3d_path]     Specify Urho3D path\n"
			"  -l [integer]         Set maximum log level (0...5)\n"
			"  -m [name]            Choose menu extension name\n"
	;

	int c;
	while((c = c55_getopt(argc, argv, opts)) != -1)
	{
		switch(c)
		{
		case 'h':
			printf(usagefmt, argv[0]);
			return 1;
		case 's':
			fprintf(stderr, "INFO: config.server_address: %s\n", c55_optarg);
			config.server_address = c55_optarg;
			break;
		case 'P':
			fprintf(stderr, "INFO: config.share_path: %s\n", c55_optarg);
			config.share_path = c55_optarg;
			break;
		case 'C':
			fprintf(stderr, "INFO: config.cache_path: %s\n", c55_optarg);
			config.cache_path = c55_optarg;
			break;
		case 'U':
			fprintf(stderr, "INFO: config.urho3d_path: %s\n", c55_optarg);
			config.urho3d_path = c55_optarg;
			break;
		case 'l':
			log_set_max_level(atoi(c55_optarg));
			break;
		case 'm':
			fprintf(stderr, "INFO: config.menu_extension_name: %s\n", c55_optarg);
			config.menu_extension_name = c55_optarg;
			break;
		default:
			fprintf(stderr, "ERROR: Invalid command-line argument\n");
			fprintf(stderr, usagefmt, argv[0]);
			return 1;
		}
	}

	config.make_paths_absolute();
	if(!config.check_paths()){
		return 1;
	}

	app::Options app_options;

	int exit_status = 0;
	while(exit_status == 0){
		magic::Context context;
		sp_<app::App> app0(app::createApp(&context, app_options));
		sp_<client::State> state(client::createState(app0));
		app0->set_state(state);

		if(config.server_address != ""){
			if(!state->connect(config.server_address, "20000"))
				return 1;
		} else {
			config.boot_to_menu = true;
		}

		exit_status = app0->run();

		if(!app0->reboot_requested())
			break;

		app_options = app0->get_current_options();

		// Re-creating app:App requires guard to be disabled
		buildat_guard_enable(false);
	}
	log_v(MODULE, "Succesful shutdown");
	return exit_status;
}
Beispiel #13
0
static void test_nameinfo_pretty(void) {
        _cleanup_free_ char *stdin_name = NULL, *localhost = NULL;

        union sockaddr_union s = {
                .in.sin_family = AF_INET,
                .in.sin_port = 0,
                .in.sin_addr.s_addr = htonl(INADDR_ANY),
        };
        int r;

        union sockaddr_union c = {};
        socklen_t slen = sizeof(c.in), clen = sizeof(c.in);

        _cleanup_close_ int sfd = -1, cfd = -1;
        r = getnameinfo_pretty(STDIN_FILENO, &stdin_name);
        log_info_errno(r, "No connection remote: %m");

        assert_se(r < 0);

        sfd = socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, 0);
        assert_se(sfd >= 0);

        assert_se(bind(sfd, &s.sa, sizeof(s.in)) == 0);

        /* find out the port number */
        assert_se(getsockname(sfd, &s.sa, &slen) == 0);

        assert_se(listen(sfd, 1) == 0);

        assert_se(asynchronous_job(connect_thread, &s) == 0);

        log_debug("Accepting new connection on fd:%d", sfd);
        cfd = accept4(sfd, &c.sa, &clen, SOCK_CLOEXEC);
        assert_se(cfd >= 0);

        r = getnameinfo_pretty(cfd, &localhost);
        log_info("Connection from %s", localhost);
        assert_se(r == 0);
}

static void test_sockaddr_equal(void) {
        union sockaddr_union a = {
                .in.sin_family = AF_INET,
                .in.sin_port = 0,
                .in.sin_addr.s_addr = htonl(INADDR_ANY),
        };
        union sockaddr_union b = {
                .in.sin_family = AF_INET,
                .in.sin_port = 0,
                .in.sin_addr.s_addr = htonl(INADDR_ANY),
        };
        union sockaddr_union c = {
                .in.sin_family = AF_INET,
                .in.sin_port = 0,
                .in.sin_addr.s_addr = htonl(1234),
        };
        union sockaddr_union d = {
                .in6.sin6_family = AF_INET6,
                .in6.sin6_port = 0,
                .in6.sin6_addr = IN6ADDR_ANY_INIT,
        };
        assert_se(sockaddr_equal(&a, &a));
        assert_se(sockaddr_equal(&a, &b));
        assert_se(sockaddr_equal(&d, &d));
        assert_se(!sockaddr_equal(&a, &c));
        assert_se(!sockaddr_equal(&b, &c));
}

int main(int argc, char *argv[]) {

        log_set_max_level(LOG_DEBUG);

        test_socket_address_parse();
        test_socket_address_parse_netlink();
        test_socket_address_equal();
        test_socket_address_get_path();
        test_socket_address_is();
        test_socket_address_is_netlink();

        test_in_addr_is_null();
        test_in_addr_prefix_intersect();
        test_in_addr_prefix_next();
        test_in_addr_to_string();

        test_nameinfo_pretty();

        test_sockaddr_equal();

        return 0;
}
Beispiel #14
0
static int run_command(struct udev *udev, const struct udevadm_cmd *cmd, int argc, char *argv[]) {
        if (cmd->debug)
                log_set_max_level(LOG_DEBUG);
        log_debug("calling: %s", cmd->name);
        return cmd->cmd(udev, argc, argv);
}
int main(int argc, char *argv[]) {
    _cleanup_free_ char *name = NULL, *bus_name = NULL, *address = NULL;
    uint8_t *p;
    sd_bus *a, *b;
    int r, bus_ref;
    sd_bus_message *m;
    int f;
    uint64_t sz;
    uint32_t u32;
    size_t i, l;
    char *s;
    _cleanup_close_ int sfd = -1;

    log_set_max_level(LOG_DEBUG);

    assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid()) >= 0);

    bus_ref = bus_kernel_create_bus(name, false, &bus_name);
    if (bus_ref == -ENOENT)
        return EXIT_TEST_SKIP;

    assert_se(bus_ref >= 0);

    address = strappend("kernel:path=", bus_name);
    assert_se(address);

    r = sd_bus_new(&a);
    assert_se(r >= 0);

    r = sd_bus_new(&b);
    assert_se(r >= 0);

    r = sd_bus_set_address(a, address);
    assert_se(r >= 0);

    r = sd_bus_set_address(b, address);
    assert_se(r >= 0);

    r = sd_bus_start(a);
    assert_se(r >= 0);

    r = sd_bus_start(b);
    assert_se(r >= 0);

    r = sd_bus_message_new_method_call(b, &m, ":1.1", "/a/path", "an.inter.face", "AMethod");
    assert_se(r >= 0);

    r = sd_bus_message_open_container(m, 'r', "aysay");
    assert_se(r >= 0);

    r = sd_bus_message_append_array_space(m, 'y', FIRST_ARRAY, (void**) &p);
    assert_se(r >= 0);

    p[0] = '<';
    memset(p+1, 'L', FIRST_ARRAY-2);
    p[FIRST_ARRAY-1] = '>';

    f = memfd_new_and_map(NULL, STRING_SIZE, (void**) &s);
    assert_se(f >= 0);

    s[0] = '<';
    for (i = 1; i < STRING_SIZE-2; i++)
        s[i] = '0' + (i % 10);
    s[STRING_SIZE-2] = '>';
    s[STRING_SIZE-1] = 0;
    munmap(s, STRING_SIZE);

    r = memfd_get_size(f, &sz);
    assert_se(r >= 0);
    assert_se(sz == STRING_SIZE);

    r = sd_bus_message_append_string_memfd(m, f, 0, (uint64_t) -1);
    assert_se(r >= 0);

    close(f);

    f = memfd_new_and_map(NULL, SECOND_ARRAY, (void**) &p);
    assert_se(f >= 0);

    p[0] = '<';
    memset(p+1, 'P', SECOND_ARRAY-2);
    p[SECOND_ARRAY-1] = '>';
    munmap(p, SECOND_ARRAY);

    r = memfd_get_size(f, &sz);
    assert_se(r >= 0);
    assert_se(sz == SECOND_ARRAY);

    r = sd_bus_message_append_array_memfd(m, 'y', f, 0, (uint64_t) -1);
    assert_se(r >= 0);

    close(f);

    r = sd_bus_message_close_container(m);
    assert_se(r >= 0);

    r = sd_bus_message_append(m, "u", 4711);
    assert_se(r >= 0);

    assert_se((sfd = memfd_new_and_map(NULL, 6, (void**) &p)) >= 0);
    memcpy(p, "abcd\0", 6);
    munmap(p, 6);
    assert_se(sd_bus_message_append_string_memfd(m, sfd, 1, 4) >= 0);

    r = bus_message_seal(m, 55, 99*USEC_PER_SEC);
    assert_se(r >= 0);

    bus_message_dump(m, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);

    r = sd_bus_send(b, m, NULL);
    assert_se(r >= 0);

    sd_bus_message_unref(m);

    r = sd_bus_process(a, &m);
    assert_se(r > 0);

    bus_message_dump(m, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
    sd_bus_message_rewind(m, true);

    r = sd_bus_message_enter_container(m, 'r', "aysay");
    assert_se(r > 0);

    r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);
    assert_se(r > 0);
    assert_se(l == FIRST_ARRAY);

    assert_se(p[0] == '<');
    for (i = 1; i < l-1; i++)
        assert_se(p[i] == 'L');
    assert_se(p[l-1] == '>');

    r = sd_bus_message_read(m, "s", &s);
    assert_se(r > 0);

    assert_se(s[0] == '<');
    for (i = 1; i < STRING_SIZE-2; i++)
        assert_se(s[i] == (char) ('0' + (i % 10)));
    assert_se(s[STRING_SIZE-2] == '>');
    assert_se(s[STRING_SIZE-1] == 0);

    r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);
    assert_se(r > 0);
    assert_se(l == SECOND_ARRAY);

    assert_se(p[0] == '<');
    for (i = 1; i < l-1; i++)
        assert_se(p[i] == 'P');
    assert_se(p[l-1] == '>');

    r = sd_bus_message_exit_container(m);
    assert_se(r > 0);

    r = sd_bus_message_read(m, "u", &u32);
    assert_se(r > 0);
    assert_se(u32 == 4711);

    r = sd_bus_message_read(m, "s", &s);
    assert_se(r > 0);
    assert_se(streq_ptr(s, "bcd"));

    sd_bus_message_unref(m);

    sd_bus_unref(a);
    sd_bus_unref(b);

    return 0;
}
Beispiel #16
0
int main(int argc, char *argv[]) {
        struct udev *udev;
        static const struct option options[] = {
                { "debug", no_argument, NULL, 'd' },
                { "help", no_argument, NULL, 'h' },
                { "version", no_argument, NULL, 'V' },
                {}
        };
        const char *command;
        unsigned int i;
        int rc = 1, c;

        udev_parse_config();
        log_parse_environment();
        log_open();

        mac_selinux_init();

        udev = udev_new();
        if (udev == NULL)
                goto out;

        while ((c = getopt_long(argc, argv, "+dhV", options, NULL)) >= 0)
                switch (c) {

                case 'd':
                        log_set_max_level(LOG_DEBUG);
                        break;

                case 'h':
                        rc = adm_help(udev, argc, argv);
                        goto out;

                case 'V':
                        rc = adm_version(udev, argc, argv);
                        goto out;

                default:
                        goto out;
                }

        command = argv[optind];

        if (command != NULL)
                for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++)
                        if (streq(udevadm_cmds[i]->name, command)) {
                                argc -= optind;
                                argv += optind;
                                /* we need '0' here to reset the internal state */
                                optind = 0;
                                rc = run_command(udev, udevadm_cmds[i], argc, argv);
                                goto out;
                        }

        fprintf(stderr, "%s: missing or unknown command\n", program_invocation_short_name);
        rc = 2;
out:
        mac_selinux_finish();
        udev_unref(udev);
        log_close();
        return rc;
}
Beispiel #17
0
static void test_non_empty(void) {
        dual_timestamp ts;
        JournalFile *f;
        struct iovec iovec;
        static const char test[] = "TEST1=1", test2[] = "TEST2=2";
        Object *o;
        uint64_t p;
        char t[] = "/tmp/journal-XXXXXX";

        log_set_max_level(LOG_DEBUG);

        assert_se(mkdtemp(t));
        assert_se(chdir(t) >= 0);

        assert_se(journal_file_open("test.journal", O_RDWR|O_CREAT, 0666, true, true, NULL, NULL, NULL, &f) == 0);

        dual_timestamp_get(&ts);

        iovec.iov_base = (void*) test;
        iovec.iov_len = strlen(test);
        assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);

        iovec.iov_base = (void*) test2;
        iovec.iov_len = strlen(test2);
        assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);

        iovec.iov_base = (void*) test;
        iovec.iov_len = strlen(test);
        assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);

#ifdef HAVE_GCRYPT
        journal_file_append_tag(f);
#endif
        journal_file_dump(f);

        assert_se(journal_file_next_entry(f, 0, DIRECTION_DOWN, &o, &p) == 1);
        assert_se(le64toh(o->entry.seqnum) == 1);

        assert_se(journal_file_next_entry(f, p, DIRECTION_DOWN, &o, &p) == 1);
        assert_se(le64toh(o->entry.seqnum) == 2);

        assert_se(journal_file_next_entry(f, p, DIRECTION_DOWN, &o, &p) == 1);
        assert_se(le64toh(o->entry.seqnum) == 3);

        assert_se(journal_file_next_entry(f, p, DIRECTION_DOWN, &o, &p) == 0);

        assert_se(journal_file_next_entry(f, 0, DIRECTION_DOWN, &o, &p) == 1);
        assert_se(le64toh(o->entry.seqnum) == 1);

        assert_se(journal_file_find_data_object(f, test, strlen(test), NULL, &p) == 1);
        assert_se(journal_file_next_entry_for_data(f, NULL, 0, p, DIRECTION_DOWN, &o, NULL) == 1);
        assert_se(le64toh(o->entry.seqnum) == 1);

        assert_se(journal_file_next_entry_for_data(f, NULL, 0, p, DIRECTION_UP, &o, NULL) == 1);
        assert_se(le64toh(o->entry.seqnum) == 3);

        assert_se(journal_file_find_data_object(f, test2, strlen(test2), NULL, &p) == 1);
        assert_se(journal_file_next_entry_for_data(f, NULL, 0, p, DIRECTION_UP, &o, NULL) == 1);
        assert_se(le64toh(o->entry.seqnum) == 2);

        assert_se(journal_file_next_entry_for_data(f, NULL, 0, p, DIRECTION_DOWN, &o, NULL) == 1);
        assert_se(le64toh(o->entry.seqnum) == 2);

        assert_se(journal_file_find_data_object(f, "quux", 4, NULL, &p) == 0);

        assert_se(journal_file_move_to_entry_by_seqnum(f, 1, DIRECTION_DOWN, &o, NULL) == 1);
        assert_se(le64toh(o->entry.seqnum) == 1);

        assert_se(journal_file_move_to_entry_by_seqnum(f, 3, DIRECTION_DOWN, &o, NULL) == 1);
        assert_se(le64toh(o->entry.seqnum) == 3);

        assert_se(journal_file_move_to_entry_by_seqnum(f, 2, DIRECTION_DOWN, &o, NULL) == 1);
        assert_se(le64toh(o->entry.seqnum) == 2);

        assert_se(journal_file_move_to_entry_by_seqnum(f, 10, DIRECTION_DOWN, &o, NULL) == 0);

        journal_file_rotate(&f, true, true);
        journal_file_rotate(&f, true, true);

        journal_file_close(f);

        log_info("Done...");

        if (arg_keep)
                log_info("Not removing %s", t);
        else {
                journal_directory_vacuum(".", 3000000, 0, 0, NULL, true);

                assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
        }

        puts("------------------------------------------------------------");
}