* file-notify-add-watch errors for UNIX sockets on macOS/BSD
@ 2022-01-11 16:51 Troy de Freitas
0 siblings, 0 replies; 2+ messages in thread
From: Troy de Freitas @ 2022-01-11 16:51 UTC (permalink / raw)
To: emacs-devel
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 professionaly),
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* file-notify-add-watch errors for UNIX sockets on macOS/BSD
@ 2022-01-11 17:19 Troy de Freitas
0 siblings, 0 replies; 2+ messages in thread
From: Troy de Freitas @ 2022-01-11 17:19 UTC (permalink / raw)
To: emacs-devel
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-11 17:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-11 17:19 file-notify-add-watch errors for UNIX sockets on macOS/BSD Troy de Freitas
-- strict thread matches above, loose matches on Subject: below --
2022-01-11 16:51 Troy de Freitas
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).