Hi!
I am having some troubles with PTRACE_TRACEME.
1 2 3 4 5 6 7
|
#include <sys/ptrace.h>
#include <sys/types.h>
if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
printf("being ptraced\n");
return 1;
}
|
With that in place. I cannot strace. I get this error:
1 2 3 4 5 6
|
ptrace(PTRACE_TRACEME, 0, 0, 0) = -1 EPERM (Operation not permitted)
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 5), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9b5ec18000
write(1, "being ptraced\n", 14being ptraced
) = 14
exit_group(1)
|
And that is correct :) But my program just stops, halfway through. In my ubuntu i just get this STOPPED error:
[1]+ Stopped
If I comment out the ptrace bit, my program is running just fine.
Is this somehing ptrace would do?
It is not very complicated. Just some simple if file exists, if some strings in file == WORD. Then run a shell command, and another.
With the ptrace code in place just the first shell command is executed, and the Stopped error comes after it completes.
I can comment out the second shell command, and I still get the Stopped error.
I have tried with several ways to run shell commands but both give me the same result.
Any ideas? Push me in the right direction.
(I have tried to build and run on both ubuntu and Red Hat, v5 and 6, same results).
--Torgeir