nelhage / reptyr

Reparent a running program to a new terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

reptyr -T fails with "Unable to attach [...] Permission Denied"

PythonNut opened this issue · comments

Hello, I'm running a version of Debian Jessie on armhf.

pi@raspberrypi ~/Downloads/reptyr $ sudo ./reptyr -T 31637 
Unable to attach to pid 31637: Permission denied

31637 has been disowned from it's parent terminal (but for the record, it does the exact same thing if the process is not disowned).

Hi,

Was pid 31637 started via ssh? It's a known limitation with -T that it can't attach things started directly out of an ssh session, because the ssh process can't be ptrace'd because it dropped privileges. If 31637 doesn't have children, you can try running without -T

Does this not work even with root? (31637 was indeed started with SSH)

Oh, sorry, I missed the sudo in your command line. I would expect that to work, although I haven't been able to test -T on arm, so it's possible something is up there. Can you run sudo strace -fo /tmp/reptyr.strace reptyr -T 31637 and attach the /tmp/reptyr.strace file?

Done, see this gist. (I had to reboot, so the PID is not the same).

ah-ha, I see the problem. Does eacces make things better? That's a hackish solution, but if it works I can think about implementing a better one.

Hm... oddly the "Permission denied" error goes away, and instead reptyr just hangs and does nothing. Would you like another strace?

I think I've reproduced locally, but probably won't have a chance to dig further until later today or tomorrow.

Out of curiosity, is this armhf specific?

I can reproduce something that seems similar on x86, so I'm hopeful it isn't.

Ok, does the multifd branch do anything better for you?

Oddly enough, that seemed to replace the current shell with the shell instance the process was originally started with, (complete with state). Quite cool, but not the intended result.

Does that even make sense at all?

Yep -- that's what reptyr -T does. It grabs the entire terminal session containing the process, shell and all. Without -T, it will just attach the specific process. Unfortunately, I don't know of a way to grab an entire process tree that isn't rooted in a terminal session.

So, if I understand this correctly, you do not (and indeed, should not) background and disown the process in the shell. (As demonstrated in #34).

If so, then everything seems to be working. (I'll close when the branch is merged)

That's correct (with -T). The behavior with and without -T are substantially different, unfortunately, with different limitations and advantages to each. I'm struggling with how to best document this / provide guidance on which to use :/