A system slows down and tcsh consumes a lot of memory due to a corrupted .history file
Environment
- Red Hat Enterprise Linux 2.1
- Red Hat Enterprise Linux 3
- Red Hat Enterprise Linux 4
- Red Hat Enterprise Linux 5
- Red Hat Enterprise Linux 6
- RHEL5: tcsh-6.14-14.el5-x86_64
- RHEL6: tcsh-6.17-8.el6.x86_64
Issue
- The data in the file ".history" becomes malformed and its file size gets larger and larger.
- Each command history should be recoded in the file with a timestamp line a command entry line which should end with EOL(End Of Line).
- Example of normal .history file:
$ cat -n .history
\#+1289787344
set
- A timestamp and a run command entry are not recorded by turns. Not a run command entry but a timestamp is recorded unexpectedly (see the line 4). Additionally, some entries are merged unexpectedly (see the line 6 and 7 below).
- Example of malformed .history file :
$ cat -n .history
\#+1289787344
test
\#+1289787367
1289787366
\#+1289787367
128978\#+12897\#+1289\#+12897test
\#+1289\#+12897testls\#\#+1289787401l12\#+1289787402
st
- A system slows down because csh uses a lot of memory to read such a large .history file.
Resolution
- We have released following 6.2.z erratum: http://rhn.redhat.com/errata/RHBA-2012-0687.html
-
We have released following 5.9 erratum: http://rhn.redhat.com/errata/RHBA-2013-0052.html
Note: we released errata only for tcsh617 package for RHEL5 system. So if you're using tcsh package 'based on tcsh-6.14), you need to replace tcsh from tcsh package to tcsh617 package.
-
We will not address this issue on Red Hat Enterprise Linux 2.1, 3 and 4.
-
Temporary workaround:
- Consists of setting the following in
~/.cshrcor on the command line:
set savehist=- The above will prevent any writing to
~/.historyfile (even the empty file still gets truncated every time) thus there won't be any delay in running scripts and no bug will show up.
- Consists of setting the following in
Root Cause
- The main issue which should be fixed is that tcsh does not handle ~/.history file exclusively. The "merge" option causes possibility of a little more unexpected behavior with warning mentioned in man page regarding the "-S" built-in command:
history \[-hTr\] \[n\]
history -S|-L|-M \[filename\] (+)
history -c (+)
With -S, the second form saves the history list to file-
name. If the first word of the savehist shell variable is
set to a number, at most that many lines are saved. If the
second word of savehist is set to ‘merge’, the history list
is merged with the existing history file instead of replac-
ing it (if there is one) and sorted by time stamp. (+)
\____Merging is intended for an environment like the X Window
System with several shells in simultaneous use. Currently
it succeeds only when the shells quit nicely one after
another.\____
- Additionally, both a value greater than 0 and "merge" option are set to savehist on csh and this is the default setting in Red Hat Enterprise Linux 5.4 or later:
$ set | grep savehist
savehist (1024 merge)
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
