0

I want to establish connection between kernel module and user application with the kernel as a client. In other words, kernel will send message to the user app, wait for reply, receive reply, and then continue execution.

For example, inside kernel I will send message and then wait for reply.

// inside kernel
nlmsg_unicast();

wait_until_user_reply();

/* process reply */
/* continue execution.. */

while inside user,

while (1) {
   // inside user
   recvmsg();

   /* assembly reply.. */

   sendmsg();
}

however, what netlink protocol does is invoking a callback function every time user sends message. What I want is to make kernel wait for a reply from user, then continue the execution. Is waiting in a busy loop on a global variable which is updated inside callback function feasible? I tried but I think that's not a very good solution.

Can I do something like "sleep until a reply come". Can I put the kernel to sleep?

Isa A
  • 1,342
  • 13
  • 31

1 Answers1

1

I have resolved this problem using wait_for_completion. It turns out that it wasn't that hard.

Isa A
  • 1,342
  • 13
  • 31
  • Ah great, someone has similiar issues. Could you share the code? – user1252280 Oct 06 '14 at 20:36
  • @user1252280 Unfortunately I can't share the code.. You can look in the documentation of wait_for_completion(). Basically, you just have to do init_completion() once, send the message, and then do wait_for_completion() or wait_for_completion_timeout() in the kernel. That's all. – Isa A Oct 09 '14 at 04:36
  • can we have a clearer answer? I tried what I understood from that message however, it causes a General Protection Fault – Wheatley Mar 16 '16 at 00:36