Hello Santosh and Anand,
Thanks for the reply and very good suggestions.
As Anand Moon suggestedhttp://people.ee.ethz.ch/%7Earkeller/linux/multi/kernel_user_space_howto-3.html
link in http://lists.kernelnewbies.org/pipermail/kernelnewbies/2012-November/006489.html previous thread,
I read all the kernel to user space communication mechanism ( Except Upcall , ll read it). As of now for my application,
the signals passing from kernel to user space is enough. I was trying the sample code provided in signals section of above link.
1. In the code he used find_task_by_pid_type, but find_task_by_pid_type not available in sched.h. So I have changed it to
find_task_by_vpid(pid), is this right way ?
2. I tried to install the module but it is not finding the symbol, but the symbol is present in /proc/kallsyms.
Anything I am missing while compiling ? as I am getting warning.
Compile:jeshwanth@jeshwanth:~/linux/kernel_user_space/code/signals$ make
make -C /lib/modules/3.0.0-26-generic-pae/build M=/home/jeshwanth/linux/kernel_user_space/code/signals modules
make[1]: Entering directory `/usr/src/linux-headers-3.0.0-26-generic-pae'
Building modules, stage 2.
MODPOST 1 modules
WARNING: "find_task_by_vpid" [/home/jeshwanth/linux/kernel_user_space/code/signals/signal_kernel.ko] undefined!
make[1]: Leaving directory `/usr/src/linux-headers-3.0.0-26-generic-pae'
[1]+ Done gedit signal_kernel.c
install Command:root@jeshwanth:/home/jeshwanth/linux/kernel_user_space/code/signals# insmod signal_kernel.ko
insmod: error inserting 'signal_kernel.ko': -1 Unknown symbol in module
/proc/kallsyms:
00000000 T find_task_by_pid_ns
00000000 T find_task_by_vpid
dmesg:[15012.556740] signal_kernel: Unknown symbol find_task_by_vpid (err 0)
Code:#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <asm/siginfo.h> //siginfo
#include <linux/rcupdate.h> //rcu_read_lock
#include <linux/sched.h> //find_task_by_pid_type
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#define SIG_TEST 44 // we choose 44 as our signal number (real-time signals are in the range of 33 to 64)
struct dentry *file;
static ssize_t write_pid(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
char mybuf[10];
int pid = 0;
int ret;
struct siginfo info;
struct task_struct *t;
/* read the value from user space */
if(count > 10)
return -EINVAL;
copy_from_user(mybuf, buf, count);
sscanf(mybuf, "%d", &pid);
printk("pid = %d\n", pid);
/* send the signal */
memset(&info, 0, sizeof(struct siginfo));
info.si_signo = SIG_TEST;
info.si_code = SI_QUEUE; // this is bit of a trickery: SI_QUEUE is normally used by sigqueue from user space,
// and kernel space should use SI_KERNEL. But if SI_KERNEL is used the real_time data
// is not delivered to the user space signal handler function.
info.si_int = 1234; //real time signals may have 32 bits of data.
rcu_read_lock();
//t = find_task_by_pid_type(PIDTYPE_PID, pid); //find the task_struct associated with this pid
t = find_task_by_vpid(pid);
if(t == NULL){
printk("no such pid\n");
rcu_read_unlock();
return -ENODEV;
}
rcu_read_unlock();
ret = send_sig_info(SIG_TEST, &info, t); //send the signal
if (ret < 0) {
printk("error sending signal\n");
return ret;
}
return count;
}
static const struct file_operations my_fops = {
.write = write_pid,
};
static int __init signalexample_module_init(void)
{
/* we need to know the pid of the user space process
* -> we use debugfs for this. As soon as a pid is written to
* this file, a signal is sent to that pid
*/
/* only root can write to this file (no read) */
file = debugfs_create_file("signalconfpid", 0200, NULL, NULL, &my_fops);
return 0;
}
static void __exit signalexample_module_exit(void)
{
debugfs_remove(file);
}
module_init(signalexample_module_init);
module_exit(signalexample_module_exit);
MODULE_LICENSE("GPL");
On Thu, Nov 8, 2012 at 11:33 AM, SaNtosh kuLkarni
<santosh.yesoptus@gmail.com> wrote:
I think you are looking for Upcall Functionality
upcall functionality allows a kernel module to invoke a function in user space. It is possible to start a program in user space, and give it some command line arguments, as well as setting environment variables.
**
int call_usermodehelper (char * path, char ** argv, char ** envp, int wait);
Runs a user-space application. The application is started asynchronously if wait is not set, and runs as a child of keventd. (ie. it runs with full root capabilities).
Must be called from process context. Returns a negative error code if program was not execed successfully, or 0.
**man pages
Regards
Santosh
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
--
Regards
Jeshwanth Kumar N K
+91-7411483498