Why are UNIX domain sockets not automatically deleted when they are no longer referenced?

When a process binds a TCP socket name (for example, ip: port pair) and exits, it does not need to clear anything explicitly: another process can reuse the same ip: port. Same thing with abstract UNIX sockets on Linux (when sun_pathstarting with a zero byte). However, when using traditional UNIX sockets, you need unlinkit after it is no longer needed (or before bind-ing, which is not very good, since you can remove something important).

According to my observations, when the last file descriptor that refers to a UNIX socket is closed, the socket file is useless garbage: openreturns ENODEV, connectreturns ECONNREFUSED, and bindreturns EADDRINUSE. The only thing that can (and should) be done is unlink.

Should I automatically delete the socket file from the file system when it is no longer in use?

+4
source share

Source: https://habr.com/ru/post/1674860/


All Articles