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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Ah great, someone has similiar issues. Could you share the code?
@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.
can we have a clearer answer? I tried what I understood from that message however, it causes a General Protection Fault

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.