lmacken / pyrasite

Inject code into running Python processes

Home Page:http://pyrasite.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pyrasite-shell hangs on Arch Linux

purboo opened this issue · comments

It works pretty well on Ubuntu 18.04. However, when I run pyrasite-shell <pid> on Arch Linux, I got the following errors:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
0x00007f9e956f3197 in select () from /usr/lib/libc.so.6

'PyGILState_Ensure' has unknown return type; cast the call to its declared return type
'PyRun_SimpleString' has unknown return type; cast the call to its declared return type
History has not yet reached $1.

^CTraceback (most recent call last):
  File "/usr/bin/pyrasite-shell", line 11, in <module>
    load_entry_point('pyrasite==2.0', 'console_scripts', 'pyrasite-shell')()
  File "/usr/lib/python2.7/site-packages/pyrasite/tools/shell.py", line 30, in shell
    ipc.connect()
  File "/usr/lib/python2.7/site-packages/pyrasite/ipc.py", line 95, in connect
    self.wait()
  File "/usr/lib/python2.7/site-packages/pyrasite/ipc.py", line 151, in wait
    (clientsocket, address) = self.server_sock.accept()
  File "/usr/lib/python2.7/socket.py", line 206, in accept
    sock, addr = self._sock.accept()
KeyboardInterrupt

May I know how to resolve this issue? Thanks.

This change to injector.py fixed the issue for me.

This appears to be detached from develop here. Is this by accident? Maybe @diamond-lizard should make a PR again?

My python application is run by user A. When I try to use pyrasite-shell, it reminds me of running it by user root and I do that. Then, Permission denies comes out which means the application needed to be injected can not open the inject code( you can see the pyrasite code. it makes a tmp file by mkstemp which leads to only the creator can read this file. So, the application can not read.). Then I try to make pyrasite-shell run by user A . I fix it.

@lmacken can you look into diamond-lizard@d1e2301 commit? It really helps to get pyrasite working on Ubuntu 18.04 too with some alternate python versions.

Hi @lmacken, found this issue while searching for the same error. Getting it on an Ubuntu 18.04 Docker container and the commit @irmatov mentions fixes it for me.

That said, Docker's default security policies don't allow ptrace, which is needed by gdb, which is needed by pyrasite. What made it work for me was to do RUN echo kernel.yama.ptrace_scope = 0 > /etc/sysctl.d/10-ptrace.conf in my Dockerfile at build time, then do my docker run call with --cap-add=SYS_PTRACE --security-opt seccomp=unconfined. I'm on Docker 19.03.2 btw.

By the way if anyone wants to pip-install the "fixed" version, remember pip supports installing from git repos, so you can point it to the fixed fork like so:

pip install git+https://github.com/diamond-lizard/pyrasite.git

Still does not work on recent arch. Installed both pip pyrasite and the git version. gdb is also installed. Cannot connect to any of my running python processes:

 pyrasite-shell 2987678
^CTraceback (most recent call last):
  File "/usr/bin/pyrasite-shell", line 33, in <module>
    sys.exit(load_entry_point('pyrasite==2.0', 'console_scripts', 'pyrasite-shell')())
  File "/usr/lib/python3.9/site-packages/pyrasite/tools/shell.py", line 30, in shell
    ipc.connect()
  File "/usr/lib/python3.9/site-packages/pyrasite/ipc.py", line 95, in connect
    self.wait()
  File "/usr/lib/python3.9/site-packages/pyrasite/ipc.py", line 151, in wait
    (clientsocket, address) = self.server_sock.accept()
  File "/usr/lib/python3.9/socket.py", line 293, in accept
    fd, addr = self._accept()
KeyboardInterrupt

gdb version is 10.1

Tried to run it as well, got the following output after enabling verbose mode:

[New LWP 31]
[New LWP 32]
[New LWP 442]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007f6cff8e3aff in __GI___poll (fds=0x7fff888d4308, nfds=1, timeout=60000) at ../sysdeps/unix/sysv/linux/poll.c:29
[Inferior 1 (process 1) detached]

29\t../sysdeps/unix/sysv/linux/poll.c: No such file or directory.
'PyGILState_Ensure' has unknown return type; cast the call to its declared return type
'PyRun_SimpleString' has unknown return type; cast the call to its declared return type
History has not yet reached $1.

Still does not work on recent arch. Installed both pip pyrasite and the git version. gdb is also installed. Cannot connect to any of my running python processes:

 pyrasite-shell 2987678
^CTraceback (most recent call last):
  File "/usr/bin/pyrasite-shell", line 33, in <module>
    sys.exit(load_entry_point('pyrasite==2.0', 'console_scripts', 'pyrasite-shell')())
  File "/usr/lib/python3.9/site-packages/pyrasite/tools/shell.py", line 30, in shell
    ipc.connect()
  File "/usr/lib/python3.9/site-packages/pyrasite/ipc.py", line 95, in connect
    self.wait()
  File "/usr/lib/python3.9/site-packages/pyrasite/ipc.py", line 151, in wait
    (clientsocket, address) = self.server_sock.accept()
  File "/usr/lib/python3.9/socket.py", line 293, in accept
    fd, addr = self._accept()
KeyboardInterrupt

gdb version is 10.1

anyone fix this ?

Any one who is collaborator can help to click this:

https://github.com/lmacken/pyrasite/compare/lmacken:develop...diamond-lizard:develop?expand=1

I'm trying to create a merge request, but failed with:

Pull request creation failed. Validation failed: must be a collaborator