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?
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
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
You should really reconsider whether you want to do this at all.
Really.
Bad Idea - heh.
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?
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
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