From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Bernardo Newsgroups: gmane.emacs.bugs Subject: bug#37884: 27.0.50; Cannot write to a file in VirtualBox shared directory Date: Tue, 29 Oct 2019 19:50:15 +1100 Message-ID: <87zhhkc4vs.fsf@pobox.com> References: <87h83zeoy1.fsf@pobox.com> <87blu2emi3.fsf@pobox.com> <83lft6rxrs.fsf@gnu.org> <874kztdy0l.fsf@pobox.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="185288"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 37884@debbugs.gnu.org To: Robert Pluim Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Oct 29 09:51:17 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.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iPNDg-000m2V-JO for geb-bug-gnu-emacs@m.gmane.org; Tue, 29 Oct 2019 09:51:16 +0100 Original-Received: from localhost ([::1]:52926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iPNDf-0006Do-Bi for geb-bug-gnu-emacs@m.gmane.org; Tue, 29 Oct 2019 04:51:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43158) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iPNDT-0006CN-Sn for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2019 04:51:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iPNDS-000809-Mm for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2019 04:51:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38012) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iPNDS-0007zV-JR for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2019 04:51:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iPNDS-00007s-FU for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2019 04:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Bernardo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 29 Oct 2019 08:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37884 X-GNU-PR-Package: emacs Original-Received: via spool by 37884-submit@debbugs.gnu.org id=B37884.1572339025438 (code B ref 37884); Tue, 29 Oct 2019 08:51:02 +0000 Original-Received: (at 37884) by debbugs.gnu.org; 29 Oct 2019 08:50:25 +0000 Original-Received: from localhost ([127.0.0.1]:46832 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iPNCq-000070-Iw for submit@debbugs.gnu.org; Tue, 29 Oct 2019 04:50:24 -0400 Original-Received: from pecan-mail.exetel.com.au ([220.233.0.8]:43175 helo=pecan.exetel.com.au) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iPNCo-00006n-TI for 37884@debbugs.gnu.org; Tue, 29 Oct 2019 04:50:23 -0400 Original-Received: from 105.199.233.220.static.exetel.com.au ([220.233.199.105] helo=deb) by pecan.exetel.com.au with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.91) (envelope-from ) id 1iPNCh-0007SI-86; Tue, 29 Oct 2019 19:50:15 +1100 In-Reply-To: (Robert Pluim's message of "Mon, 28 Oct 2019 13:32:45 +0100") 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:170352 Archived-At: Robert Pluim writes: >>>>>> On Mon, 28 Oct 2019 20:23:22 +1100, Bernardo said: > Bernardo> $ git diff src/filelock.c > Bernardo> diff --git a/src/filelock.c b/src/filelock.c > Bernardo> index ff25d6475d..79eb8fa91e 100644 > Bernardo> --- a/src/filelock.c > Bernardo> +++ b/src/filelock.c > Bernardo> @@ -403,7 +403,7 @@ create_lock_file (char *lfname, char *lock_info_str, bool force) > Bernardo> lock_info_len = strlen (lock_info_str); > Bernardo> err = 0; > Bernardo> if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len > Bernardo> - || fchmod (fd, S_IRUSR | S_IRGRP | S_IROTH) != 0) > Bernardo> + || fchmod (fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) != 0) > Bernardo> err = errno; > Bernardo> /* There is no need to call fsync here, as the contents of > Bernardo> the lock file need not survive system crashes. */ > > Bernardo> and Emacs is happy again, no problems with writing to files in > Bernardo> VirtualBox shared directory. > > Bernardo> Please let me know if you want me to test anything else. > > I think Eli's suggestion was more like the below, which only calls > fchmod if the unlink fails. > > diff --git a/src/filelock.c b/src/filelock.c > index ff25d6475d..7fb14774b0 100644 > --- a/src/filelock.c > +++ b/src/filelock.c > @@ -732,6 +732,15 @@ unlock_file (Lisp_Object fn) > int err = current_lock_owner (0, lfname); > if (err == -2 && unlink (lfname) != 0 && errno != ENOENT) > err = errno; > + /* On certain filesystems the file must be writable for unlink to > + succeed (Bug#37784). */ > + if (errno == EPERM) > + { > + fchmod (fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); > + errno = 0; > + if (unlink (lfname) != 0 && errno != ENOENT) > + err = errno; > + } > if (0 < err) > report_file_errno ("Unlocking file", filename, err); > two changes in that code snippet were needed to get things working: * replace fchmod() with chmod() (a minor one) * more importantly, had to set the value of err to 0, otherwise it would end up with the same problem; guess you'll have a closer look at the 2nd change and possibly come up with a better solution The code that works fine looks like this: $ git diff diff --git a/src/filelock.c b/src/filelock.c index ff25d6475d..046a1b014f 100644 --- a/src/filelock.c +++ b/src/filelock.c @@ -732,6 +732,16 @@ unlock_file (Lisp_Object fn) int err = current_lock_owner (0, lfname); if (err == -2 && unlink (lfname) != 0 && errno != ENOENT) err = errno; + /* On certain filesystems the file must be writable for unlink to + succeed (Bug#37784). */ + if (errno == EPERM) + { + chmod (lfname, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + err = 0; + errno = 0; + if (unlink (lfname) != 0 && errno != ENOENT) + err = errno; + } if (0 < err) report_file_errno ("Unlocking file", filename, err);