emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

file-notify-add-watch errors for UNIX sockets on macOS/BSD


From: Troy de Freitas
Subject: file-notify-add-watch errors for UNIX sockets on macOS/BSD
Date: Tue, 11 Jan 2022 11:19:09 -0600
User-agent: Cyrus-JMAP/3.5.0-alpha0-4569-g891f756243-fm-20220111.001-g891f7562

Hi,

I'm running into an issue on MacOS with `file-notify-add-watch'. From
the looks of it, it seems like it would affect other BSD systems as
well.

I'd like to be able to watch for when a UNIX socket file is
deleted. On Linux, it's possible to listen for when a UNIX socket is
deleted using `file-notify-add-watch'. However, on Mac, I get a
"Operation not supported on socket" error. To reproduce, using
emacs-Q, run the following elisp:

    (let* ((sock "/tmp/netproc.sock")
               (p (make-network-process
                   :name "test"
                   :family 'local
                   :local sock
                   :server t)))
          (unwind-protect
              (file-notify-add-watch sock '(change)
                                     (lambda (_) (message (format "%s changed." 
sock))))
            (delete-process p)
            (delete-file sock)))


It throws the error:

   edebug-signal: File cannot be opened: Operation not supported on
   socket, /tmp/netproc.sock

The issue appears to be in the underlying call to `kqueue-add-watch',
which uses `openat()' (by way of `emacs_open()`) to get a
file-descriptor. According to the BSD docs for `openat()', calling
`openat()' on socket files is not supported. But kqueue supports
watching sockets. So the issue is somehow getting a file descriptor to
the socket that doesn't  involve using `open()' or `openat()'.

Now, my C isn't very good (I've never written any C professionally),
but from my reading of the source for `kqueue-add-watch', it should be
possible to detect that the file is a socket on MacOS, and then
dispatch to `scoket()' and `connect()' instead, no? Or is there a
better approach?


- ntdef

PS: posting again since I changed my email associated with the mailing list.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]