I am currently writing a Linux kernel module, where I have to send requests to a user-space application out of a callback function.
So what I need in my module is something like this:
int callback_function () {
...
send_request_to_app();
receive_answer();
...
}
I tried using generic netlink combined with wait_queues somewhat like this:
int response = 0;
DECLARE_WAIT_QUEUE_HEAD(wait_queue);
static int nl_recv_msg(struct sk_buff *skb, struct genl_info* info) {
...
response = 1;
wake_up_interruptible(&wait_queue);
...
}
int callback_function () {
...
send_request_to_app();
wait_event_interruptible(wait_queue, response);
...
}
Similar to this question: How to send and receive messages from function other than registered callback function in Netlink socket?
This does not work for me, which I believe might be because of race conditions, since the callback_function is called frequently.
Is there another way to receive an answer without using another callback function or is there a different IPC method that solves this problem?
Edit: I am not trying to fix the code above. I am just looking for other methods/ideas.