How to use kevent to monitor removal of a socket-file

Tobias C. Berner tcberner at freebsd.org
Wed Jul 5 13:58:48 UTC 2017


Hi there


I want to be notified once a given socket file, say '/var/run/socket.pipe'
gets deleted.


Something like

+---------------------------------------------+
|   string path = "/var/run/socket.pipe";     |
|   int fd = open(path, O_RDONLY);            |
|   EV_SET(&k, fd, ...);                      |
|   kevent(..., &k, ...);                     |
+---------------------------------------------+

however does not work, as open(2) does not handle socket files, throwing
back
    ENOTSUPP : An attempt was made to open a socket (not currently
implemented).


What is the proper way to monitor such files?
* Just monitoring the parent directory for changes, and look up whether the
file still exists each time?
* Connecting to the socket and using EVFILT_READ and wait for EOF?


Am I missing the obvious solution here?



mfg Tobias


More information about the freebsd-hackers mailing list