execute a shell command from kernel

Submitted by maat
on December 18, 2005 - 1:24am

hi,
i am trying to run a shell command from kernel with the function do_execve, but i get always the error "no a file or directory". follow is the code.
############# code #####################
char *cmd[]={//set the command to be use
/*"sh",*/
"-c",
"ls /",
NULL
};

char *env[]={ //set the environment
"HOME=/",
"PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/sawacom/bin",
"SHELL=/bin/bash",
"TERM=xterm",
NULL
};

struct pt_regs *regs;

int a= do_execve("sh", cmd, env, regs); //execute the shell command

printk("<1>##### a=%d #####\n",a);
################# end code ########################
perhaps someone can tell me what i am doing wrong.

thanks

tried with full path?

strcmp
on
December 18, 2005 - 3:06am

Like execve() in user space do_execve() may want the absolute path of the file to execute (execlp is not a syscall..). In your case "/bin/sh" instead of "sh". In fact, what the error "no a file or directory" says is exactly "you passed the wrong file name"...

You really shouldn't want to

Ano Nymous
on
December 18, 2005 - 4:05am

You really shouldn't want to do things like this in the kernel. Why not use uevent or generate a hotplug event and start the script with a udev rule, or something similar?

What problem are you trying to solve and what is your goal?

You should really reconsider

Anonymous (not verified)
on
December 18, 2005 - 8:17am

You should really reconsider whether you want to do this at all.

Really.

Bad Idea - heh.

Anonymouse (not verified)
on
December 18, 2005 - 4:32pm

Greg K-H did a small article to Linux Journal this year about similar types of perverted behavior.

See his on-line version: http://www.linuxjournal.com/article/8110

Why?

jakemathai
on
December 18, 2005 - 9:17pm

Jacob Mathai

I would question the logic here as well. I am curious what functionality were you hoping to achieve or put another way, what problem are you hoping to solve ? :)

execute a shell command from kernel

maat
on
January 3, 2006 - 5:01pm

i want to create a file. My goal is to write a reset interrupt handler for a router. My handler has to reboot the system and load it with default value if the user has pressed the reset-button more than 3 second. and to know at load time if the user has pressed the button more than 3 second i have to creat a file befor i reboot the system.
sorry for the time i have done befor i reply

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.