unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Troy de Freitas" <me@ntdef.com>
To: emacs-devel@gnu.org
Subject: file-notify-add-watch errors for UNIX sockets on macOS/BSD
Date: Tue, 11 Jan 2022 10:51:04 -0600	[thread overview]
Message-ID: <12b3d3b9-8299-482d-8d18-2111ab086b36@www.fastmail.com> (raw)

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



             reply	other threads:[~2022-01-11 16:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11 16:51 Troy de Freitas [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-01-11 17:19 file-notify-add-watch errors for UNIX sockets on macOS/BSD Troy de Freitas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12b3d3b9-8299-482d-8d18-2111ab086b36@www.fastmail.com \
    --to=me@ntdef.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).