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

From: "Troy de Freitas" <[email-masked]>
Date: Tue, 11 Jan 2022 10:22:01 -0600

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.

In GNU Emacs 29.0.50 (build 1, aarch64-apple-darwin20.6.0, NS appkit-2022.60 Version 11.5.1 (Build 20G80))
 of 2021-10-26 built on C02FW2L5Q05P
Windowing system distributor 'Apple', version 10.3.2113
System Description:  macOS 12.1

Configured using:
 'configure --disable-dependency-tracking --disable-silent-rules
 --enable-locallisppath=/opt/homebrew/share/emacs/site-lisp
 --infodir=/opt/homebrew/Cellar/emacs-plus@29/29.0.50/share/info/emacs
 --prefix=/opt/homebrew/Cellar/emacs-plus@29/29.0.50 --with-xml2
 --with-gnutls --without-dbus --with-imagemagick --with-modules
 --with-rsvg --with-ns --disable-ns-self-contained'

Configured features:
ACL GIF GLIB GMP GNUTLS IMAGEMAGICK JPEG JSON LCMS2 LIBXML2 MODULES
NOTIFY KQUEUE NS PDUMPER PNG RSVG THREADS TIFF TOOLKIT_SCROLL_BARS WEBP
XIM ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8

Major mode: Elisp

Minor modes in effect:
  semantic-minor-modes-format: ((:eval (if (or semantic-highlight-edits-mode semantic-show-unmatched-syntax-mode)  S)))
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  shell-dirtrack-mode: t
  default-text-scale-mode: t
  recentf-mode: t
  vertico-mode: t
  winner-mode: t
  windmove-mode: t
  elisp-slime-nav-mode: t
  paredit-mode: t
  aggressive-indent-mode: t
  highlight-quoted-mode: t
  display-fill-column-indicator-mode: t
  rainbow-delimiters-mode: t
  symbol-overlay-mode: t
  bug-reference-prog-mode: t
  goto-address-prog-mode: t
  dimmer-mode: t
  global-anzu-mode: t
  anzu-mode: t
  flycheck-color-mode-line-mode: t
  global-flycheck-mode: t
  flycheck-mode: t
  diredfl-global-mode: t
  savehist-mode: t
  electric-pair-mode: t
  delete-selection-mode: t
  global-auto-revert-mode: t
  global-so-long-mode: t
  mode-line-bell-mode: t
  beacon-mode: t
  global-page-break-lines-mode: t
  page-break-lines-mode: t
  whole-line-or-region-global-mode: t
  whole-line-or-region-local-mode: t
  hes-mode: t
  which-key-mode: t
  global-whitespace-cleanup-mode: t
  whitespace-cleanup-mode: t
  global-diff-hl-mode: t
  projectile-mode: t
  ipretty-mode: t
  auto-compile-on-load-mode: t
  auto-compile-on-save-mode: t
  auto-compile-mode: t
  immortal-scratch-mode: t
  envrc-global-mode: t
  envrc-mode: t
  marginalia-mode: t
  repeat-mode: t
  desktop-save-mode: t
  corfu-global-mode: t
  corfu-mode: t
  ns-auto-titlebar-mode: t
  override-global-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Features:
