1

I was having difficulty reattaching to a screen session, so I tried to kill the client screen session and reattach to the server session. This failed. Then I did something kinda stupid. I did a -wipe. Now I have no named pipe file in the /tmp/uscreens/... directory.

The screen server is still running and I was wondering if it was somehow possible to recreate the named pipe.

I'm using Screen version 4.00.03 (FAU) 23-Oct-06 running under cygwin running under Win7 Home Premium. Though I could recover from killing the screen sever and it's children, I would prefer not to.

Any ideas?

EDIT: Here is the list from my fd dir:

$ ls -l /proc/8728/fd/
total 0
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 0 -> /dev/null
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 1 -> /dev/null
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 10 -> /dev/ptmx
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 11 -> /cygdrive/c/Users/Adrian/Downloads/arduino-1.0.3-windows/Projects/RangeDetector5/screenlog.2
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 2 -> /dev/null
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 3 -> /tmp/uscreens/S-Adrian/8728.pty0.TARDIS
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 4 -> /dev/pty0
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 5 -> /var/run/utmp
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 6 -> /dev/ptmx
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 7 -> /cygdrive/c/Users/Adrian/Downloads/arduino-1.0.3-windows/Projects/RangeDetector5/screenlog.0
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 8 -> /dev/ptmx
lrwxrwxrwx 1 Adrian None 0 May 12 22:32 9 -> /cygdrive/c/Users/Adrian/Downloads/arduino-1.0.3-windows/Projects/RangeDetector5/screenlog.1
Adrian
  • 137
  • 9

1 Answers1

2

The situation here:

start cmd: # ps -o pid,args -p 4629 --no-headings
4629 SCREEN
start cmd: # ls -l /proc/4629/fd | grep socket
lrwx------ 1 root root 64 13. Mai 02:55 4 -> socket:[90202]
start cmd: # lsof -n | grep 90202
screen     4629   [...]  90202 /var/run/screens/S-root/4629.pts-12.inno

I guess what you have deleted is the equivalent to my /var/run/screens/S-root/4629.pts-12.inno. ls -l /proc/$PID/fd may still point to the socket node. If you delete files then you can get their content via /proc/$PID/fd as long as a process keeps them opened. I am not familiar with sockets but you can at least give it a try: You can create a symlink (instead of the deleted socket) which points to the socket descriptor in /proc/$PID/fd.

Edit 1:

It may not be sufficient to set a symlink to a socket because the client process may check the type of file and find a symlik where it expects a socket and thus abort without checking the symlink target.

This problem can perhaps be solved with socat. This program allows a "socket forwarding". I have just tested it (with gpg-agent instead of screen though; and the original socket was not deleted):

start cmd:> echo $GPG_AGENT_INFO 
/tmp/gpg-DMOHGo/S.gpg-agent:3236:1
# next command in another shell
start cmd:> socat UNIX-LISTEN:gpg-agent-socket UNIX-CONNECT:/tmp/gpg-DMOHGo/S.gpg-agent
start cmd:> GPG_AGENT_INFO=/home/hl/tmp/gpg-agent-socket:3236:1
start cmd:> start cmd:> gpg-connect-agent 
> 

This may work with the socked FD in /proc, too. Furthermore socat supports FIFOs (named pipes).

Edit 2:

It does work with FIFOs, too:

socat PIPE:/proc/8728/fd/3 PIPE:/tmp/uscreens/S-Adrian/8728.pty0.TARDIS

should do.

BTW: Even if this does not solve your problem (yet) I do think that the effort and quality of my answer should at least be worth an upvote...

