Пример #1
0
static int powerd(void *__unused)
{
	static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
	char *argv[] = { "/sbin/shutdown", "-h", "now", NULL };
	DECLARE_WAITQUEUE(wait, current);

	daemonize("powerd");

	add_wait_queue(&powerd_wait, &wait);
again:
	for (;;) {
		set_task_state(current, TASK_INTERRUPTIBLE);
		if (button_pressed)
			break;
		flush_signals(current);
		schedule();
	}
	__set_current_state(TASK_RUNNING);
	remove_wait_queue(&powerd_wait, &wait);

	/* Ok, down we go... */
	button_pressed = 0;
	if (kernel_execve("/sbin/shutdown", argv, envp) < 0) {
		printk("powerd: shutdown execution failed\n");
		add_wait_queue(&powerd_wait, &wait);
		goto again;
	}
	return 0;
}
Пример #2
0
void *usrland_test(int arg1, void *arg2){
	const char* filename="/sbin/init";
	char *argv[] = { NULL };
    	char *envp[] = { NULL };
	kernel_execve(filename,argv,envp);
	return NULL;
}
Пример #3
0
/*
 * This is the task which runs the usermode application
 */
static int ____call_usermodehelper(void *data)
{
	struct subprocess_info *sub_info = data;
	int retval;

	spin_lock_irq(&current->sighand->siglock);
	flush_signal_handlers(current, 1);
	spin_unlock_irq(&current->sighand->siglock);

	/* We can run anywhere, unlike our parent keventd(). */
	set_cpus_allowed_ptr(current, cpu_all_mask);

	/*
	 * Our parent is keventd, which runs with elevated scheduling priority.
	 * Avoid propagating that into the userspace child.
	 */
	set_user_nice(current, 0);

	if (sub_info->init) {
		retval = sub_info->init(sub_info);
		if (retval)
			goto fail;
	}

	retval = kernel_execve(sub_info->path, sub_info->argv, sub_info->envp);

	/* Exec failed? */
fail:
	sub_info->retval = retval;
	do_exit(0);
}
Пример #4
0
static int __init do_linuxrc(void * shell)
{
	static char *argv[] = { "linuxrc", NULL, };
	extern char * envp_init[];

	sys_close(old_fd);sys_close(root_fd);
	sys_setsid();
	return kernel_execve(shell, argv, envp_init);
}
Пример #5
0
static int dumpfn(void *arg)
{
	int i;
	int *pfd = arg;
	char *argv[] = { "iptables-restore", "-c", NULL };

	if (pfd[0] != 0)
		sc_dup2(pfd[0], 0);

	for (i=1; i<current->files->fdt->max_fds; i++)
		sc_close(i);

	module_put(THIS_MODULE);

	set_fs(KERNEL_DS);
	i = kernel_execve("/sbin/iptables-restore", argv, NULL);
	if (i == -ENOENT)
		i = kernel_execve("/usr/sbin/iptables-restore", argv, NULL);
	eprintk("failed to exec iptables-restore: %d\n", i);
	return 255 << 8;
}
Пример #6
0
static int __init do_linuxrc(void * shell)
{
	static char *argv[] = { "linuxrc", NULL, };
	extern char * envp_init[];

	sys_close(old_fd);sys_close(root_fd);
	sys_close(0);sys_close(1);sys_close(2);
	sys_setsid();
	(void) sys_open((const char __user *)"/dev/console",O_RDWR,0);
	(void) sys_dup(0);
	(void) sys_dup(0);
	return kernel_execve(shell, argv, envp_init);
}
Пример #7
0
static void *
initproc_run(int arg1, void *arg2)
{

   /*#ifdef __DRIVERS__

       while(1){

       int op = do_open("/usr/bin/hello",O_RDONLY);

        kshell_add_command("sunghan", sunghanTest, "Runs sunghan test");
        kshell_add_command("faber", fabertest, "Runs Faber test");
        kshell_add_command("deadlock", deadlock, "Runs Faber test");

        kshell_add_command("vfstest",(void*)vfstest, "Runs vfs test");
        kshell_add_command("faber",faber_fs_thread_test,"Runs faber test");
        kshell_add_command("faber_dir",faber_directory_test,"Runs faber directory test");
        kshell_add_command("rename_test",rename_test,"Runs rename_test");

           kshell_t *kshell = kshell_create(0);
        if (NULL == kshell) panic("init: Couldn't create kernel shell\n");
        while (kshell_execute_next(kshell));
            kshell_destroy(kshell);
            int s;
        while(do_waitpid(-1, 0, &s)==1);
        return  0;
        }
    #endif  __DRIVERS__ */

        /*int fd = do_open("/dev/tty0", O_RDONLY);
        fd = do_open("/dev/tty0", O_WRONLY);
       
       char *argv2[] = {"memtest",NULL};
        char *envp2[] = {NULL};
        kernel_execve("/usr/bin/memtest",argv2,envp2);*/

        char *argv1[] = {"init",NULL};
        char *envp1[] = {NULL};
        kernel_execve("/sbin/init",argv1,envp1);

        /*char *argv[] = {"vfstest",NULL};
        char *envp[] = {NULL};
        kernel_execve("/usr/bin/vfstest",argv,envp);
        
        do_exit(0);
        do_close(fd);*/

        return 0;
}
Пример #8
0
/**
 * The init thread's function changes depending on how far along your Weenix is
 * developed. Before VM/FI, you'll probably just want to have this run whatever
 * tests you've written (possibly in a new process). After VM/FI, you'll just
 * exec "/bin/init".
 *
 * Both arguments are unused.
 *
 * @param arg1 the first argument (unused)
 * @param arg2 the second argument (unused)
 */
