LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   close socket + kernel module (https://www.linuxquestions.org/questions/linux-kernel-70/close-socket-kernel-module-680901/)

ibaniski 11-03-2008 03:54 PM

close socket + kernel module
 
Hello,

I am working with/writing a kernel module which communicates with user processes using a custom socket family.

One of the features that I need in this module is "force shutdown", which will close the sockets and somehow notify the user process(es) that the communication has been broken.

I attempted to do the following in the module "shutdown" code:
PHP Code:

sock_orphan(sk);
sock_put(p->sock->sk);
sk NULL

for each open socket. However, the user process is not notified of this, and continues to listen on the socket; and when I try to terminate the process it attempts to close the socket (even though it has been closed in the kernel) and faults.

Any ides on how to properly close a socket from inside a kernel module? Perhaps I need to do something specific in sk_destruct?

Thanks,
ib

sundialsvcs 11-10-2008 09:17 AM

If the user opens a socket, then the user (or user-side process cleanup code) must close it.

When you determine that the communications represented by some particular socket are no longer possible, then you should signal the user-process (in some agreed-upon way), and also set a flag in your own internal data-structures to reflect the fact that this communication channel is now "dead."

If the user ignores the notification and attempts to communicate with a dead channel, the request is turned-away, returning an error indication to the user's socket-I/O request. If the user queries the status of the channel (in some way that you have provided), he will learn that it is "dead as a doornail."

Eventually, one way or the other, the user will close what he has opened. When he does so, the data-structures you have created must be expunged.

Mara 11-11-2008 02:45 PM

You must have some code that notifies the client when your socket becomes unusable (if it's connection-oriented, when the connection is broken; when the interface goes down etc). Copy that code. Don't deallocate socket structures - it's needed for the client to read()/write() and get an error and/or close() properly.


All times are GMT -5. The time now is 03:26 AM.