From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#35418: [PATCH] Don't poll auto-revert files that use notification Date: Sat, 27 Apr 2019 18:19:36 +0200 Message-ID: References: <83sgu71b91.fsf@gnu.org> <74CB5185-5DA1-4786-BD9C-9EEB3D43B3C1@acm.org> <83o94uz9h2.fsf@gnu.org> <875zqzssql.fsf@gmx.de> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="192253"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 35418@debbugs.gnu.org To: Michael Albinus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 27 18:20:12 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hKQ3g-000ntS-BC for geb-bug-gnu-emacs@m.gmane.org; Sat, 27 Apr 2019 18:20:12 +0200 Original-Received: from localhost ([127.0.0.1]:33924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKQ3f-0006jT-CP for geb-bug-gnu-emacs@m.gmane.org; Sat, 27 Apr 2019 12:20:11 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:59589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKQ3X-0006j8-GH for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2019 12:20:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hKQ3W-0000Ja-AF for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2019 12:20:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50521) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hKQ3W-0000JS-7U for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2019 12:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hKQ3W-0007Hm-1E for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2019 12:20:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 27 Apr 2019 16:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35418 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 35418-submit@debbugs.gnu.org id=B35418.155638198427977 (code B ref 35418); Sat, 27 Apr 2019 16:20:01 +0000 Original-Received: (at 35418) by debbugs.gnu.org; 27 Apr 2019 16:19:44 +0000 Original-Received: from localhost ([127.0.0.1]:35832 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hKQ3D-0007HB-P4 for submit@debbugs.gnu.org; Sat, 27 Apr 2019 12:19:44 -0400 Original-Received: from mail156c50.megamailservers.eu ([91.136.10.166]:32782 helo=mail51c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hKQ3A-0007H0-Rl for 35418@debbugs.gnu.org; Sat, 27 Apr 2019 12:19:41 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1556381978; bh=Xw1b1qpJPC2iIsONrhrPe6tQ14K3ncHuNRnQXj2KBWY=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=mhmrQq3PXaFIls3izW9IOsW5alwB8fYAS/Jw8K1FuvnQXm+uvKi4gyncv6YrgsDhR rbbgDozEICYiSZHB5YAZiPB2HLnG1q4Q4tfE+NWPb89+NUAu0AFTLk4UneMjZMJXwm WKXf+ML6lSubGvilX6fmNAo3r7tjDwve4nTWW6Yg= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.1.64] (c-e636e253.032-75-73746f71.bbcust.telenor.se [83.226.54.230]) (authenticated bits=0) by mail51c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x3RGJaN1001772; Sat, 27 Apr 2019 16:19:38 +0000 In-Reply-To: <875zqzssql.fsf@gmx.de> X-Mailer: Apple Mail (2.3445.104.8) X-CTCH-RefID: str=0001.0A0B020B.5CC4811A.0025, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=NqD/jfVJ c=1 sm=1 tr=0 a=M+GU/qJco4WXjv8D6jB2IA==:117 a=M+GU/qJco4WXjv8D6jB2IA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=f289YO8E5LQ18tp_bgsA:9 a=7LxUVfY0szrN1Za1:21 a=wcZv7zFZoprkOq0x:21 a=CjuIK1q_8ugA:10 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:158360 Archived-At: 27 apr. 2019 kl. 11.27 skrev Michael Albinus : >=20 > Well, in inotify you still get undesired notifications. Like this: >=20 > --8<---------------cut here---------------start------------->8--- > (write-region "foo" nil "/tmp/foo") > (add-name-to-file "/tmp/foo" "/tmp/bar" 'ok) >=20 > (inotify-add-watch "/tmp/foo" t (lambda (event) (message "inotify %S" = event))) > =3D> (1 . 0) > (inotify-add-watch "/tmp/bar" t (lambda (event) (message "inotify %S" = event))) > =3D> (1 . 1) > (write-region "foo" nil "/tmp/foo") > =3D> inotify ((1 . 0) (modify) "/tmp/foo" 0) > inotify ((1 . 1) (modify) "/tmp/bar" 0) Thanks for the example! I wouldn't call this undesired. Create a hard link to a file, ask for = notification on both links, and then modify the file. Then both = notifiers trigger, because someone has modified the file they were = watching. The kqueue back-end behaves similarly. > However, in filenotify this is fixed: >=20 > --8<---------------cut here---------------start------------->8--- > (file-notify-add-watch "/tmp/foo" '(change attribute-change) > (lambda (event) (message "file-notify %S" = event))) > =3D> (2 . 0) > (file-notify-add-watch "/tmp/bar" '(change attribute-change) > (lambda (event) (message "file-notify %S" = event))) > =3D> (2 . 1) > (write-region "foo" nil "/tmp/foo") > =3D> file-notify ((2 . 0) changed "/tmp/foo") > inotify ((1 . 0) (modify) "/tmp/foo" 0) > inotify ((1 . 1) (modify) "/tmp/bar" 0) Actually, it is (arguably) a bug. With two buffers referring to distinct = hard links for the same file, surely we want a change in that file to = trigger notification for both! (It's quite an exotic case, not the least = because Emacs normally recognises hard links as if they were the same = file name.) However, with the kqueue back-end, file-notify watches do trigger for = both, as expected. The reason is that file-notify does not call inotify-add-watch on = individual files, as in your example above, but on their containing = directory ("/tmp" in your example). When monitoring a directory with two = hard links to the same file, and the file is changed, inotify (sensibly) = only reports a change to one of the links (the one employed for the = change). Thus, the logic is in the Linux kernel, not in filenotify. For kqueue it is different: here, changes to files are not reported when = a watch is monitoring their directory, so filenotify.el sets kqueue = watches on each file instead. The same could be done with inotify (and = w32notify, if I read the code right), but watching directories has = certain advantages. > Unrelated events for "/tmp/bar" are filtered out in > `file-notify-callback'. So yes, the inotify problems seem to be fixed. Are you really sure that the inotify problems were really about changes = to files with multiple hard links? It sounds very unlikely, and as = showed above, the behaviour differs between back-ends. If I were to guess, the problem was rather that the inotify back-end = used to return the kernel-provided descriptor number, which is the same = for the same directory: when /dir/a and /dir/b (distinct files, not hard = links) both were watched, inotify would monitor /dir twice and give the = same descriptor for both, with the ensuing chaos. This was subsequently = fixed by making inotify return unique descriptors. > We might extend this variable. *If* this regexp matches a file name, = we > know that we need polling. But it is clear, that we cannot catch all > cases by just parsing file names. >=20 > (Btw, we should use the value of `mounted-file-systems', introduced in > Emacs 26.1, when initializing = `auto-revert-notify-exclude-dir-regexp'.) That variable contains "^//[^/]+/" on Windows, so we need to make up our = minds about it. > One alternative approach could be to analyze the file system device > number, as returned by `file-attributes'. By this, we could detect > mounted file systems. Sort of; the interpretation is tricky, and as Eli commented, quite = platform-specific. > But I don't believe that this information is always trustworty, given = it > isn't used anywhere. And at least for remote files it doesn't tell you > anything. Furthermore, mounted file systems are not the only reason = that > file notification doesn't work, and we need to poll. What other reasons are you thinking about?