static void *
initproc_run(int arg1, void *arg2)
{
        /* PROCS {{{ */
#ifdef __VM__
        int status;

        dbg(DBG_INIT, "do_init!\n");

        do_open("/dev/tty0", O_RDONLY);
        do_open("/dev/tty0", O_WRONLY);
        do_open("/dev/tty0", O_WRONLY);

        char *const argvec[] = { "foo", NULL };
        char *const envvec[] = { "bar", NULL };
        kernel_execve("/sbin/init", argvec, envvec);

        while (!do_waitpid(-1, 0, &status));
        do_exit(0);
#endif

#ifdef __DRIVERS__

        /* If we do not have VM yet, run the kernel shell */
        kshell_t *kshell;

        /* Create kernel shell on TTY 0 */
        kshell = kshell_create(0);
        if (NULL == kshell)
                panic("init: Couldn't create kernel shell\n");

        while (kshell_execute_next(kshell));
        kshell_destroy(kshell);
#endif
        /* PROCS }}} */
    
    
#ifdef __VFS__
        /*TEST VFS*/
        vfstest_main(1,NULL);
        do_exit(0);
#endif

        return NULL;
}
Пример #9
0
/*
 * This is the task which runs the usermode application
 */
static int ____call_usermodehelper(void *data)
{
	struct subprocess_info *sub_info = data;
	int retval;

	//TODO:RAWLINSON
	struct cpumask cpu_padrao = cpumask_of_cpu(CPUID_PADRAO);

	spin_lock_irq(&current->sighand->siglock);
	flush_signal_handlers(current, 1);
	spin_unlock_irq(&current->sighand->siglock);

	/* We can run anywhere, unlike our parent keventd(). */
	//TODO:RAWLINSON
	//set_cpus_allowed_ptr(current, cpu_all_mask); //TODO:RAWLINSON - CODIGO ORIGINAL...
	current->cpus_allowed = cpu_padrao;
	set_cpus_allowed_ptr(current, &cpu_padrao);

	/*
	 * Our parent is keventd, which runs with elevated scheduling priority.
	 * Avoid propagating that into the userspace child.
	 */
	set_user_nice(current, 0);

	if (sub_info->init) {
		retval = sub_info->init(sub_info);
		if (retval)
			goto fail;
	}

	retval = kernel_execve(sub_info->path,
			       (const char *const *)sub_info->argv,
			       (const char *const *)sub_info->envp);

	/* Exec failed? */
fail:
	sub_info->retval = retval;
	do_exit(0);
}
Пример #10
0
/**
 * The init thread's function changes depending on how far along your Weenix is
 * developed. Before VM/FI, you'll probably just want to have this run whatever
 * tests you've written (possibly in a new process). After VM/FI, you'll just
 * exec "/bin/init".
 *
 * Both arguments are unused.
 *
 * @param arg1 the first argument (unused)
 * @param arg2 the second argument (unused)
 */
