EDIT (MADE PROGRESS) :멀티 스레드 응용 프로그램을 ptrace하는 방법은 무엇입니까?
vsftpd 데몬을 ptrace하려고합니다. 나는 데몬에 붙어있는 다음 코드를 가지고있다. 그런 다음 첫 번째 생성 된 프로세스의 PID를 성공적으로 표시합니다. 그러나이 생성 된 프로세스의 하위 항목에 대해 2,3,3 ... PID를 반환합니다. 프로그램이 생성 된 프로세스의 종료를 catch하지만 내가 가까이에 있다고 생각하게 만듭니다.
아이디어가 있으십니까?
void * trace_process(void * pid){
pid_t child = atoi((char *) pid);
long orig_eax, eax;
int status;
int callmade = FALSE;
long opt = PTRACE_O_TRACEFORK;
long newpid;
long trace = ptrace(PTRACE_ATTACH,child,NULL,NULL);
ptrace(PTRACE_SETOPTIONS,child,NULL,opt);
if(trace == FALSE)
printf("Attached to %d\n",child);
while(TRUE) {
child = waitpid(-1, &status, __WALL);
if (status >> 16 == PTRACE_EVENT_FORK) {
ptrace(PTRACE_GETEVENTMSG, child, NULL, (long) &newpid);
ptrace(PTRACE_SYSCALL, newpid, NULL, NULL);
printf("Attached to offspring %ld\n", newpid);
}
else{
if(WIFEXITED(status))
printf("Child %d exited\n", child);
}
ptrace(PTRACE_SYSCALL,child, NULL, NULL);
}
}
샘플 출력 :
Attached to 2015 // daemon
Attached to offspring 5302 // new connection handler
Attached to offspring 2 // should be authenticator
Child 5303 exited // authenticator exiting on successful login
Attached to offspring 3 // should be process serving files
Child 5304 exited // logout: process serving files
Child 5302 exited // connection closed
Attached to offspring 5305 // new connection handler
Attached to offspring 2 // ... repeat
Child 5306 exited
Attached to offspring 3
Child 5307 exited
Child 5305 exited
당신이 strace를 (1)'로 봤어'전혀? –
@ Nikolai N Fetissov 지금 strace 소스를 조사 중입니다. 그렇게하기가 쉽지는 않습니다. 더 흥미로운 점은 내가 strace를 vsftpd의 pid에 연결했고 ncftp를 사용하여 로그인하면 "연결 중 ..."대화 상자에 멈추는 것입니다. strace에서 Ctrl-c를 누르면 제대로 작동합니다. strace도 실제로 작동하지 않습니다. – ofosho
'-f' 옵션을 사용 했습니까? –