public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* cann't dump info to user file from kernel
@ 2007-10-02  7:28 kernel coder
  2007-10-02  7:38 ` Denis V. Lunev
  0 siblings, 1 reply; 2+ messages in thread
From: kernel coder @ 2007-10-02  7:28 UTC (permalink / raw)
  To: linux-kernel

hi,
          I'm trying to dump some information from dev.c to user space
file.Following is the code which i'm using to write to user spcae
file.I'm using 2.6.22.x86_64 kernel.


#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
#define WRITABLE(f) (f->f_op && f->f_op->write)

int write_to_file(char *logfile, char *buf,int size)
{
        int ret = 0;
        struct file *f=NULL;
        mm_segment_t old_fs = get_fs();
        set_fs(get_ds());
         f = filp_open(logfile, O_CREAT|O_APPEND,00600);
        if(IS_ERR(f)){
                DPRINT("Error %ld openeing %s\n",-PTR_ERR(f), logfile);
                ret = -1;
        } else {
                if (WRITABLE(f))
                        _write(f, buf, size);
                else {
                        DPRINT("%s does not have a write method\n",
                                logfile);
                        ret = -1;
                }

                if ((ret = filp_close(f,NULL)))
                        DPRINT("Error %d closing %s\n", -ret, logfile);
        }
        END_KMEM;

        return ret;
}


I'm calling this function from netif_recieve_skb in dev.c

int netif_recieve_skb(struct sk_buff *skb){

---------------------
write_to_file("/root/kernel_log","hello_world",12);
----------------------

}

But whenever this function is called ,the kernel simply halts.Please
tell me what might be the reason.

I just want to dump some information to user spcace file from dev.c
.Is there some better way to do it.


thanks,
shahzad

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: cann't dump info to user file from kernel
  2007-10-02  7:28 cann't dump info to user file from kernel kernel coder
@ 2007-10-02  7:38 ` Denis V. Lunev
  0 siblings, 0 replies; 2+ messages in thread
From: Denis V. Lunev @ 2007-10-02  7:38 UTC (permalink / raw)
  To: kernel coder; +Cc: linux-kernel

This will never work, as you call blocking (non-atomic) functions from
atomic context.

kernel coder wrote:
> hi,
>           I'm trying to dump some information from dev.c to user space
> file.Following is the code which i'm using to write to user spcae
> file.I'm using 2.6.22.x86_64 kernel.
> 
> 
> #define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
> #define WRITABLE(f) (f->f_op && f->f_op->write)
> 
> int write_to_file(char *logfile, char *buf,int size)
> {
>         int ret = 0;
>         struct file *f=NULL;
>         mm_segment_t old_fs = get_fs();
>         set_fs(get_ds());
>          f = filp_open(logfile, O_CREAT|O_APPEND,00600);
>         if(IS_ERR(f)){
>                 DPRINT("Error %ld openeing %s\n",-PTR_ERR(f), logfile);
>                 ret = -1;
>         } else {
>                 if (WRITABLE(f))
>                         _write(f, buf, size);
>                 else {
>                         DPRINT("%s does not have a write method\n",
>                                 logfile);
>                         ret = -1;
>                 }
> 
>                 if ((ret = filp_close(f,NULL)))
>                         DPRINT("Error %d closing %s\n", -ret, logfile);
>         }
>         END_KMEM;
> 
>         return ret;
> }
> 
> 
> I'm calling this function from netif_recieve_skb in dev.c
> 
> int netif_recieve_skb(struct sk_buff *skb){
> 
> ---------------------
> write_to_file("/root/kernel_log","hello_world",12);
> ----------------------
> 
> }
> 
> But whenever this function is called ,the kernel simply halts.Please
> tell me what might be the reason.
> 
> I just want to dump some information to user spcace file from dev.c
> .Is there some better way to do it.
use something like ipt_LOG or packet sockets

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-10-02  7:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-02  7:28 cann't dump info to user file from kernel kernel coder
2007-10-02  7:38 ` Denis V. Lunev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox