0

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.

Tr4mper
  • 1
  • 1
  • Welcome to Stack Overflow! "This does not work for me" is not a description of the problem, with which we could help you. "which I believe might be because of race conditions, since the `callback_function` is called frequently" - It could be many other reasons why your code doesn't work. If you suspect the messages to be arrived too often, then modify user-space application to send them less often and verify that kernel code works in that case. "Is there another way to receive an answer without using another callback function" - No, receiving a message is purely asynchronous event. – Tsyvarev Apr 03 '20 at 16:18
  • Thank you for your comment! Yeah, I have tried many different things regarding that problem, but since I did not make any progress, I was just looking for a completely different method. Not a fix for the wait_queue stuff. I will try to make my question more precise the next time. Thank you! – Tr4mper Apr 03 '20 at 16:35
  • You may [edit] the question. Please, do that and update description of your problem so it can be answered. "I was just looking for a completely different method." - There are plenty other methods for interact kernel a user. Enumerating all of them would be **too broad** for stack overflow. – Tsyvarev Apr 03 '20 at 17:22

0 Answers0