From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Troy de Freitas" Newsgroups: gmane.emacs.devel Subject: file-notify-add-watch errors for UNIX sockets on macOS/BSD Date: Tue, 11 Jan 2022 11:19:09 -0600 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11106"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.5.0-alpha0-4569-g891f756243-fm-20220111.001-g891f7562 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jan 11 18:29:54 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n7Ky2-0002fy-Mv for ged-emacs-devel@m.gmane-mx.org; Tue, 11 Jan 2022 18:29:54 +0100 Original-Received: from localhost ([::1]:43374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7Ky1-0004Kn-OT for ged-emacs-devel@m.gmane-mx.org; Tue, 11 Jan 2022 12:29:53 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:37822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Knz-0006ar-RX for emacs-devel@gnu.org; Tue, 11 Jan 2022 12:19:32 -0500 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:51915) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kny-00006N-9h for emacs-devel@gnu.org; Tue, 11 Jan 2022 12:19:31 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id A677A5C01C6 for ; Tue, 11 Jan 2022 12:19:29 -0500 (EST) Original-Received: from imap42 ([10.202.2.92]) by compute1.internal (MEProxy); Tue, 11 Jan 2022 12:19:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntdef.com; h= mime-version:message-id:date:from:to:subject:content-type; s= mesmtp; bh=nHIstvBW08xocrQEfZxy4DiXCV0mxWvEew9+O5njT5E=; b=kG5da 6xKiM7WPDDWq3EdCUm39c03hYH0QHku+e7vUTQIAz3VSKloPnw69HinBwiMVPh/H HRyhnB6mBfEu848W6BBnsdxXyhv66HHaS8oEj5gt/jk6HPiEm+fxytRL9nH2pSSN GAPAfrpAEZnOXXYNCRA5kpC2MXo4t6pjCQMihg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=nHIstvBW08xocrQEfZxy4DiXCV0mx WvEew9+O5njT5E=; b=GZK4BsK+cO+315/SWwOTIGOpu068YpwRLrPdEvtbNDo8a uuQAZegzr43ZrLwc0fec7DG/QlWH+Rw7rT48hl3S0h9JfCDDPOMU7DdReJ/9G1tW 3ceduUhaHKe93VYPyvkrFUThSuD/95EfNIPYe6GVpd2FjGcwpaq7C1eyuS92WInt oKFNq5hmVeZ48PbKz7KXXuYwP/GyxRAzR6Vlf/iEOi3LDkOR027xcRNMTQPhS4Hr gNs7guta1l3Yvht0yK2qEVUopnfFLQ9cuVA3b6JFyeyru+UFvZuYCv0hmPiIq0Z+ 3eB1j6/T3bTxfMP/m/CJJCHOIjbUJyc3DuEc0t1Fw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrudehfedguddttdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkfffhvffutgesthdtre dtreertdenucfhrhhomhepfdfvrhhohicuuggvucfhrhgvihhtrghsfdcuoehmvgesnhht uggvfhdrtghomheqnecuggftrfgrthhtvghrnhepfeefleekteeiheelueetvddvffffhf egveevjedtvdeuheelteduudeuhfetueegnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomhepmhgvsehnthguvghfrdgtohhm X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 6EADE2180078; Tue, 11 Jan 2022 12:19:29 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Received-SPF: pass client-ip=66.111.4.28; envelope-from=me@ntdef.com; helo=out4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:284619 Archived-At: 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.