unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#34093: auto-save prevents quitting emacs on read-only filesystem
@ 2019-01-16  3:01 Leonard Lausen
  2020-08-18 17:52 ` Stefan Kangas
  0 siblings, 1 reply; 6+ messages in thread
From: Leonard Lausen @ 2019-01-16  3:01 UTC (permalink / raw)
  To: 34093

Recently my filesystem had to be emergency remounted as read-only. I
observed that I could not kill-emacs anymore. The following showed up in
my log upon trying to quit emacs:

```
company-statistics--save: Opening output file: Read-only file system, /home/leonard/.emacs.d/.cache/company-statistics-cache.el
Error running timer ‘savehist-autosave’: (file-error "Opening output file" "Read-only file system" "/home/leonard/.emacs.d/.cache/savehist")
```

This prevented quitting emacs.

I am not sure if `company-statistics--save` prevented the shutdown, or
just warned about the read-only file system. Possibly the behavior of
`company-statistics--save` is sane and only `savehist-autosave` is at
fault. Maybe both are at fault?

The expected behavior is that emacs may warn about or ignore that it
cannot write the savehist file. Calling kill-emacs should still quit
emacs.

The company-mode bug report is at
https://github.com/company-mode/company-mode/issues/860

This is with GNU Emacs 26.1 and the following init.el
https://github.com/leezu/dotfiles/blob/master/emacs/.spacemacs.d/init.el





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#34093: auto-save prevents quitting emacs on read-only filesystem
  2019-01-16  3:01 bug#34093: auto-save prevents quitting emacs on read-only filesystem Leonard Lausen
@ 2020-08-18 17:52 ` Stefan Kangas
  2020-08-18 18:20   ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Kangas @ 2020-08-18 17:52 UTC (permalink / raw)
  To: Leonard Lausen; +Cc: 34093