static void *
initproc_run(int arg1, void *arg2)
{
	dbg(DBG_CORE, "running initproc_run\n");

	/* TESTS */
	my_proctest();
	my_drivertest();
	my_s5fstest();
	my_vmtest();

	vfstest_main(1, NULL);

#ifdef __VM__
	int status;
	char *const argv[] = { "hello", NULL };
	char *const envp[] = { "world", NULL };

	do_open("/dev/tty0", O_RDONLY);
	do_open("/dev/tty0", O_WRONLY);
	do_open("/dev/tty0", O_WRONLY);

	kernel_execve("/sbin/init", argv, envp);

	while (!do_waitpid(-1, 0, &status));
	do_exit(0);
#endif

	/* KSHELL */
	int err = 0;
	kshell_t *ksh = kshell_create(0);
	KASSERT(ksh && "did not create a kernel shell as expected");

	while ((err = kshell_execute_next(ksh)) > 0);
	KASSERT(err == 0 && "kernel shell exited with an error\n");
	kshell_destroy(ksh);

        return NULL;
}
Пример #11
0
static void run_init_process(char *init_filename)
{
	argv_init[0] = init_filename;
	kernel_execve(init_filename, argv_init, envp_init);
}
Пример #12
0
/*
 * This is the task which runs the usermode application
 */
static int ____call_usermodehelper(void *data)
{
	struct subprocess_info *sub_info = data;
	int retval;

	BUG_ON(atomic_read(&sub_info->cred->usage) != 1);

	/* Unblock all signals */
	spin_lock_irq(&current->sighand->siglock);
	flush_signal_handlers(current, 1);
	sigemptyset(&current->blocked);
	recalc_sigpending();
	spin_unlock_irq(&current->sighand->siglock);

	/* Install the credentials */
	commit_creds(sub_info->cred);
	sub_info->cred = NULL;

	/* Install input pipe when needed */
	if (sub_info->stdin) {
		struct files_struct *f = current->files;
		struct fdtable *fdt;
		/* no races because files should be private here */
		sys_close(0);
		fd_install(0, sub_info->stdin);
		spin_lock(&f->file_lock);
		fdt = files_fdtable(f);
		FD_SET(0, fdt->open_fds);
		FD_CLR(0, fdt->close_on_exec);
		spin_unlock(&f->file_lock);

		/* and disallow core files too */
		current->signal->rlim[RLIMIT_CORE] = (struct rlimit){0, 0};
	}

	/* We can run anywhere, unlike our parent keventd(). */
	set_cpus_allowed_ptr(current, cpu_all_mask);

	/*
	 * Our parent is keventd, which runs with elevated scheduling priority.
	 * Avoid propagating that into the userspace child.
	 */
	set_user_nice(current, 0);

	if (sub_info->init) {
		retval = sub_info->init(sub_info);
		if (retval)
			goto fail;
	}

	retval = kernel_execve(sub_info->path, sub_info->argv, sub_info->envp);

	/* Exec failed? */
fail:
	sub_info->retval = retval;
	return 0;
}

void call_usermodehelper_freeinfo(struct subprocess_info *info)
{
	if (info->cleanup)
		(*info->cleanup)(info);
	if (info->cred)
		put_cred(info->cred);
	kfree(info);
}
EXPORT_SYMBOL(call_usermodehelper_freeinfo);

