Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

call insmod in C program

668 views
Skip to first unread message

mbm

unread,
Apr 25, 2008, 10:00:29 AM4/25/08
to
Hi

I need to insert kernel modules from a C application , is it possible
to do that without calling system("insmod ..")

Any comment is welcome

Josef Moellers

unread,
Apr 25, 2008, 10:11:38 AM4/25/08
to
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.

--
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

Message has been deleted

kartik saxena

unread,
Apr 25, 2008, 5:01:36 PM4/25/08
to
Hi,

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


Tilman Schmidt

unread,
Apr 26, 2008, 8:59:27 AM4/26/08
to
kartik saxena schrieb:
>> mbm wrote:

>>> 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.

Tilman Schmidt

unread,
Apr 26, 2008, 9:12:00 AM4/26/08
to
mbm schrieb:

> I need to insert kernel modules from a C application , is it possible
> to do that without calling system("insmod ..")

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.

Josef Moellers

unread,
Apr 28, 2008, 3:16:35 AM4/28/08
to

IIRC modprobe calls insmod after having resolved dependencies.

Tilman Schmidt

unread,
Apr 28, 2008, 7:58:57 PM4/28/08
to
Josef Moellers schrieb:

> 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.

0 new messages