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