zsh-workers
 help / color / mirror / code / Atom feed
* zsh history gets destroyed when running out of disk space
@ 2007-06-11 20:22 Michael Prokop
  2007-06-21  8:04 ` Frank Terbeck
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Prokop @ 2007-06-11 20:22 UTC (permalink / raw)
  To: zsh-workers


[-- Attachment #1.1: Type: text/plain, Size: 777 bytes --]

Hi,

Problem:

Zsh truncates the zsh history file if you are running out of disk
space (AKA ENOSPC). If you don't have any space left in your $HOME
and exit zsh you'll find an empty $HISTFILE left.

Reason:

The savehistfile() function in Src/hist.c does not handle write
errors very smart.

Fix:

See attached patch (against version 4.3.4). The fix might need some
more work though. For example there should be much more and better
error handling; Zsh shouldn't exit with a return value of 0 when
such serious errors happen; the user should be informed about the
reason why it failed.

regards,
-mika-
-- 
 ,'"`.         http://www.michael-prokop.at/
(  grml.org -» Linux Live-CD for texttool-users and sysadmins
 `._,'         http://www.grml.org/

[-- Attachment #1.2: zsh_fix_history_enospc.patch --]
[-- Type: text/x-diff, Size: 864 bytes --]

--- Src/hist.c.orig	2007-06-11 21:02:42.000000000 +0200
+++ Src/hist.c	2007-06-11 21:58:37.000000000 +0200
@@ -2158,6 +2158,11 @@
     Histent he;
     zlong xcurhist = curhist - !!(histactive & HA_ACTIVE);
     int extended_history = isset(EXTENDEDHISTORY);
+    int write_file = 1; // by default assume we can write the file
+
+    // make sure we don't write anything in case of an error
+    if (errno == ENOSPC)
+      write_file = 0;
 
     if (!interact || savehistsiz <= 0 || !hist_ring
      || (!fn && !(fn = getsparam("HISTFILE"))))
@@ -2222,7 +2227,7 @@
 #endif
 	}
     }
-    if (out) {
+    if (out && write_file) {
 	for (; he && he->histnum <= xcurhist; he = down_histent(he)) {
 	    if ((writeflags & HFILE_SKIPDUPS && he->node.flags & HIST_DUP)
 	     || (writeflags & HFILE_SKIPFOREIGN && he->node.flags & HIST_FOREIGN)

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2007-06-23 18:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-11 20:22 zsh history gets destroyed when running out of disk space Michael Prokop
2007-06-21  8:04 ` Frank Terbeck
2007-06-22 20:28   ` Peter Stephenson
2007-06-22 22:40     ` Michael Prokop
2007-06-23 18:09       ` Peter Stephenson

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

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).