i want to call open,write system calls from kernel space.

what i want to do actually is to wrap up open system call.I have done wrap
up part of open system call using jprobes.

Now i want to write name of file being opened in another file say
"/home/rahul/log" and code for it will be written in wrap-up part
since the wrap-up part of open system call also runs in kernel space i want
to open and write file "/home/rahul/log" from kernel
space.

so the code in my wrap up routine in jprobe module will look like.

long my_sys_open(char*name,int flag,int mode)
{
int fd;

 fs = get_fs();     /* save previous value */
set_fs (get_ds()); /* use kernel limit */
fd=sys_open("/home/rahul/log",O_CREAT,O_RDRW);
 set_fs(fs);

fs = get_fs();     /* save previous value */
set_fs (get_ds()); /* use kernel limit */
fwrite(fd,name,strlen(name));
set_fs(fs);

  jprobe_return();
        return 0;

}

I will take care that recursion will not happen since i am calling sys_open
from wrapper of sys_open


On Wed, Apr 28, 2010 at 8:10 AM, Joel Fernandes <agnel.j...@gmail.com>wrote:

> On Wed, Apr 28, 2010 at 8:09 AM, Joel Fernandes <agnel.j...@gmail.com>wrote:
>
>>
>> On Tue, Apr 27, 2010 at 7:55 AM, rahul patil <
>> rahul.deshmukhpa...@gmail.com> wrote:
>>
>>> Though it is bad idea to call a system call from kernel space
>>> is it possible any how to call a system call from kernel space?
>>>
>>
>> Generally a better idea to user kernel interfaces directly instead of sys
>> calls. Further most sys call functions are not exported so you can't call
>> them from your kernel module. You'll have to EXPORT_SYMBOL them and
>> recompile your kernel which is kind of ugly.
>>
>
>
> If you can tell us which syscalls you'd like to make, maybe we can suggest
> some alternatives
>
> -Joel
>
>


-- 
Regards,
Rahul Patil

Reply via email to