nelhage / reptyr

Reparent a running program to a new terminal
MIT License
5.82k stars 215 forks source link

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

Closed PythonNut closed 9 years ago

PythonNut commented 9 years ago

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).

nelhage commented 9 years ago

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

PythonNut commented 9 years ago

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

nelhage commented 9 years ago

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?

PythonNut commented 9 years ago

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

nelhage commented 9 years ago

ah-ha, I see the problem. Does https://github.com/nelhage/reptyr/commit/eacces make things better? That's a hackish solution, but if it works I can think about implementing a better one.

PythonNut commented 9 years ago

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

nelhage commented 9 years ago

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

PythonNut commented 9 years ago

Out of curiosity, is this armhf specific?

nelhage commented 9 years ago

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

nelhage commented 9 years ago

Ok, does the https://github.com/nelhage/reptyr/commit/multifd branch do anything better for you?

PythonNut commented 9 years ago

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?

nelhage commented 9 years ago

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.

PythonNut commented 9 years ago

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)

nelhage commented 9 years ago

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 :/