My Tech notes: Calling User Space Program From Kernel Space
Subscribe

Unix Documentation

Free Online Unix Training Materials

Lists many links to free Unix training materials.

Pointers and Arrays Materials

Pointers and Arrays materials Explained for C beginners

C FAQ and General Questions C Interview Questions

Powered By

Free XML Skins for Blogger

Powered by Blogger

Monday, December 15, 2008

Calling User Space Program From Kernel Space

Invoking user mode application from kernel modules, yes its possible with help of CALL_USERMODEHELPER.
With the following kernel API, we can invoke user mode application from Kernel modules/threads.


int call_usermodehelper (char * path, char ** argv, char ** envp, int wait);

path: pathname for the application.
argv: null-terminated argument list.
envp: null-terminated environment list.
wait: wait for application to finish and return status.


Example:

Kernel Module:
#include
#include

char name[]="user_program";

static int init_function(void)
{
int ret;
char *argv[] = {name, "hello", "world", NULL };
static char *envp[] = { "HOME=/",
"TERM=linux",
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
NULL };

printk("We r in init_function\n");


ret= call_usermodehelper(name, argv, envp, 1);
if ( ret <>
#include
int main(int argc,char *argv[],char *envp[])
{
int i=0,fd;

fd=open("/dev/ttyMCS",O_WRONLY);
if( fd <>

No comments:

Post a Comment