Search code examples
filesocketsipcbindshutdown

Delete AF_UNIX file automatically?


Is there a way to delete the file created by AF_UNIX bind() operation automatically if the process crashes?


Solution

  • No, there is not.

    You can however remove it when you start up, before you (re)create the socket.

    On e.g. linux you can avoid creating an entry in the file system by having the sun_path start with a 0 byte - this creates an "abstract" socket that isn't visible in the filsystem - see the mentioned man page for more info, and thus vanishes when the process exits. It's not entierly clear to me whether that is a standard feature or if it is linux specific.