fix crash when write to parent fails
This commit is contained in:
@@ -116,32 +116,39 @@ static int retried_write( int fd, const void *buf, size_t count )
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parent_write(int to_child, const void *p, size_t size)
|
static bool parent_write(int to_child, const void *p, size_t size)
|
||||||
{
|
{
|
||||||
size_t ret = retried_write(to_child, p, size);
|
size_t ret = retried_write(to_child, p, size);
|
||||||
if(ret != size)
|
if(ret != size)
|
||||||
{
|
{
|
||||||
safe_print(fileno(stderr), "Unexpected write() result (", strerror(errno), ")\n", NULL);
|
safe_print(fileno(stderr), "Unexpected write() result (", strerror(errno), ")\n", NULL);
|
||||||
exit(1);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parent_process( int to_child, const CrashData *crash )
|
static void parent_process( int to_child, const CrashData *crash )
|
||||||
{
|
{
|
||||||
/* 1. Write the CrashData. */
|
/* 1. Write the CrashData. */
|
||||||
parent_write(to_child, crash, sizeof(CrashData));
|
if( !parent_write(to_child, crash, sizeof(CrashData)) )
|
||||||
|
return;
|
||||||
|
|
||||||
/* 2. Write info. */
|
/* 2. Write info. */
|
||||||
const char *p = RageLog::GetInfo();
|
const char *p = RageLog::GetInfo();
|
||||||
int size = strlen(p)+1;
|
int size = strlen(p)+1;
|
||||||
parent_write(to_child, &size, sizeof(size));
|
if( !parent_write(to_child, &size, sizeof(size)) )
|
||||||
parent_write(to_child, p, size);
|
return;
|
||||||
|
if( !parent_write(to_child, p, size) )
|
||||||
|
return;
|
||||||
|
|
||||||
/* 3. Write AdditionalLog. */
|
/* 3. Write AdditionalLog. */
|
||||||
p = RageLog::GetAdditionalLog();
|
p = RageLog::GetAdditionalLog();
|
||||||
size = strlen(p)+1;
|
size = strlen(p)+1;
|
||||||
parent_write(to_child, &size, sizeof(size));
|
if( !parent_write(to_child, &size, sizeof(size)) )
|
||||||
parent_write(to_child, p, size);
|
return;
|
||||||
|
if( !parent_write(to_child, p, size) )
|
||||||
|
return;
|
||||||
|
|
||||||
/* 4. Write RecentLogs. */
|
/* 4. Write RecentLogs. */
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
@@ -153,23 +160,28 @@ static void parent_process( int to_child, const CrashData *crash )
|
|||||||
for( int i = 0; i < cnt; ++i )
|
for( int i = 0; i < cnt; ++i )
|
||||||
{
|
{
|
||||||
size = strlen(ps[i])+1;
|
size = strlen(ps[i])+1;
|
||||||
parent_write(to_child, &size, sizeof(size));
|
if( parent_write(to_child, &size, sizeof(size)) )
|
||||||
parent_write(to_child, ps[i], size);
|
return;
|
||||||
|
if( parent_write(to_child, ps[i], size) )
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 5. Write CHECKPOINTs. */
|
/* 5. Write CHECKPOINTs. */
|
||||||
p = Checkpoints::GetLogs("\n");
|
p = Checkpoints::GetLogs("\n");
|
||||||
size = strlen(p)+1;
|
size = strlen(p)+1;
|
||||||
parent_write(to_child, &size, sizeof(size));
|
if( !parent_write(to_child, &size, sizeof(size)) )
|
||||||
parent_write(to_child, p, size);
|
return;
|
||||||
|
|
||||||
|
if( !parent_write(to_child, p, size) )
|
||||||
|
return;
|
||||||
|
|
||||||
/* 6. Write the crashed thread's name. */
|
/* 6. Write the crashed thread's name. */
|
||||||
p = RageThread::GetCurThreadName();
|
p = RageThread::GetCurThreadName();
|
||||||
size = strlen(p)+1;
|
size = strlen(p)+1;
|
||||||
parent_write(to_child, &size, sizeof(size));
|
if( !parent_write(to_child, &size, sizeof(size)) )
|
||||||
parent_write(to_child, p, size);
|
return;
|
||||||
|
if( !parent_write(to_child, p, size) )
|
||||||
close(to_child);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -341,6 +353,8 @@ static void RunCrashHandler( const CrashData *crash )
|
|||||||
{
|
{
|
||||||
close(fds[0]);
|
close(fds[0]);
|
||||||
parent_process( fds[1], crash );
|
parent_process( fds[1], crash );
|
||||||
|
close( fds[1] );
|
||||||
|
|
||||||
int status = 0;
|
int status = 0;
|
||||||
waitpid( childpid, &status, 0 );
|
waitpid( childpid, &status, 0 );
|
||||||
if( WIFSIGNALED(status) )
|
if( WIFSIGNALED(status) )
|
||||||
|
|||||||
Reference in New Issue
Block a user