Beispiel #1
0
/*
 * get the bitmask of the present nodes including offline nodes
 *
 * return value: 0  - success
 * 		 -1 - failed
 */
int present_memmask(struct bitmask *memmask)
{
	FILE *fp = NULL;
	char buf[BUFFSIZE];

	if (memmask == NULL)
		return -1;

	/*
	 * open file /sys/devices/system/node/possible and get present
	 * nodelist
	 */
	if ((fp = fopen(LIST_PRESENT_MEM_FILE, "r")) == NULL)
		return -1;

	if (fgets(buf, sizeof(buf), fp) == NULL) {
		fclose(fp);
		return -1;
	}

	fclose(fp);

	/* parse present nodelist to bitmap */
	buf[strlen(buf) - 1] = '\0';
	if (bitmask_parselist(buf, memmask) != 0)
		return -1;

	return 0;
}
Beispiel #2
0
int main(int argc, char **argv)
{
	struct bitmask *mask1 = NULL, *mask2 = NULL, *mask3 = NULL;
	char buff[MAX_STRING_SIZE];

	checkopt(argc, argv);

	mask1 = bitmask_alloc(MAX_NBITS);
	if (mask1 == NULL)
		err(EXIT_FAILURE, "alloc memory space for bitmask1 failed.");

	mask2 = bitmask_alloc(MAX_NBITS);
	if (mask2 == NULL)
		err(EXIT_FAILURE, "alloc memory space for bitmask2 failed.");

	mask3 = bitmask_alloc(MAX_NBITS);
	if (mask3 == NULL)
		err(EXIT_FAILURE, "alloc memory space for bitmask3 failed.");

	if (bitmask_parselist(argv[argc - 2 + convert], mask1) != 0)
		err(EXIT_FAILURE, "parse list1 string failed.");

	if (convert) {
		bitmask_displaylist(buff, MAX_STRING_SIZE, mask1);
		printf("%s\n", buff);
		return 0;
	}

	if (bitmask_parselist(argv[argc - 1], mask2) != 0)
		err(EXIT_FAILURE, "parse list2 string failed.");

	if (add_or_subtract)
		bitmask_andnot(mask3, mask1, mask2);
	else
		bitmask_or(mask3, mask1, mask2);

	bitmask_displaylist(buff, MAX_STRING_SIZE, mask3);
	printf("%s\n", buff);

	return 0;
}
static void handle_options(int *argc, const char ***argv)
{
	int ret, x, new_argc = 0;

	if (*argc < 1)
		return;

	for (x = 0;  x < *argc && ((*argv)[x])[0] == '-'; x++) {
		const char *param = (*argv)[x];
		if (!strcmp(param, "-h") || !strcmp(param, "--help")) {
			print_help();
			exit(EXIT_SUCCESS);
		} else if (!strcmp(param, "-c") || !strcmp(param, "--cpu")) {
			if (*argc < 2) {
				print_help();
				exit(EXIT_FAILURE);
			}
			if (!strcmp((*argv)[x+1], "all"))
				bitmask_setall(cpus_chosen);
			else {
				ret = bitmask_parselist(
						(*argv)[x+1], cpus_chosen);
				if (ret < 0) {
					fprintf(stderr, _("Error parsing cpu "
							  "list\n"));
					exit(EXIT_FAILURE);
				}
			}
			x += 1;
			
			new_argc += 2;
			continue;
		} else if (!strcmp(param, "-v") ||
			!strcmp(param, "--version")) {
			print_version();
			exit(EXIT_SUCCESS);
#ifdef DEBUG
		} else if (!strcmp(param, "-d") || !strcmp(param, "--debug")) {
			be_verbose = 1;
			new_argc++;
			continue;
#endif
		} else {
			fprintf(stderr, "Unknown option: %s\n", param);
			print_help();
			exit(EXIT_FAILURE);
		}
	}
	*argc -= new_argc;
	*argv += new_argc;
}