Пример #1
0
static int
u_dpm_set_task_state(pid_t pid, dpm_state_t task_state)
{
	return dpm_set_task_state(pid, task_state);
}
Пример #2
0
static int 
write_proc_dpm_cmd (struct file *file, const char *buffer,
		    unsigned long count, void *data)
{
	char *buf, *tok, **tokptrs;
	char *whitespace = " \t\r\n";
	int ret = 0, ntoks;

	if (current->uid != 0)
		return -EACCES;
	if (count == 0)
		return 0;
	if (!(buf = kmalloc(count + 1, GFP_KERNEL)))
		return -ENOMEM;
	if (copy_from_user(buf, buffer, count)) {
		ret = -EFAULT;
		goto out0;
	}

	buf[count] = '\0';

	if (!(tokptrs = (char **)__get_free_page(GFP_KERNEL))) {
		ret = -ENOMEM;
		goto out1;
	}

	ret = -EINVAL;
	ntoks = 0;
	do {
		buf = buf + strspn(buf, whitespace);
		tok = strsep(&buf, whitespace);
		if (*tok == '\0') {
			if (ntoks == 0) {
				ret = 0;
				goto out1;
			} else
				break;
		}
		if (ntoks == (PAGE_SIZE / sizeof(char **)))
			goto out1;
		tokptrs[ntoks++] = tok;
	} while(buf);

	if (ntoks == 1) {
		if (strcmp(tokptrs[0], "init") == 0) {
			ret = dpm_init();
		} else if (strcmp(tokptrs[0], "enable") == 0) {
			ret = dpm_enable();
		} else if (strcmp(tokptrs[0], "disable") == 0) {
			ret = dpm_disable();
		} else if (strcmp(tokptrs[0], "terminate") == 0) {
			ret = dpm_terminate();
		}
	} else if (ntoks == 2) {
		if (strcmp(tokptrs[0], "set_policy") == 0)
			ret = dpm_set_policy(tokptrs[1]);
		else if (strcmp(tokptrs[0], "set_state") == 0)
			ret = dpm_set_op_state(tokptrs[1]);
	} else {
		if (strcmp(tokptrs[0], "set_task_state") == 0) {
			if (ntoks != 3) 
				pwarn("set_task_state", ntoks, "", 3);
			else
				ret = dpm_set_task_state(simple_strtol(tokptrs[1],
								       NULL, 0),
							 simple_strtol(tokptrs[2],
								       NULL, 0));
		} else if (strcmp(tokptrs[0], "create_opt") == 0) {
			if (ntoks != DPM_PP_NBR + 2)
				pwarn("create_opt", ntoks, 
				      "", DPM_PP_NBR + 2);
			else {
				dpm_md_pp_t pp[DPM_PP_NBR];
				int i;
			
				for (i = 0; i < DPM_PP_NBR; i++)
					pp[i] = simple_strtol(tokptrs[i + 2],
							      NULL, 0);
				ret = dpm_create_opt(tokptrs[1], pp);
			}

		} else if (strcmp(tokptrs[0], "create_class") == 0) {
			if (ntoks < 3) 
				pwarn("create_class", ntoks, ">= ", 3);
			else 
				ret = dpm_create_class(tokptrs[1], &tokptrs[2],
						       ntoks - 2);

		} else if (strcmp(tokptrs[0], "create_policy") == 0) {
			if (ntoks != (DPM_STATES + 2)) 
				pwarn("create_policy", ntoks, "", 
				      DPM_STATES + 2);
			else 
				ret = dpm_create_policy(tokptrs[1],
							&tokptrs[2]);
		}
	}
out1:
	free_page((unsigned long)tokptrs);
out0:
	kfree(buf);
	if (ret == 0)
		return count;
	else 
		return ret;
}