How to do execve in kernel_thread ...?

Thomas Omerzu (omerzu@quantum.de)
15 Sep 1996 21:06:38 GMT


Hi to all kernel wizards,

I tried to build a module that creates a kernel_thread, which does
an execve(). Unfortunately, the execve() fails with errno 14.
So this has probably something to do with memory allocation for the
function arguments. All examples of kernel execve's I could find
don't seem to have this problem, so I'm somewhat clueless.

Example code follows, could someone please tell me what's going wrong?
Thanks a lot in advance ...

Thomas.

-------------------------------------------------------------------

#include <linux/module.h>

#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/config.h>
#include <linux/sched.h>
#include <linux/kernel.h>

#define __KERNEL_SYSCALLS__
#include <linux/unistd.h>

static int errno=0;
static char * argv[] = { "sleep", "20", NULL };
static char * envp[] = { "HOME=/", NULL };

static int do_shell(void *shell)
{
execve(shell, argv, envp);
printk("execve error: %d\n",errno);
return 0;
}

#ifdef MODULE
int init_module(void)
{
int pid = kernel_thread(do_shell,"/usr/bin/sleep",SIGCHLD);
printk("pid is %d\n",pid);
return 0;
}

void cleanup_module( void) {
return;
}
#endif

-- 
*----------------------------------------------------------------------------*
      Thomas Omerzu        Internet:   omerzu@quantum.de
  Quantum Software GmbH    Web:        http://www.quantum.de/~to/
    Dortmund, Germany      Telefon:    +49-231-9749-233      Fax: -3