Merge remote-tracking branch 'origin/fastpath'

* origin/fastpath:
  and remove superflous print.
  add testcase for subrecords and events add missing binary testcase (Baseline is in master, testcase is missing for some reason) make error output for nonmatching event types much more verbose
  Add more error handling for close() calls.
  add testcase for subrecords to input framework tests
This commit is contained in:
Robin Sommer 2012-07-26 14:33:21 -07:00
commit 951444ee73
15 changed files with 294 additions and 22 deletions

View file

@ -722,7 +722,7 @@ void init_random_seed(uint32 seed, const char* read_file, const char* write_file
{
int amt = read(fd, buf + pos,
sizeof(uint32) * (bufsiz - pos));
close(fd);
safe_close(fd);
if ( amt > 0 )
pos += amt / sizeof(uint32);
@ -1204,7 +1204,7 @@ void _set_processing_status(const char* status)
len -= n;
}
close(fd);
safe_close(fd);
errno = old_errno;
}
@ -1353,6 +1353,31 @@ bool safe_write(int fd, const char* data, int len)
return true;
}
void safe_close(int fd)
{
/*
* Failure cases of close(2) are ...
* EBADF: Indicative of programming logic error that needs to be fixed, we
* should always be attempting to close a valid file descriptor.
* EINTR: Ignore signal interruptions, most implementations will actually
* reclaim the open descriptor and POSIX standard doesn't leave many
* options by declaring the state of the descriptor as "unspecified".
* Attempting to inspect actual state or re-attempt close() is not
* thread safe.
* EIO: Again the state of descriptor is "unspecified", but don't recover
* from an I/O error, safe_write() won't either.
*
* Note that we don't use the reporter here to allow use from different threads.
*/
if ( close(fd) < 0 && errno != EINTR )
{
char buf[128];
strerror_r(errno, buf, sizeof(buf));
fprintf(stderr, "safe_close error %d: %s\n", errno, buf);
abort();
}
}
void out_of_memory(const char* where)
{
reporter->FatalError("out of memory in %s.\n", where);