Maybe it's an odd question:
I'm making some test on module programming to accomplish a simple purpose which
is based on the elementary structure of a module (such as _init, _fini ,
_info......).And the purpose is:
TO EXECUTE AN EXTERNAL COMMAND WHEN THE MODULE IS LOADED
This is my code:
-----------------------------mod3.c----------------------------------------------
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/modctl.h>
#include <sys/cmn_err.h>
#include <sys/exec.h>
extern struct mod_ops mod_miscops;
static struct modlmisc modlmisc = {
&mod_miscops,
"Real Loadable Kernel Module",
};
static struct modlinkage modlinkage = {
MODREV_1,
(void *)&modlmisc,
NULL
};
int _init(void)
{
int i,j;
char arg0[] = "ls ";
char arg1[] = "-l ";
char arg2[] = "/ ";
char arg3[] = ">> ";
char arg4[] = "/tmp/abc.txt";
char arg5[] = "\0";
const char *argp[6] = {arg0,arg1,arg2,arg3,arg4,arg5};
if ((i=mod_install(&modlinkage))!=0)
cmn_err(CE_NOTE,"Could not install module\n");
else
cmn_err(CE_NOTE,"mod: successfully installed");
exec_common("/bin/ls",argp,NULL);
return i;
}
int _info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
int _fini(void)
{
int i;
if ((i= mod_remove(&modlinkage))!=0)
cmn_err(CE_NOTE,"Could not remove module\n");
else
cmn_err(CE_NOTE,"mod: successfully removed");
return i;
}
--------------------------------end-----------------------------------
And then I compile it and load it:
# gcc -c -D_KERNEL -D_SYSCALL32 -D_SYSCAL32_IMPL mod3.c
# ld -r -o mod3 mod3.o
# modload mod3
# modinfo |grep mod3
155 f9d2fd3c 210 - l mod3 (Real Loadable Kernel Module)
And the console show:
NOTICE! mod: successfully installed
You can see everything is all right. But the file "abc.txt" didn't appear in
the /tmp.
You also can see I use the exec_common which is defined in <sys/exec.h> but not
execl in <unistd.h> because if i choose the latter one, the system cannot
modload the mod3 with an alert "unidentified symbols"
I'm wandering:
1.The function exec_common cannot be called in such a way?
2.The kernel doesn't allow the kernel space to execute an external function
when module loaded?
3.If I stick to accomplishing my purpose,how?
--
This message posted from opensolaris.org
_______________________________________________
opensolaris-discuss mailing list
[email protected]