# tcsh: .history.lock prevents logout



## getopt (May 17, 2019)

The number of hanging logouts from tcsh login shells became annoying here on releng-11.2 systems.
The reason is in all events a remaining .history.lock.

I'm not sure, but I suspect that the file is a remaining from shutdowns where the file was not removed. 

Who knows how to solve/avoid this by making sure no .history.lock is left over?


----------



## Maxnix (May 17, 2019)

If you don't need locking the history file (i.e. you do not have multiple instances of tcsh that exit contemporarily and could corrupt commands history), you can disable locking removing the word _lock_ from the _savehist_ parameter.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=632892


----------



## getopt (May 17, 2019)

Maxnix said:


> If you don't need locking the history file...


Well, actually I do need locking and there is in .tcshrc

```
set history = (1000)
set savehist = (1000 merge lock)
set histdup = erase
```
Without locking in .history corrupted entries occur.


----------



## getopt (Jul 24, 2019)

There seem to be a bug in Tcsh as now it is for sure that ~/.history.lock persists shutdowns. Does the dot_unlock of Tcsh not work?

Or is it a non-graceful shutdown handling from the system?

There are always multiple ttys open when one of does a shutdown. 
After booting and login a ~/.history.lock can be found which should not be the case.

Having looked into /usr/src/contrib/tcsh I admit that my knowledge of signal handling is poor.


----------



## Phishfry (Aug 20, 2019)

getopt said:


> non-graceful shutdown handling from the system?


I think this could be it. When logged in to the same user account via ssh and console I have seen the problem..
So I have learned from this post that .history is locked.
But I too have seen this survive a reboot, more than once, so maybe shutting down in the middle of a ssh session that causes this.
I can confirm that I have seen this sporatic behaviour... I assumed it was something I was doing wrong.
So now I will keep an eye on ~/history.lock


----------



## badbrain (Aug 20, 2019)

Install fish or zsh and the problem will gone automatically.


----------



## getopt (Aug 20, 2019)

badbrain said:


> Install fish or zsh and the problem will gone automatically.


This is one of the finest examples on how to avoid fixing problems.
This kind of "problem solving" is reserved to those who cannot better and it has it's root where deinstalling/reinstalling serves the dumbest.


----------



## badbrain (Aug 21, 2019)

getopt said:


> This is one of the finest examples on how to avoid fixing problems.
> This kind of "problem solving" is reserved to those who cannot better and it has it's root where deinstalling/reinstalling serves the dumbest.


Yes. I'm incompetent.


----------



## jauh (Apr 9, 2021)

I was bitten by this on FreeBSD in the past and again today on raspberry OS (tcsh 6.20.00).
I haven't seen the problem on my FreeBSD boxen for a while now (FreeBSD 12.2p6 provides tcsh 6.21.00).

My hack/workaround until a newer tcsh package is available is to add a ~/.login file to remove any lock files at login.


```
# Hack: a left over ~/.history.lock can cause logout to hang (and ignore terminal interrupts!)
# see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=632892
if ( -e ~/.history.lock ) then
    echo "WARNING: removed ~/.history.lock (left over from previous reboot?)"
endif
rm -rf ~/.history.lock
```

Maxnix thanks for the link to the bug report


----------

