zsh-workers
 help / color / mirror / code / Atom feed
* bug: can't write history file
@ 2006-10-24 14:17 Dmitry Karasik
  2006-10-24 15:27 ` Wayne Davison
  2006-10-24 15:37 ` Peter Stephenson
  0 siblings, 2 replies; 7+ messages in thread
From: Dmitry Karasik @ 2006-10-24 14:17 UTC (permalink / raw)
  To: zsh-workers

Hello,

After upgrading to 4.3.2, I've found that one of the features I love in zsh is
broken, namely the possibility to use the history file for both root and
non-root sessions.  Now, after I logout from "sudo zsh", I get this:

   zsh: can't write history file /home/dk/.zsh-history

I found that it is savehistfile() to blame, because it apparently is called
with writeflags=0, which bypasses all append/rewrite logic, falling back to
saving the file by renaming it to .zsh-history.new, and (correctly) refusing to
overwrite .zsh-history because the euid is different. If I'm correct in
this, the patch below fixes the problem:

--- hist.c.orig Tue Oct 24 15:45:28 2006
+++ hist.c      Tue Oct 24 15:45:47 2006
@@ -2163,7 +2163,7 @@
            readhistfile(fn, err, 0);
            hist_ignore_all_dups = isset(HISTIGNOREALLDUPS);
            if (histlinect)
-               savehistfile(fn, err, 0);
+               savehistfile(fn, err, writeflags & HFILE_APPEND);
 
            pophiststack();
            histactive = remember_histactive;


-- 
Sincerely,
	Dmitry Karasik



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

* Re: bug: can't write history file
  2006-10-24 14:17 bug: can't write history file Dmitry Karasik
@ 2006-10-24 15:27 ` Wayne Davison
  2006-10-24 16:15   ` Dmitry Karasik
  2006-10-24 15:37 ` Peter Stephenson
  1 sibling, 1 reply; 7+ messages in thread
From: Wayne Davison @ 2006-10-24 15:27 UTC (permalink / raw)
  To: Dmitry Karasik; +Cc: zsh-workers

On Tue, Oct 24, 2006 at 04:17:40PM +0200, Dmitry Karasik wrote:
> I found that it is savehistfile() to blame, because it apparently is
> called with writeflags=0, which bypasses all append/rewrite logic

This is as it should be, because that code is re-writing the history
file to trim it.  As long as you use HIST_APPEND or SHARE_HISTORY, the
history from a root session should be added to the file -- just the
rewrite at the end will be skipped.

..wayne..


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

* Re: bug: can't write history file
  2006-10-24 14:17 bug: can't write history file Dmitry Karasik
  2006-10-24 15:27 ` Wayne Davison
@ 2006-10-24 15:37 ` Peter Stephenson
  1 sibling, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2006-10-24 15:37 UTC (permalink / raw)
  To: zsh-workers

Dmitry Karasik wrote:
> Hello,
> 
> After upgrading to 4.3.2, I've found that one of the features I love in zsh i
> s
> broken, namely the possibility to use the history file for both root and
> non-root sessions.  Now, after I logout from "sudo zsh", I get this:
> 
>    zsh: can't write history file /home/dk/.zsh-history
> 
> I found that it is savehistfile() to blame, because it apparently is called
> with writeflags=0, which bypasses all append/rewrite logic, falling back to
> saving the file by renaming it to .zsh-history.new, and (correctly) refusing 
> to
> overwrite .zsh-history because the euid is different. If I'm correct in
> this, the patch below fixes the problem:
> 
>...
> -               savehistfile(fn, err, 0);
> +               savehistfile(fn, err, writeflags & HFILE_APPEND);
>...

That line is the same in 4.2, so I presume what has changed is the
default options (how it reaches this code).  In that case it's
plausible that this should always have had that flag.  It would
be best if Wayne could comment about what he thinks did change,
but I'm not sure if he's around at the moment.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


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

* Re: bug: can't write history file
  2006-10-24 15:27 ` Wayne Davison
@ 2006-10-24 16:15   ` Dmitry Karasik
  2006-10-24 19:08     ` Wayne Davison
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Karasik @ 2006-10-24 16:15 UTC (permalink / raw)
  To: zsh-workers

