I need to insert kernel modules from a C application , is it possible
to do that without calling system("insmod ..")
Any comment is welcome
Definitely. All you need to do is to take the insmod source code and
copy it into your application.
Simple as that. Open Source.
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
On Apr 25, 7:11 pm, Josef Moellers <josef.moell...@fujitsu-
siemens.com> wrote:
> mbm wrote:
> > Hi
>
> > I need to insert kernel modules from a C application , is it possible
> > to do that without calling system("insmod ..")
>
> Definitely. All you need to do is to take the insmod source code and
> copy it into your application.
> Simple as that. Open Source.
>
Just compile your module at a source directory , and run the following
after compiling the following with gcc.
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
setuid(0);
system("/sbin/insmod /.../sourcedirectory/yourmodule.ko");
system("/sbin/rmmod yourmodule.ko");
return 0;
}
Thanks
Kartik
>>> I need to insert kernel modules from a C application , is it possible
>>> to do that without calling system("insmod ..")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Hi, here goes the program.
>
> #include <sys/types.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
>
> int main()
> {
> setuid(0);
> system("/sbin/insmod /.../yourmodule.ko");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hmmm.
You need the init_module() system call. See "man 2 init_module" for
details, and modprobe.c in module-init-tools for a working example.
HTH
T.
IIRC modprobe calls insmod after having resolved dependencies.
Not the version that can be found in module-init-tools-3.3-pre1.tar.bz2
(the latest on www.kernel.org) anyway. Perhaps some older version?
HTH
T.