Пример #1
0
static int run(struct fi_info *hints, char *node, char *port)
{
	struct fi_info *info;
	int ret;
	uint64_t flags;

	flags = list_providers ? FI_PROV_ATTR_ONLY : 0;
	ret = fi_getinfo(FI_VERSION(FI_MAJOR_VERSION, FI_MINOR_VERSION),
			node, port, flags, hints, &info);
	if (ret) {
		fprintf(stderr, "fi_getinfo: %d\n", ret);
		return ret;
	}

	if (env)
		ret = print_vars();
	else if (verbose)
		ret = print_long_info(info);
	else if (list_providers)
		ret = print_providers(info);
	else
		ret = print_short_info(info);

	fi_freeinfo(info);
	return ret;
}
Пример #2
0
static int bee_dep_list(int argc, char *argv[])
{
    int c, i, opt_count, help, files, packages, count,
        depending_on, required_by, removable, provider_of,
        not_cached, broken;
    struct hash *graph;
    char *name;
    struct option long_options[] = {
        {"help",         0, &help,         1},
        {"files",        0, &files,        1},
        {"packages",     0, &packages,     1},
        {"count",        0, &count,        1},
        {"depending-on", 0, &depending_on, 1},
        {"required-by",  0, &required_by,  1},
        {"removable",    0, &removable,    1},
        {"provider-of",  0, &provider_of,  1},
        {"not-cached",   0, &not_cached,   1},
        {"broken",       0, &broken,       1},
        {0, 0, 0, 0}
    };

    opt_count = help         = files       = packages  = provider_of =
    count     = depending_on = required_by = removable = not_cached  =
    broken    = 0;

    while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) {
        switch (c) {
            case '?':
                usage_list();
                return 1;

            default:
                opt_count++;
        }
    }

    if (help) {
        usage_list();
        return 0;
    }

    if (!opt_count && optind != argc) {
        fprintf(stderr, "bee-dep: too many arguments\n");
        return 1;
    }

    if (!opt_count)
        packages = 1;

    if (opt_count > 1 && !count) {
        fprintf(stderr, "bee-dep: too many options specified\n");
        return 1;
    }

    if (packages) {
        graph = get_cache();

        if (count)
            printf("%d\n", count_packages(graph));
        else
            list_packages(graph);

        hash_free(graph);
        return 0;
    }

    if (broken && optind < argc) {
        fprintf(stderr, "bee-dep: too many arguments\n");
        return 1;
    }

    if (optind == argc && !broken) {
        fprintf(stderr, "bee-dep: arguments needed\n");
        return 1;
    }

    if (count && (depending_on || required_by))
        fprintf(stderr, "bee-dep: ignoring option --count\n");

    graph = get_cache();

    for (i = optind; i < argc; i++) {
        name = argv[i];

        if (optind < argc - 1)
            printf("%s:\n", name);

        if (files) {
            if (count) {
                c = count_files(graph, name);

                if (c < 0) {
                    hash_free(graph);
                    return 1;
                }

                printf("%d\n", c);
            } else if (list_files(graph, name)) {
                 hash_free(graph);
                 return 1;
            }
        }

        if (removable) {
            if (count) {
                c = count_removable(graph, name);

                if (c < 0) {
                    hash_free(graph);
                    return 1;
                }

                printf("%d\n", c);
            } else if (print_removable(graph, name)) {
                hash_free(graph);
                return 1;
            }
        }

        if (depending_on && print_neededby(graph, name)) {
            hash_free(graph);
            return 1;
        }

        if (required_by && print_needs(graph, name)) {
            hash_free(graph);
            return 1;
        }

        if (provider_of) {
            if (count) {
                c = count_providers(graph, name);

                if (c < 0) {
                    hash_free(graph);
                    return 1;
                }

                printf("%d\n", c);
            } else if (print_providers(graph, name)) {
                hash_free(graph);
                return 1;
            }
        }

        if (not_cached) {
            c = print_not_cached(graph, name, !count);

            if (c < 0) {
                hash_free(graph);
                return 1;
            }

            if (count)
                printf("%d\n", c);
        }
    }

    if (broken) {
        c = print_broken(graph, !count);

        if (c < 0) {
            hash_free(graph);
            return 1;
        }

        if (count)
            printf("%d\n", c);
    }

    hash_free(graph);
    return 0;
}