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: dualbus@hp ...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); #else But it seems that the fix is not that simple, since now this happens: dualbus@hp ...src/gnu/bash % cat ~/.bash_history echo 1 #1452197044 echo a; sleep 1 #1452197045 echo b; sleep 1 dualbus@hp ...src/gnu/bash % ./bash -i <<< "HISTTIMEFORMAT='%Y-%m-%dT%H:%M:%S ' history" dualbus@hp:~/local/src/gnu/bash$ HISTTIMEFORMAT='%Y-%m-%dT%H:%M:%S ' history 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(...) if(t) strftime(...) else strcat(..., "??") It considers 0 as an invalid value. -- Eduardo Bustamante https://dualbus.me/