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 10:51:04 -0600 Message-ID: <12b3d3b9-8299-482d-8d18-2111ab086b36@www.fastmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28367"; 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:56:17 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 1n7LNY-0007EX-H9 for ged-emacs-devel@m.gmane-mx.org; Tue, 11 Jan 2022 18:56:16 +0100 Original-Received: from localhost ([::1]:38236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7LNW-00070b-Ih for ged-emacs-devel@m.gmane-mx.org; Tue, 11 Jan 2022 12:56:14 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7KMy-0004iY-3K for emacs-devel@gnu.org; Tue, 11 Jan 2022 11:51:36 -0500 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:42027) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7KMo-0004G2-BO for emacs-devel@gnu.org; Tue, 11 Jan 2022 11:51:35 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id B84055C018A for ; Tue, 11 Jan 2022 11:51:24 -0500 (EST) Original-Received: from imap42 ([10.202.2.92]) by compute1.internal (MEProxy); Tue, 11 Jan 2022 11:51:24 -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=UxnCF7sUXxHZEATYthNznhvb+BaKR1eXbkRc1b1AFZw=; b=PQjhs vvtlv0jL2GAn5kXdQ6Jwagrk1+bqeZtZCUqckRgWD31CSyrrapipUD2rkcBTy5jM m2CaaE5UNoYJnwlr+40yRPLWHwHyZudERrmE++rd4/K2CtJKi81DVcm0o9nP+IiE k1C9bFX7bVLQTFon/tpVghD+koXd241VTv4Iq0= 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=UxnCF7sUXxHZEATYthNznhvb+BaKR 1eXbkRc1b1AFZw=; b=M0VmAoAeDU/t7yJ8p2BJVAFYKvRVvgrVxfb25Jsgj+Iv7 MXlMTCRaLg/uTGvCj2vzDxtv8/ycxzI8av6Xvhd6BIURBlngK0SGi/M8KoEYS2nL H6zRR6g/ET+rUCitiyuqEgabFwZIJ9uhOPJZv7jrB3YClodcNWYXE/jhxpA2MEjB GdLLBGYEqpj79zx/hV64Oy5hsayBAW78RlGjtyRoBmnPYMCEwNl59PkOpenCyKOL X0VqGQflhMgs9e1ku+eiye6SZETEyWB+ffnjO4D9xwZhfCPjLbRVuCZTIMg6r4Ct K0g3LTAevutPQZ4rsAFkPLyEUGJOieitofxWAm4sQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrudehfedgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfffhffvufgtsehttdertd erredtnecuhfhrohhmpedfvfhrohihucguvgcuhfhrvghithgrshdfuceomhgvsehnthgu vghfrdgtohhmqeenucggtffrrghtthgvrhhnpeeffeelkeetieehleeutedvvdfffffhge evveejtddvueehleetudduuefhteeugeenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehmvgesnhhtuggvfhdrtghomh X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 876902180078; Tue, 11 Jan 2022 11:51:24 -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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 11 Jan 2022 12:24:14 -0500 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:284623 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 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