static void umh_complete(struct subprocess_info *sub_info)
{
	struct completion *comp = xchg(&sub_info->complete, NULL);
	/*
	 * See call_usermodehelper_exec(). If xchg() returns NULL
	 * we own sub_info, the UMH_KILLABLE caller has gone away.
	 */
	if (comp)
		complete(comp);
	else
		call_usermodehelper_freeinfo(sub_info);
}

/* Keventd can't block, but this (a child) can. */
static int wait_for_helper(void *data)
{
	struct subprocess_info *sub_info = data;
	pid_t pid;

	/* Install a handler: if SIGCLD isn't handled sys_wait4 won't
	 * populate the status, but will return -ECHILD. */
	allow_signal(SIGCHLD);

	pid = kernel_thread(____call_usermodehelper, sub_info, SIGCHLD);
	if (pid < 0) {
		sub_info->retval = pid;
	} else {
		int ret;

		/*
		 * Normally it is bogus to call wait4() from in-kernel because
		 * wait4() wants to write the exit code to a userspace address.
		 * But wait_for_helper() always runs as keventd, and put_user()
		 * to a kernel address works OK for kernel threads, due to their
		 * having an mm_segment_t which spans the entire address space.
		 *
		 * Thus the __user pointer cast is valid here.
		 */
		sys_wait4(pid, (int __user *)&ret, 0, NULL);

		/*
		 * If ret is 0, either ____call_usermodehelper failed and the
		 * real error code is already in sub_info->retval or
		 * sub_info->retval is 0 anyway, so don't mess with it then.
		 */
		if (ret)
			sub_info->retval = ret;
	}

	if (sub_info->wait == UMH_NO_WAIT)
		call_usermodehelper_freeinfo(sub_info);
	else
		umh_complete(sub_info);
	return 0;
}

/* This is run by khelper thread  */
static void __call_usermodehelper(struct work_struct *work)
{
	struct subprocess_info *sub_info =
		container_of(work, struct subprocess_info, work);
	int wait = sub_info->wait & ~UMH_KILLABLE;
	pid_t pid;

	BUG_ON(atomic_read(&sub_info->cred->usage) != 1);

	/* CLONE_VFORK: wait until the usermode helper has execve'd
	 * successfully We need the data structures to stay around
	 * until that is done.  */
	if (wait == UMH_WAIT_PROC || wait == UMH_NO_WAIT)
		pid = kernel_thread(wait_for_helper, sub_info,
				    CLONE_FS | CLONE_FILES | SIGCHLD);
	else
		pid = kernel_thread(____call_usermodehelper, sub_info,
				    CLONE_VFORK | SIGCHLD);

	switch (wait) {
	case UMH_NO_WAIT:
		break;

	case UMH_WAIT_PROC:
		if (pid > 0)
			break;
		sub_info->retval = pid;
		/* FALLTHROUGH */

	case UMH_WAIT_EXEC:
		umh_complete(sub_info);
	}
}

#ifdef CONFIG_PM_SLEEP
/*
 * If set, call_usermodehelper_exec() will exit immediately returning -EBUSY
 * (used for preventing user land processes from being created after the user
 * land has been frozen during a system-wide hibernation or suspend operation).
 * Should always be manipulated under umhelper_sem acquired for write.
 */
static int usermodehelper_disabled;

/* Number of helpers running */
static atomic_t running_helpers = ATOMIC_INIT(0);

/*
 * Wait queue head used by usermodehelper_pm_callback() to wait for all running
 * helpers to finish.
 */
static DECLARE_WAIT_QUEUE_HEAD(running_helpers_waitq);

/*
 * Time to wait for running_helpers to become zero before the setting of
 * usermodehelper_disabled in usermodehelper_pm_callback() fails
 */
#define RUNNING_HELPERS_TIMEOUT	(5 * HZ)

void read_lock_usermodehelper(void)
{
	down_read(&umhelper_sem);
}