[-- Attachment #1: Type: text/plain, Size: 1293 bytes --]

tags 34093 + patch
thanks

Leonard Lausen <leonard@lausen.nl> writes:

> Recently my filesystem had to be emergency remounted as read-only. I
> observed that I could not kill-emacs anymore. The following showed up in
> my log upon trying to quit emacs:
>
> ```
> company-statistics--save: Opening output file: Read-only file system, /home/leonard/.emacs.d/.cache/company-statistics-cache.el
> Error running timer ‘savehist-autosave’: (file-error "Opening output file" "Read-only file system" "/home/leonard/.emacs.d/.cache/savehist")
> ```
>
> This prevented quitting emacs.
>
> I am not sure if `company-statistics--save` prevented the shutdown, or
> just warned about the read-only file system. Possibly the behavior of
> `company-statistics--save` is sane and only `savehist-autosave` is at
> fault. Maybe both are at fault?
>
> The expected behavior is that emacs may warn about or ignore that it
> cannot write the savehist file. Calling kill-emacs should still quit
> emacs.

I can reproduce this under "emacs -Q" by evaluating:

(progn (savehist-mode)
       (setq savehist-file "/usr/foo")
       (confirm-exit-emacs))

I have attached a patch which fixes this bug by showing a warning if
this file is not readable.

Best regards,
Stefan Kangas

[-- Attachment #2: 0001-Fix-exiting-Emacs-when-savehist-file-not-writable.patch --]
[-- Type: text/x-diff, Size: 3351 bytes --]

From d780864fd38768801c88778ee694a1a535e41810 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Tue, 18 Aug 2020 19:29:19 +0200
Subject: [PATCH] Fix exiting Emacs when savehist-file not writable

* lisp/savehist.el (savehist-save): Show warning when 'savehist-file'
is not writable.  (Bug#34093)
(savehist--has-given-file-warning): New variable.
---
 lisp/savehist.el | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/lisp/savehist.el b/lisp/savehist.el
index 4e52efe7f1..5a64b9327a 100644
--- a/lisp/savehist.el
+++ b/lisp/savehist.el
@@ -215,6 +215,7 @@ savehist-uninstall
     (cancel-timer savehist-timer)
     (setq savehist-timer nil)))
 
+(defvar savehist--has-given-file-warning nil)
 (defun savehist-save (&optional auto-save)
   "Save the values of minibuffer history variables.
 Unbound symbols referenced in `savehist-additional-variables' are ignored.
@@ -288,23 +289,29 @@ savehist-save
     ;; If autosaving, avoid writing if nothing has changed since the
     ;; last write.
     (let ((checksum (md5 (current-buffer) nil nil savehist-coding-system)))
-      (unless (and auto-save (equal checksum savehist-last-checksum))
-	;; Set file-precious-flag when saving the buffer because we
-	;; don't want a half-finished write ruining the entire
-	;; history.  Remember that this is run from a timer and from
-	;; kill-emacs-hook, and also that multiple Emacs instances
-	;; could write to this file at once.
-	(let ((file-precious-flag t)
-	      (coding-system-for-write savehist-coding-system)
-              (dir (file-name-directory savehist-file)))
-          ;; Ensure that the directory exists before saving.
-          (unless (file-exists-p dir)
-            (make-directory dir t))
-	  (write-region (point-min) (point-max) savehist-file nil
-			(unless (called-interactively-p 'interactive) 'quiet)))
-	(when savehist-file-modes
-	  (set-file-modes savehist-file savehist-file-modes))
-	(setq savehist-last-checksum checksum)))))
+      (condition-case err
+        (unless (and auto-save (equal checksum savehist-last-checksum))
+	  ;; Set file-precious-flag when saving the buffer because we
+	  ;; don't want a half-finished write ruining the entire
+	  ;; history.  Remember that this is run from a timer and from
+	  ;; kill-emacs-hook, and also that multiple Emacs instances
+	  ;; could write to this file at once.
+	  (let ((file-precious-flag t)
+	        (coding-system-for-write savehist-coding-system)
+                (dir (file-name-directory savehist-file)))
+            ;; Ensure that the directory exists before saving.
+            (unless (file-exists-p dir)
+              (make-directory dir t))
+	    (write-region (point-min) (point-max) savehist-file nil
+			  (unless (called-interactively-p 'interactive) 'quiet)))
+	  (when savehist-file-modes
+	    (set-file-modes savehist-file savehist-file-modes))
+	  (setq savehist-last-checksum checksum))
+        (file-error
+         (unless savehist--has-given-file-warning
+          (lwarn '(savehist-file) :warning "Error writing `%s': %s"
+                 savehist-file (caddr err))
+          (setq savehist--has-given-file-warning t)))))))
 
 (defun savehist-autosave ()
   "Save the minibuffer history if it has been modified since the last save.
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#34093: auto-save prevents quitting emacs on read-only filesystem
  2020-08-18 17:52 ` Stefan Kangas
@ 2020-08-18 18:20   ` Eli Zaretskii
  2020-08-18 18:44     ` Stefan Kangas
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2020-08-18 18:20 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 34093, leonard

> From: Stefan Kangas <stefan@marxist.se>
> Date: Tue, 18 Aug 2020 17:52:24 +0000
> Cc: 34093@debbugs.gnu.org
> 
> (progn (savehist-mode)
>        (setq savehist-file "/usr/foo")
>        (confirm-exit-emacs))
> 
> I have attached a patch which fixes this bug by showing a warning if
> this file is not readable.

Thanks, but is a single warning really enough?  What if the situation
is slightly different, in that the user could somehow resolve the
problem -- should we perhaps prompt the user whether to retry or
ignore the error?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#34093: auto-save prevents quitting emacs on read-only filesystem
  2020-08-18 18:20   ` Eli Zaretskii
@ 2020-08-18 18:44     ` Stefan Kangas
  2021-05-11 13:58       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Kangas @ 2020-08-18 18:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 34093, leonard

Eli Zaretskii <eliz@gnu.org> writes:

> Thanks, but is a single warning really enough?  What if the situation
> is slightly different, in that the user could somehow resolve the
> problem -- should we perhaps prompt the user whether to retry or
> ignore the error?

Is it worth it?  The bug will presumably trigger only under rare
circumstances such as serious misconfiguration by the user or serious
system failure ($HOME remounted as read-only sounds fairly exceptional).
And the consequence is that the user will miss out on a very minor
convenience feature.

OTOH, I'm not a regular user of savehist-mode, so I'm not sure.  Maybe
people really depend on saving their minibuffer history between
sessions...  But even then, they would be no worse off with my proposed
fix than they are now.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#34093: auto-save prevents quitting emacs on read-only filesystem
  2020-08-18 18:44     ` Stefan Kangas
@ 2021-05-11 13:58       ` Lars Ingebrigtsen
  2021-05-12  4:04         ` Richard Stallman
  0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2021-05-11 13:58 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 34093, leonard

Stefan Kangas <stefan@marxist.se> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>> Thanks, but is a single warning really enough?  What if the situation
>> is slightly different, in that the user could somehow resolve the
>> problem -- should we perhaps prompt the user whether to retry or
>> ignore the error?
>
> Is it worth it?  The bug will presumably trigger only under rare
> circumstances such as serious misconfiguration by the user or serious
> system failure ($HOME remounted as read-only sounds fairly exceptional).
> And the consequence is that the user will miss out on a very minor
> convenience feature.

I agree with Stefan that the fix should be sufficient for most usages,
so I've applied it to Emacs 28.  It would be nice if it went even
further, of course, but the patch is at the very least a step in the
right direction in itself.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#34093: auto-save prevents quitting emacs on read-only filesystem
  2021-05-11 13:58       ` Lars Ingebrigtsen
@ 2021-05-12  4:04         ` Richard Stallman
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2021-05-12  4:04 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 34093, stefan, leonard

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

The situation where something goes wrong with a disk, and you can't
save your files any more, can be very painful.  So let's try to be as
helpful as we can be.  We can offer to save on another disk, or over
the net.


-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)







^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-12  4:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-16  3:01 bug#34093: auto-save prevents quitting emacs on read-only filesystem Leonard Lausen
2020-08-18 17:52 ` Stefan Kangas
2020-08-18 18:20   ` Eli Zaretskii
2020-08-18 18:44     ` Stefan Kangas
2021-05-11 13:58       ` Lars Ingebrigtsen
2021-05-12  4:04         ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).