Re: File opening by Kernel threads

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




The problem over is not of kernel thread but of sys_open. The string that
u pass to sys_open should be from userspace and not from the kernel space.
When you use sys_open, there is check in the kernel to see whenther the
address of the string is a userspace address or not.

 HTH,
Raghu


On Sat, 12 Jul 2003, kernel rakshakudu wrote:

> Hi,
> I am writing a kernel thread which opens a file and
> writes into it everytime in a continous loop. The
> Kernel thread is started by a system call.
>
> The problem is the file openning by Kernel thread
> fails and sys_open() returns -14 (EFAULT). Can any
> body help me in this ??? Also if you know any url
> where there is good discussion or documentation of
> kernel threads, keventd , let me know.
>
> source is as follows:
>
> static void example_thread()
> {
>
>
>  int i,error,fd,num;
>  char c;
>  daemonize();
>  strcpy(current->comm,"examplethread");
>  printk("This is test log message by
> example_thread\n");
>
>    for(;;)
>    {
>
>    fd=sys_open("/tmp/examplethread",O_CREAT |
> O_WRONLY,S_IRWXU);
>    printk("Fd of the file:%d\n",fd);
>    if (fd>=0)
>    {
>
>       num=sys_write(fd,"This is test log",100);
>
>    }
>    else
>    {
>    printk("/tmp/examplethread failed to open\n");
>    goto out;
>
>    }
>
>    sys_close(fd);
>    current->state = TASK_INTERRUPTIBLE;
>    schedule();
>    }
>    printk("The second message is read from log
> buffer\n");
>
>    out:
>    printk("example_thread exiting\n");
> }
>
>
> asmlinkage int sys_startkthread( )
> {
>    pid_t pid;
>    pid = kernel_thread(example_thread,NULL,CLONE_FS |
> CLONE_FILES | CLONE_SIGNAL);
>    if (pid < 0)
>     return -1;
>    return pid;
>
> }
>
>
> thanks in advance,
> KR
>
> =====
>
> "Conquering Myselves to Conquer The World"
>
> "Securing Kernel to Secure Whole System"
>
>
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux