int main(int argc, char *argv[]) {
        int r, k;
        ItemArray *a;
        Iterator iterator;
        _cleanup_strv_free_ char **config_dirs = NULL;
        bool invalid_config = false;
        char **f;

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

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

        umask(0022);

        mac_selinux_init();

        items = ordered_hashmap_new(&string_hash_ops);
        globs = ordered_hashmap_new(&string_hash_ops);

        if (!items || !globs) {
                r = log_oom();
                goto finish;
        }

        r = 0;

        if (arg_user) {
                r = user_config_paths(&config_dirs);
                if (r < 0) {
                        log_error_errno(r, "Failed to initialize configuration directory list: %m");
                        goto finish;
                }
        } else {
                config_dirs = strv_split_nulstr(CONF_PATHS_NULSTR("tmpfiles.d"));
                if (!config_dirs) {
                        r = log_oom();
                        goto finish;
                }
        }

        if (DEBUG_LOGGING) {
                _cleanup_free_ char *t = NULL;

                t = strv_join(config_dirs, "\n\t");
                if (t)
                        log_debug("Looking for configuration files in (higher priority first:\n\t%s", t);
        }

        if (optind < argc) {
                int j;

                for (j = optind; j < argc; j++) {
                        k = read_config_file((const char**) config_dirs, argv[j], false, &invalid_config);
                        if (k < 0 && r == 0)
                                r = k;
                }

        } else {
                _cleanup_strv_free_ char **files = NULL;

                r = conf_files_list_strv(&files, ".conf", arg_root, 0, (const char* const*) config_dirs);
                if (r < 0) {
                        log_error_errno(r, "Failed to enumerate tmpfiles.d files: %m");
                        goto finish;
                }

                STRV_FOREACH(f, files) {
                        k = read_config_file((const char**) config_dirs, *f, true, &invalid_config);
                        if (k < 0 && r == 0)
                                r = k;
                }
        }

        /* The non-globbing ones usually create things, hence we apply
         * them first */
        ORDERED_HASHMAP_FOREACH(a, items, iterator) {
                k = process_item_array(a);
                if (k < 0 && r == 0)
                        r = k;
        }

        /* The globbing ones usually alter things, hence we apply them
         * second. */
        ORDERED_HASHMAP_FOREACH(a, globs, iterator) {
                k = process_item_array(a);
                if (k < 0 && r == 0)
                        r = k;
        }

finish:
        ordered_hashmap_free_with_destructor(items, item_array_free);
        ordered_hashmap_free_with_destructor(globs, item_array_free);

        free(arg_include_prefixes);
        free(arg_exclude_prefixes);
        free(arg_root);

        set_free_free(unix_sockets);

        mac_selinux_finish();

        if (r < 0)
                return EXIT_FAILURE;
        else if (invalid_config)
                return EX_DATAERR;
        else
                return EXIT_SUCCESS;
}