more error checking around opening /proc/pid/mem

develop
Petr Mrázek 2009-10-29 17:40:39 +00:00
parent 42e0d2a1d5
commit 9db0d5490a
1 changed files with 18 additions and 6 deletions

@ -117,12 +117,24 @@ bool Process::attach()
} }
cout << "Managed to attach to pid " << my_handle << endl; cout << "Managed to attach to pid " << my_handle << endl;
attached = true; int proc_pid_mem = open(memFile.c_str(),O_RDONLY);
g_pProcess = this; if(proc_pid_mem == -1)
g_ProcessHandle = my_handle; {
g_ProcessMemFile = open(memFile.c_str(),O_RDONLY); ptrace(PTRACE_DETACH, my_handle, NULL, NULL);
cout << "Attach_after_opening /proc/PID/mem" << endl; cerr << "couldn't open /proc/" << my_handle << "/mem" << endl;
return true; // we are attached perror("open(memFile.c_str(),O_RDONLY)");
return false;
}
else
{
attached = true;
g_pProcess = this;
g_ProcessHandle = my_handle;
g_ProcessMemFile = proc_pid_mem;
cout << "Attach_after_opening /proc/PID/mem" << endl;
return true; // we are attached
}
} }
bool Process::detach() bool Process::detach()