nelhage / reptyr

Reparent a running program to a new terminal
MIT License
5.77k stars 216 forks source link

Test build fails with kernel < 3.4? #69

Closed scop closed 8 years ago

scop commented 8 years ago

On CentOS 6 (kernel-headers-2.6.32):

$ make test
cc -Wall -Werror -D_GNU_SOURCE -g   -c -o test/victim.o test/victim.c
test/victim.c: In function ‘main’:
test/victim.c:8: error: ‘PR_SET_PTRACER’ undeclared (first use in this function)
test/victim.c:8: error: (Each undeclared identifier is reported only once
test/victim.c:8: error: for each function it appears in.)
test/victim.c:8: error: ‘PR_SET_PTRACER_ANY’ undeclared (first use in this function)
make: *** [test/victim.o] Error 1

I suppose PR_SET_PTRACER was added in kernel 3.4. Not sure what can be done about this, but if nothing else, document it?

nelhage commented 8 years ago

The PR_SET_PTRACER code should only be needed under yama (which is to say, ~recent Ubuntu kernels, effectively). Does https://github.com/nelhage/reptyr/pull/70 do anything good?

scop commented 8 years ago

Yes, that fixes the compilation. The actual tests still end up failing:

$ make test
python test/basic.py
python test/tty-steal.py
Traceback (most recent call last):
  File "test/tty-steal.py", line 12, in <module>
    prctl.set_ptracer(PR_SET_PTRACER_ANY)
AttributeError: 'module' object has no attribute 'set_ptracer'
make: *** [test] Error 1

But I suppose that prctl stuff isn't needed either? If so, would be nice if the prctl python module would be required only wherever its set_ptracer would do any good.

nelhage commented 8 years ago

Just pushed another commit on that branch – does that do any good?

scop commented 8 years ago

It does, however of course the prctl python module is still required even if it doesn't end up being used.

nelhage commented 8 years ago

Yeah – is that problematic in some way? I'm not sure of an easy way to check whether it's necessary. I could grub around for the yama sysctls, but that seems unsatisfactory.

scop commented 8 years ago

python-prctl is not available (in packaged form) in Fedora or EPEL so I'm going to have to patch it out. Not a big problem. But if you still want to consider doing something about this and autodetection is messy/unsatisfactory, perhaps do the Python prctl stuff only if it's not disabled via an environment variable, like SKIP_PRCTL=1 make test and

if not os.environ.get("SKIP_PRCTL"):
    import prctl
    # rest of that stuff
nelhage commented 8 years ago

Got it. Just pushed a change that will just swallow the ImportError with a warning message. That passes tests on my CentOS 5 VM, and I think should also work on Travis. I'll merge assuming it does.