[lkml]   [1996]   [Sep]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectHow to do execve in kernel_thread ...?

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 ...



#include <linux/module.h>

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

#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) {

Thomas Omerzu Internet:
Quantum Software GmbH Web:
Dortmund, Germany Telefon: +49-231-9749-233 Fax: -3

 \ /
  Last update: 2005-03-22 13:38    [W:0.028 / U:0.280 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site