[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Default time for unmarked history lines

From: Eduardo A . Bustamante López
Subject: Re: Default time for unmarked history lines
Date: Thu, 7 Jan 2016 22:21:24 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

On Thu, Jan 07, 2016 at 08:56:06PM +0000, Reuben Thomas wrote:
> ​Yes, and it's not at the moment (or wasn't, until I added timestamps to
> every line in my history), because the lines at the start of the history,
> with no timestamp, were given the current date and time, and lines at the
> end of the history, with timestamps, were given​ the earlier date and time
> at which they were added to the history. That's why the epoch is better.
> Also, it's a better clue that the timestamp is being faked.

I now understand your points.

I was playing a bit with the code, and found the piece that initializes time in
history entries:

    address@hidden ...src/gnu/bash % git diff
    diff --git a/lib/readline/history.c b/lib/readline/history.c
    index 3b8dbc5..2b186e9 100644
    --- a/lib/readline/history.c
    +++ b/lib/readline/history.c
    @@ -258,7 +258,7 @@ hist_inittime ()
       time_t t;
       char ts[64], *ret;
    -  t = (time_t) time ((time_t *)0);
    +  t = (time_t) 1;
     #if defined (HAVE_VSNPRINTF)           /* assume snprintf if vsnprintf 
exists */
       snprintf (ts, sizeof (ts) - 1, "X%lu", (unsigned long) t);

But it seems that the fix is not that simple, since now this happens:

    address@hidden ...src/gnu/bash % cat ~/.bash_history          
    echo 1
    echo a; sleep 1
    echo b; sleep 1

    address@hidden ...src/gnu/bash % ./bash -i <<< 
"HISTTIMEFORMAT='%Y-%m-%dT%H:%M:%S ' history"
    address@hidden:~/local/src/gnu/bash$ HISTTIMEFORMAT='%Y-%m-%dT%H:%M:%S ' 
        1  1969-12-31T18:00:01 echo 1
        2  2016-01-07T14:04:04 echo a; sleep 1
        3  2016-01-07T14:04:05 echo b; sleep 1
        4  1969-12-31T18:00:01 HISTTIMEFORMAT='%Y-%m-%dT%H:%M:%S ' history

So, it seems that new entries are created with the localtime, unless there's a
history comment followed by a timestamp. I'm not sure what changes are needed
to adjust this, but I guess that is not a simple fix.

BTW, the timestamp = 0 thing is a bug in readline. Since it uses (time_t) 0 as
a return value for errors in history_get_time, and later there's code similar
to this:

    t = history_get_time(...)
      strcat(..., "??")

It considers 0 as an invalid value.

Eduardo Bustamante

reply via email to

[Prev in Thread] Current Thread [Next in Thread]