views:

211

answers:

1

Where in the linux kernel does the closing of a socket's file descriptor occur? I know for a file, the file's file descriptor is closed in fs/open.cs function sys_close(). However, for a socket file descriptor, is this the same location or somewhere else?

Also, do sockets utilize the file.c alloc_fd to allocate the file descriptor or do they utilize some other function?

+2  A: 

Yes, sys_close() is the entry point for closing all file descriptors, including sockets.

sys_close() calls filp_close(), which calls fput() on the struct file object. When the last reference to the struct file has been put, fput() calls the file object's .release() method, which for sockets, is the sock_close() function in net/socket.c.

The socket code uses get_unused_fd() and put_unused_fd() to acquire and release file descriptors.

caf
And I see get_unused_fd calls alloc_fd so by changing my code as needed in sys_close and alloc_fd, this should handle all file descriptors for files and sockets, correct?
NTek
Maybe, it's hard to say without knowing what your code does.
caf