On Tue, Oct 24, 2006 at 08:27:18AM -0700, Wayne Davison wrote:
> On Tue, Oct 24, 2006 at 04:17:40PM +0200, Dmitry Karasik wrote:
> > I found that it is savehistfile() to blame, because it apparently is
> > called with writeflags=0, which bypasses all append/rewrite logic
> 
> This is as it should be, because that code is re-writing the history
> file to trim it.  As long as you use HIST_APPEND or SHARE_HISTORY, the
> history from a root session should be added to the file -- just the
> rewrite at the end will be skipped.

That is possibly true, however before changing the code I did play with
HIST_APPEND and SHARE_HISTORY and I cannot confirm that setting these option
will work.  To support this, as far as I can see in the code,
"isset(APPENDHISTORY)" or "isset(SHAREHISTORY)" are only checked when
"writeflags & HFILE_USE_OPTIONS", which is actually never true in the second
call. 

> That line is the same in 4.2, so I presume what has changed is the
> default options (how it reaches this code).  In that case it's
> plausible that this should always have had that flag. 

I'm not sure what caused this problem not to appear in the previous versions,
but if you insist that this is the configuration problem, I'd like to ask you
to send me a minimalistic .zshenv that will not trigger the error and will save
the history correctly both under root and non-root. 

-- 
Sincerely,
	Dmitry Karasik



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

* Re: bug: can't write history file
  2006-10-24 16:15   ` Dmitry Karasik
@ 2006-10-24 19:08     ` Wayne Davison
  2006-10-24 20:51       ` Dmitry Karasik
  0 siblings, 1 reply; 7+ messages in thread
From: Wayne Davison @ 2006-10-24 19:08 UTC (permalink / raw)
  To: Dmitry Karasik; +Cc: zsh-workers

On Tue, Oct 24, 2006 at 06:15:06PM +0200, Dmitry Karasik wrote:
> as far as I can see in the code, "isset(APPENDHISTORY)" or
> "isset(SHAREHISTORY)" are only checked when "writeflags &
> HFILE_USE_OPTIONS", which is actually never true in the second call. 

Right.  As I said, this is as it should be.  That part of the code is
rewriting the file on exit, so it should never honor the incremental
options at that point -- it must always rewrite the file from scratch.

> I'd like to ask you to send me a minimalistic .zshenv that will not
> trigger the error and will save the history correctly both under root
> and non-root. 

One new option that I just remembered is HIST_SAVE_BY_COPY:  if you
unset that, the error will go away.  It is a little less safe of an
update, but it does allow root to update the user's file without
changing its ownership.  The alternative is to just live with the
occasional history-file warning while using a history-appending option
(I tested that that will still leave root's commands in the file).

..wayne..


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

* Re: bug: can't write history file
  2006-10-24 19:08     ` Wayne Davison
@ 2006-10-24 20:51       ` Dmitry Karasik
  2006-10-24 21:02         ` Wayne Davison
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Karasik @ 2006-10-24 20:51 UTC (permalink / raw)
  To: zsh-workers

> One new option that I just remembered is HIST_SAVE_BY_COPY:  if you
> unset that, the error will go away.  It is a little less safe of an
> update, but it does allow root to update the user's file without
> changing its ownership.  The alternative is to just live with the

Thanks! But it seems that I'm trying to reproduce it the wrong way...
I say "unset HIST_SAVE_BY_COPY" in .zshenv ... and nothing happens -
the warning is still there. What is the correct incantation?

-- 
Sincerely,
	Dmitry Karasik



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

* Re: bug: can't write history file
  2006-10-24 20:51       ` Dmitry Karasik
@ 2006-10-24 21:02         ` Wayne Davison
  0 siblings, 0 replies; 7+ messages in thread
From: Wayne Davison @ 2006-10-24 21:02 UTC (permalink / raw)
  To: Dmitry Karasik; +Cc: zsh-workers

On Tue, Oct 24, 2006 at 10:51:43PM +0200, Dmitry Karasik wrote:
> I say "unset HIST_SAVE_BY_COPY" in .zshenv ... and nothing happens -

You want unsetopt instead of unset.

..wayne..


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

end of thread, other threads:[~2006-10-24 21:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-24 14:17 bug: can't write history file Dmitry Karasik
2006-10-24 15:27 ` Wayne Davison
2006-10-24 16:15   ` Dmitry Karasik
2006-10-24 19:08     ` Wayne Davison
2006-10-24 20:51       ` Dmitry Karasik
2006-10-24 21:02         ` Wayne Davison
2006-10-24 15:37 ` 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).