I have several long-running GNU screen sessions. I ssh to the box they're running on and run screen -d -r foo
to detach them if they're connected anywhere else, and then attach them in my current window.
99% of the time this works fine, but on occasion I get this:
$ screen -d -r foo
[2430.foo detached.]
...and nothing happens; I can't get back to the shell at all. Trying in another window does the same thing, the only thing I can do is destroy that screen session (losing all the programs that were running in it) and recreate it
Why does this happen? How can I avoid it or reconnect successfully when it does happen?
Edit: My .screenrc
:
startup_message off
defwritelock off
bind q quit
caption always '%{gk} (%n) %t %{y}%d %M %Y :: %c:%s %{b}%W%{d}'
screen -t ZSH
autodetach on
shelltitle ZSH
defutf8 on
Edit: The end of an strace
log when trying to attach:
readlink("/proc/self/fd/0", "/dev/pts/14", 4095) = 11
stat64("/dev/pts/14", {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 14), ...}) = 0
stat64("/dev/pts/14", {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 14), ...}) = 0
geteuid32() = 1000
getegid32() = 1000
open("/dev/pts/14", O_RDWR|O_NONBLOCK) = 3
geteuid32() = 1000
getegid32() = 1000
close(3) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
umask(0) = 022
lstat64("/var/run/screen", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
access("/var/run/screen/S-mrozekma", F_OK) = 0
stat64("/var/run/screen/S-mrozekma", {st_mode=S_IFDIR|0700, st_size=4096, ...}) = 0
umask(022) = 0
uname({sys="Linux", node="etudes-2", ...}) = 0
rt_sigaction(SIGHUP, {0x806e520, [], 0}, {SIG_DFL, [], 0}, 8) = 0
geteuid32() = 1000
getegid32() = 1000
open("/var/run/screen/S-mrozekma", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3
getdents(3, /* 6 entries */, 32768) = 124
stat64("/var/run/screen/S-mrozekma/2386.chat", {st_mode=S_IFIFO|0700, st_size=0, ...}) = 0
geteuid32() = 1000
getegid32() = 1000
open("/var/run/screen/S-mrozekma/2386.chat", O_WRONLY|O_NONBLOCK) = 4
geteuid32() = 1000
getegid32() = 1000
fcntl64(4, F_SETFL, O_RDONLY) = 0
geteuid32() = 1000
getegid32() = 1000
getdents(3, /* 0 entries */, 32768) = 0
close(3) = 0
geteuid32() = 1000
getegid32() = 1000
setuid32(1000) = 0
setgid32(1000) = 0
stat64("/var/run/screen/S-mrozekma/2386.chat", {st_mode=S_IFIFO|0700, st_size=0, ...}) = 0
getpid() = 30081
write(4, "\0gsm\4\0\0\0/dev/pts/14\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 12336
strace screen -d -r foo
(you may need to make a non-set[ug]id copy of thescreen
executable) andstrace -p$(pidof SCREEN)
around the time of a failed reconnection.strace
log.strace
ing the main screen process shows a similar block in awrite()
callscreen
be trying to write to a connection that no longer exists?SCREEN
) still alive? What is it doing (strace
)?