Subject: bug#53191: 29.0.50; file-notify-add-watch fails for socket files on MacOS

From: Michael Albinus <[email-masked]>
Date: Wed, 12 Jan 2022 10:01:55 +0100

"Troy de Freitas" <[email-masked]> writes:

Hi Troy,

> This bug affects MacOS (and most likely FreeBSD and OpenBSD as well).
> On MacOS running `file-notify-add-watch' throws an error when attached to a UNIX socket
> file but works fine on Linux. To reproduce, using 'emacs -Q', evaluate 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.

Thanks for the report. The incrimed behavior is due to unconditional
using of the EVFILT_VNODE filter, calling EV_SET in
Fkqueue_add_watch. This requires a file descriptor.

I'll investigate, whether another filter, like EVFILT_READ, is better
suited for sockets, using a sockfd. This might take some days, though.

See kqueue(2) for details, if you're interested in.

> - Troy

Best regards, Michael.