mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: kthread execve question
@ 2002-09-02 16:18 Petr Vandrovec
  0 siblings, 0 replies; 2+ messages in thread
From: Petr Vandrovec @ 2002-09-02 16:18 UTC (permalink / raw)
  To: Der Herr Hofrat; +Cc: linux-kernel

On  2 Sep 02 at 17:03, Der Herr Hofrat wrote:
> 
>  any hint whats wrong ? any pointers to using kernel threads dosc/examples in 
>  general and how to execute user space apps would be appreciated.
> 
> char cmd_path[256] = "/bin/echo";
> 
> static int exec_cmd(void * kthread_arg)
> {
>     static char * envp[] = { "HOME=/", 
>         "TERM=linux", 
>         "PATH=/:/bin:/usr/bin:/usr/bin", 
>         NULL };
>     char *argv[] = { kthread_arg,
>         ">>",
>         "/tmp/kthread_echo", 

'>>' is bash thing. Try executing "/bin/touch" with "/tmp/testfile" instead.
If /tmp/testfile will appear, you got it.

And also do not forget that argv[0] should contain program name, not
first argument - so in most cases you want
exec_usermodehelper(argv[0], argv, envp) ...
                                                    Petr Vandrovec
                                                    

^ permalink raw reply	[flat|nested] 2+ messages in thread

* kthread execve question
@ 2002-09-02 15:03 Der Herr Hofrat
  0 siblings, 0 replies; 2+ messages in thread
From: Der Herr Hofrat @ 2002-09-02 15:03 UTC (permalink / raw)
  To: linux-kernel


HI !

 starting out at kernel/kmod.c as an example I tried to execve a simple command
 from a kernel thread using the exec_usermodehelper from kmod (kmod enabled in
 the kernel). It all seems to be fine - the printk appears but the command is
 not executed...

 any hint whats wrong ? any pointers to using kernel threads dosc/examples in 
 general and how to execute user space apps would be appreciated.

thx !
hofrat

--- broken hello world kthread ---
#define __KERNEL_SYSCALLS__

#include <linux/config.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/unistd.h>
#include <linux/kmod.h>
#include <linux/smp_lock.h>

#include <asm/uaccess.h>

char cmd_path[256] = "/bin/echo";

static int exec_cmd(void * kthread_arg)
{
	static char * envp[] = { "HOME=/", 
		"TERM=linux", 
		"PATH=/:/bin:/usr/bin:/usr/bin", 
		NULL };
	char *argv[] = { kthread_arg,
		">>",
		"/tmp/kthread_echo", 
		NULL };
	int ret;

	printk("calling usermodehelper for %s \n",cmd_path); 
	ret = exec_usermodehelper(cmd_path, argv, envp);

	printk(KERN_ERR "failed to exec %s, ret = %d\n", cmd_path,ret);
	return ret;
}

int init_module(void) {
	pid_t pid;
	char kthread_arg[]="Hello World";

	pid = kernel_thread(exec_cmd, (void*) kthread_arg, 0);
	if (pid < 0) {
		printk(KERN_ERR "fork failed, errno %d\n", -pid);
		return pid;
	}
	printk("fork ok, pid %d\n",pid);
	return 0;
}

void cleanup_module(void) {
	printk("module exit\n");
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-09-02 16:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-02 16:18 kthread execve question Petr Vandrovec
  -- strict thread matches above, loose matches on Subject: below --
2002-09-02 15:03 Der Herr Hofrat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®