more voodoo

develop
Petr Mrázek 2009-11-01 09:32:47 +00:00
parent 0853ce83ff
commit 2bee198946
2 changed files with 9 additions and 13 deletions

@ -89,23 +89,18 @@ bool isStopped(pid_t pid)
if(evil) if(evil)
{ {
// zlo means evil in czech. // zlo means evil in czech.
char zlo[256]; char zlo[64];
char zlo2[256];
char test; char test;
// read first line, ignore // read first line, ignore
fgets(zlo,256,evil); fgets(zlo,64,evil);
// read second line // read second line
fgets(zlo,256,evil); fgets(zlo,64,evil);
sscanf(zlo,"State: %c %s",&test, zlo2 ); sscanf(zlo,"State: %c",&test);
fclose(evil); fclose(evil);
if(test == 'T') if(test == 'T')
{
string crap = zlo2;
if(crap == "(stopped)")
{ {
return true; return true;
} }
}
return false; return false;
} }
cerr << "couldn't open file " << filename << "assuming process stopped" << endl; cerr << "couldn't open file " << filename << "assuming process stopped" << endl;
@ -127,7 +122,7 @@ bool Process::attach()
kill(my_handle,SIGSTOP); kill(my_handle,SIGSTOP);
while (!isStopped(my_handle)); while (!isStopped(my_handle));
} }
usleep(10000);
cout << "Attach: after conditional stop" << endl; cout << "Attach: after conditional stop" << endl;
// can we attach? // can we attach?
if (ptrace(PTRACE_ATTACH , my_handle, NULL, NULL) == -1) if (ptrace(PTRACE_ATTACH , my_handle, NULL, NULL) == -1)
@ -137,7 +132,7 @@ bool Process::attach()
cerr << "attach failed on pid " << my_handle << endl; cerr << "attach failed on pid " << my_handle << endl;
return false; return false;
} }
usleep(10000);
cout << "Attach: after ptrace" << endl; cout << "Attach: after ptrace" << endl;
/* /*
while(true) while(true)
@ -182,6 +177,7 @@ bool Process::attach()
bool Process::detach() bool Process::detach()
{ {
if(!attached) return false;
int result = 0; int result = 0;
cout << "detach: start" << endl; cout << "detach: start" << endl;
result = close(g_ProcessMemFile);// close /proc/PID/mem result = close(g_ProcessMemFile);// close /proc/PID/mem
@ -211,6 +207,7 @@ bool Process::detach()
// continue, wait for it to recover // continue, wait for it to recover
kill(my_handle,SIGCONT); kill(my_handle,SIGCONT);
while (isStopped(my_handle)); while (isStopped(my_handle));
usleep(10000);
// we finish // we finish
return true; return true;
} }

@ -64,7 +64,6 @@ int main (void)
time(&end); time(&end);
time_diff = difftime(end, start); time_diff = difftime(end, start);
DF.Detach();
cout << "attach tests done in " << time_diff << " seconds." << endl; cout << "attach tests done in " << time_diff << " seconds." << endl;
cout << "Press any key to continue" << endl; cout << "Press any key to continue" << endl;
cin.ignore(); cin.ignore();