(shadow emacsbug sendmail cal-move info-look proced move-dup eglot array
jsonrpc switch-window switch-window-mvborder switch-window-asciiart
quail man flymake-cc flymake-proc flymake macrostep-c cmacexp edebug
pandoc-mode-utils sort tablist tablist-filter semantic/wisent/comp
semantic/wisent semantic/wisent/wisent semantic/util-modes semantic/util
semantic semantic/tag semantic/lex semantic/fw mode-local cedet
calc-mode calc-yank calc-forms calc-arith calc-alg calc-comb calc-ext
calc-misc calc-menu calc calc-loaddefs calc-macs reposition thai-util
thai-word lao-util enriched facemenu json-mode json-snatcher slime-tests
ert slime-fancy slime-indentation slime-cl-indent cl-indent
slime-trace-dialog slime-fontifying-fu slime-package-fu slime-references
slime-compiler-notes-tree slime-scratch slime-presentations bridge
slime-macrostep macrostep slime-mdot-fu slime-enclosing-context
slime-fuzzy slime-fancy-trace slime-fancy-inspector slime-c-p-c
slime-editing-commands slime-autodoc slime-repl slime-parse
slime-company company slime arc-mode archive-mode hyperspec mail-extr
tabify em-unix em-term em-script em-prompt em-ls em-hist em-pred em-glob
em-cmpl em-dirs esh-var em-basic em-alias warnings quickrun em-banner
eshell esh-mode esh-cmd esh-ext esh-opt esh-proc esh-io esh-arg
esh-module esh-groups esh-util autoload mm-archive gnutls network-stream
url-http url-gw nsm url-cache url-auth vterm term ehelp vterm-module
term/xterm xterm macros rect loadhist docker-tramp tramp-cache tramp
tramp-loaddefs trampver tramp-integration files-x tramp-compat ls-lisp
completion dos-w32 find-cmd debug backtrace apropos find-dired scratch
sql vc-annotate vc-filewise ibuffer-vc gitignore-mode conf-mode cl-print
shortdoc rainbow-mode ibuffer-projectile sh-script smie embark ffap
misearch multi-isearch pulse scala-mode scala-mode-prettify-symbols
scala-mode-imenu scala-mode-map scala-mode-fontlock scala-mode-indent
scala-mode-paragraph scala-mode-syntax scala-mode-lib help-fns
radix-tree magit-patch magit-subtree magit-gitignore magit-ediff ediff
ediff-merg ediff-mult ediff-wind ediff-diff ediff-help ediff-init
ediff-util wucuo wucuo-sdk find-lisp flyspell ispell info-colors js
dired-aux diff-hl-dired magit-extras magit-bookmark magit-submodule
magit-obsolete magit-blame magit-stash magit-reflog magit-bisect
magit-push magit-pull magit-fetch magit-clone magit-remote magit-commit
magit-sequence magit-notes magit-worktree magit-tag magit-merge
magit-branch magit-reset magit-files magit-refs magit-status magit
magit-repos magit-apply magit-wip magit-log which-func magit-diff
smerge-mode diff git-commit log-edit add-log magit-core magit-autorevert
magit-margin magit-transient magit-process with-editor shell magit-mode
transient magit-git magit-section magit-utils crm markdown-mode
doom-one-theme doom-themes doom-themes-base consult-vertico consult
bookmark executable cus-edit cus-start cus-load default-text-scale
recentf tree-widget orderless vertico winner windswap windmove
add-node-modules-path typescript-mode cc-mode cc-fonts cc-guess cc-menus
cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs elisp-slime-nav
etags fileloop xref project view paredit aggressive-indent
highlight-quoted display-fill-column-indicator rainbow-delimiters
symbol-overlay vc-mtn vc-hg vc-bzr vc-src vc-sccs vc-svn vc-cvs vc-rcs
bug-reference goto-addr dimmer anzu flycheck-color-mode-line face-remap
flycheck-package package-lint let-alist imenu finder flycheck dash
disp-table vc-git org-element avl-tree generator ol-eww eww xdg
url-queue mm-url ol-rmail ol-mhe ol-irc ol-info ol-gnus nnselect
gnus-search eieio-opt speedbar ezimage dframe gnus-art mm-uu mml2015
mm-view mml-smime smime dig gnus-sum shr kinsoku svg dom gnus-group
gnus-undo gnus-start gnus-dbus dbus xml gnus-cloud nnimap nnmail
mail-source utf7 netrc nnoo parse-time gnus-spec gnus-int gnus-range
message rmc puny rfc822 mml mml-sec epa epg rfc6068 epg-config mm-decode
mm-bodies mm-encode mailabbrev gmm-utils mailheader gnus-win gnus
nnheader gnus-util rmail rmail-loaddefs mail-utils wid-edit ol-docview
doc-view image-mode exif dired-x diredfl dired dired-loaddefs ol-bibtex
ol-bbdb ol-w3m ol-doi org-link-doi org-clock org ob ob-tangle ob-ref
ob-lob ob-table ob-exp org-macro org-footnote org-src ob-comint
org-pcomplete pcomplete org-list org-faces org-entities noutline outline
org-version ob-emacs-lisp ob-core ob-eval org-table oc-basic bibtex
iso8601 time-date ol org-keys oc org-compat org-macs org-loaddefs
format-spec find-func cal-menu calendar cal-loaddefs savehist elec-pair
delsel autorevert filenotify so-long mode-line-bell beacon
page-break-lines whole-line-or-region highlight-escape-sequences
which-key diminish whitespace-cleanup-mode whitespace diff-hl log-view
pcvs-util vc-dir ewoc vc vc-dispatcher diff-mode projectile lisp-mnt
mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr grep
compile text-property-search comint ring ibuf-ext ibuffer
ibuffer-loaddefs thingatpt jka-compr ipretty advice auto-compile packed
immortal-scratch uptimes pp envrc inheritenv server init init-local
pcase marginalia init-locales session sanityinc-tomorrow-bright-theme
color-theme-sanityinc-tomorrow color init-direnv init-snippets
yasnippet-snippets yasnippet init-ledger init-dash init-folding
init-misc init-slime init-lisp init-paredit init-nix init-terraform
init-docker init-yaml init-toml init-sql init-python reformatter
ansi-color init-http init-haml init-css init-html init-nxml init-org
init-javascript init-erlang erlang-start init-csv init-markdown
init-textile init-crontab init-compile init-projectile init-github
init-git init-vc init-whitespace init-editing-utils repeat init-mmm
mmm-auto mmm-vars mmm-utils mmm-compat init-sessions desktop frameset
init-windows init-completion cape corfu init-embark init-minibuffer
init-recentf init-flycheck init-ibuffer ibuf-macs init-uniquify
init-grep init-isearch init-dired init-gui-frames ns-auto-titlebar
init-osx-keys edmacro kmacro init-themes init-xterm init-frame-hooks
init-exec-path exec-path-from-shell init-elpa fullframe
use-package-ensure-system-package system-packages use-package
use-package-delight use-package-diminish use-package-bind-key bind-key
easy-mmode cl-extra help-mode use-package-ensure use-package-core
finder-inf rx slime-autoloads info package browse-url url url-proxy
url-privacy url-expand url-methods url-history url-cookie url-domsuf
url-util mailcap url-handlers url-parse auth-source eieio eieio-core
cl-macs eieio-loaddefs password-cache json map url-vars seq gv subr-x
byte-opt bytecomp byte-compile cconv init-site-lisp cl-seq init-utils
init-benchmarking cl-loaddefs cl-lib derived early-init iso-transl
tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/ns-win ns-win ucs-normalize
mule-util term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads kqueue cocoa ns lcms2
multi-tty make-network-process emacs)

Memory information:
((conses 16 1524406 530432)
 (symbols 48 81700 151)
 (strings 32 312418 63333)
 (string-bytes 1 12192584)
 (vectors 16 133974)
 (vector-slots 8 2581686 711833)
 (floats 8 1701 7648)
 (intervals 56 36559 8126)
 (buffers 992 93))

- Troy
[email-masked]