Hauke Laging
  • 5,285
  • 2
  • 24
  • 40
  • since I'm using cygwin, it doesn't quite map the same way. Nothing with `-> socket:[...]`. They all appear to be symlinks in the /proc/$PID/fd directory. – Adrian May 13 '13 at 02:34
  • How would I create a symlink? Using `ln`? Would it not be better for a hard link using `cp -l`? Also, cygwin doesn't have the `lsof` command. – Adrian May 13 '13 at 02:40
  • @Adrian You cannot hardlink across file systems and not within /proc at all. Symlinks are created with `ln -s` (or `cp -s`). – Hauke Laging May 13 '13 at 03:17
  • Looks like I can't copy. With the command: `$ cp -s /proc/8728/fd/3 /tmp/uscreens/S-Adrian/8728.pty0.TARDIS` I get an error: `cp: cannot stat \`/proc/8728/fd/3': No such file or directory`. I'm thinking that the file handle isn't accessible? – Adrian May 13 '13 at 04:35
  • @Adrian You haven't tried that with `ln -s` as I told you, have you? – Hauke Laging May 13 '13 at 05:01
  • Yeah, I did, but that didn't work either. Cmd: `$ ln -s /proc/8728/fd/3 /tmp/uscreens/S-Adrian/8728.pty0.TARDIS` worked, but `screen -ls` gave `No Sockets found in /tmp/uscreens/S-Adrian.` – Adrian May 13 '13 at 05:19
  • Starting up a new screen session, and listing the files in the `/tmp/uscreens/S-Adrian` gives a new named pipe file `prwx------ 1 Adrian None 0 May 13 01:16 15212.pty5.TARDIS` and the attemped link file `lrwxrwxrwx 1 Adrian None 15 May 13 01:15 8728.pty0.TARDIS -> /proc/8728/fd/3` which has the wrong attributes. – Adrian May 13 '13 at 05:21
  • Tried to use `mkfifo` but `screen -ls` shows `8728.pty0.TARDIS (Dead ???)`. Maybe the handle is cached somewhere? – Adrian May 13 '13 at 05:28
  • @Adrian Do you think "Tried to use mkfifo" makes clear what you have done? I have no idea why there are FIFOs with you and sockets with me. I have a solution for sockets (which may work with FIFOs, too) now. I'll edit my answer. – Hauke Laging May 13 '13 at 19:56
  • No, it doesn't make it clear what I had done. I tried mkfifo because what you suggested didn't work. if you understand, I'd appreciate it if you'd share. ;) I had just recognized that a the flag on the listing was `p` which is a pipe file. What OS are you running under? As I said, I'm running under Win7, cygwin CYGWIN_NT-6.1-WOW64. – Adrian May 13 '13 at 21:10
  • Oh, wait, I understand, you don't understand what I mean by "tried to use mkfifo". mkfifo creates a named fifo in the filesystem. AFAIK, they are able to be used interchangeably in most if not all cases. So what I did was `mkfifo -m 700 /tmp/uscreens/S-Adrian/8728.pty0.TARDIS` which created a file that looked like it had the proper file flags set. – Adrian May 14 '13 at 00:36
  • I'm looking at your answer, but I'm unsure as to what I should do with it. It looks like it creates a named socket. I'll have to read up on socat more. – Adrian May 14 '13 at 00:51
  • @Adrian Creating a FIFO is not enough. I'll do another edit. – Hauke Laging May 14 '13 at 01:13
  • Sorry for not upvoting. Still kinda new to the site. It won't work as the file exists. Tried to move the file, but of course it's on a read-only filesystem. – Adrian May 14 '13 at 01:44
  • @Adrian Move which file? What is read-only? – Hauke Laging May 14 '13 at 02:23
  • `/proc/8728/fd/3` is on the RO filesystem of `/proc` (though I don't see it on my mount table). Executing the command as you suggested results in `2013/05/14 12:20:49 socat[1380116] E mkfifo(/proc/8728/fd/3, 438): File exists`. – Adrian May 14 '13 at 16:24
  • 1
    @Adrian Strange. It seems that not only your `screen` acts differently from mine but also your `socat`. The file must exist, wouldn't make sense otherwise... You could ask a new question here (linking this one), reduced to the socat problem. – Hauke Laging May 14 '13 at 20:10
  • @HaukeLanging: You never did say what OS you are running. – Adrian May 15 '13 at 04:24
  • @Adrian openSUSE 12.2 (on x86_64) – Hauke Laging May 15 '13 at 04:54