Re: Accessing a user space variable from a kernel module

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

 



Hi all,
        I read thread on kernelnewbies that string can
be accessed in kernel from user space. So i try to do
it. I write simple user space program that receives
input string from user.  I wan to know how then i can
write a kernel module that will receive that string
given by user.
My user program.

#include <stdio.h>
 main()
{

char string_to_kernel[25];

printf("Enter string to be send to kernel= ");
scanf("%s",string_to_kernel);
printf("string sent to kenrel
is=%s\n",string_to_kernel);

}


My kernel module
#include <linux/init.h>
#include <linux/module.h>
#include <asm/uaccess.h>

static int hello_init(void)
{
char *str_from_user;
//What changes do i have to do here
copy_from_user(str_from_user, source,strlen(source) );
        printk(KERN_INFO "String from
user=%s\n",str_from_user);
              
        return 0;
}

static void hello_exit(void)
{
        printk(KERN_INFO "Goodbye\n");
}

module_init(hello_init);
module_exit(hello_exit);

please correct me.
regards,
cranium.





		
__________________________________ 
Do you Yahoo!? 
Make Yahoo! your home page 
http://www.yahoo.com/r/hs

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