LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 11-03-2008, 03:54 PM   #1
ibaniski
LQ Newbie
 
Registered: Nov 2008
Posts: 10

Rep: Reputation: 0
Question 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

Last edited by ibaniski; 11-03-2008 at 04:05 PM.
 
Old 11-10-2008, 09:17 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,679
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
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.
 
Old 11-11-2008, 02:45 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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.
 
  


Reply

Tags
close, kernel, module, socket



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why can i not close socket with command /quit lrios Programming 11 05-08-2008 11:06 PM
Installing perl module IO::Socket::SSL [GOD]Anck Slackware 1 03-26-2008 07:07 AM
command to close tcp socket powah Linux - Networking 1 08-17-2007 12:22 PM
race condition in close socket?? jwstric2 Programming 3 03-18-2005 05:01 PM
Close socket/port THETEZ Linux - General 4 03-28-2004 08:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration