Minor tweak in the VG_(poll) syscall and callers: have a way to show

the error in case the poll syscall unexpectedly fails.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13748
This commit is contained in:
Philippe Waroquiers 2013-12-05 22:10:55 +00:00
parent 45c11d4804
commit b330c9fa31
3 changed files with 41 additions and 25 deletions

View File

@ -157,22 +157,27 @@ int poll_cond (short revents)
/* Ensures we have a valid write file descriptor.
Returns 1 if we have a valid write file descriptor,
0 if the write fd could not be opened. */
0 if the write fd is not valid/cannot be opened. */
static
int ensure_write_remote_desc(void)
{
struct vki_pollfd write_remote_desc_ok;
int ret;
SysRes ret;
if (write_remote_desc != INVALID_DESCRIPTOR) {
write_remote_desc_ok.fd = write_remote_desc;
write_remote_desc_ok.events = VKI_POLLOUT;
write_remote_desc_ok.revents = 0;
ret = VG_(poll)(&write_remote_desc_ok, 1, 0);
if (ret && poll_cond(write_remote_desc_ok.revents)) {
dlog(1, "POLLcond %d closing write_remote_desc %d\n",
write_remote_desc_ok.revents, write_remote_desc);
VG_(close) (write_remote_desc);
write_remote_desc = INVALID_DESCRIPTOR;
if (sr_isError(ret)
|| (sr_Res(ret) > 0 && poll_cond(write_remote_desc_ok.revents))) {
if (sr_isError(ret)) {
sr_perror(ret, "ensure_write_remote_desc: poll error\n");
} else {
dlog(0, "POLLcond %d closing write_remote_desc %d\n",
write_remote_desc_ok.revents, write_remote_desc);
}
VG_(close) (write_remote_desc);
write_remote_desc = INVALID_DESCRIPTOR;
}
}
if (write_remote_desc == INVALID_DESCRIPTOR) {
@ -439,10 +444,10 @@ void error_poll_cond(void)
counter values maintained in shared memory by vgdb. */
int remote_desc_activity(const char *msg)
{
int ret;
int retval;
SysRes ret;
const int looking_at = shared->written_by_vgdb;
if (shared->seen_by_valgrind == looking_at)
// if (last_looked_cntr == looking_at)
return 0;
if (remote_desc == INVALID_DESCRIPTOR)
return 0;
@ -450,23 +455,30 @@ int remote_desc_activity(const char *msg)
/* poll the remote desc */
remote_desc_pollfdread_activity.revents = 0;
ret = VG_(poll) (&remote_desc_pollfdread_activity, 1, 0);
if (ret && poll_cond(remote_desc_pollfdread_activity.revents)) {
dlog(1, "POLLcond %d remote_desc_pollfdread %d\n",
remote_desc_pollfdread_activity.revents, remote_desc);
error_poll_cond();
ret = 2;
if (sr_isError(ret)
|| (sr_Res(ret) && poll_cond(remote_desc_pollfdread_activity.revents))) {
if (sr_isError(ret)) {
sr_perror(ret, "remote_desc_activity: poll error\n");
} else {
dlog(0, "POLLcond %d remote_desc_pollfdread %d\n",
remote_desc_pollfdread_activity.revents, remote_desc);
error_poll_cond();
}
retval = 2;
} else {
retval = sr_Res(ret);
}
dlog(1,
"remote_desc_activity %s %d last_looked_cntr %d looking_at %d"
" shared->written_by_vgdb %d shared->seen_by_valgrind %d"
" ret %d\n",
" retval %d\n",
msg, remote_desc, last_looked_cntr, looking_at,
shared->written_by_vgdb, shared->seen_by_valgrind,
ret);
retval);
/* if no error from poll, indicate we have "seen" up to looking_at */
if (ret != 2)
if (retval == 1)
last_looked_cntr = looking_at;
return ret;
return retval;
}
/* Convert hex digit A to a number. */
@ -803,7 +815,7 @@ int readchar (int single)
static unsigned char buf[PBUFSIZ];
static int bufcnt = 0;
static unsigned char *bufp;
int ret;
SysRes ret;
if (bufcnt-- > 0)
return *bufp++;
@ -815,9 +827,13 @@ int readchar (int single)
wait for some characters to arrive */
remote_desc_pollfdread_activity.revents = 0;
ret = VG_(poll)(&remote_desc_pollfdread_activity, 1, -1);
if (ret != 1) {
dlog(0, "readchar: poll got %d\n", ret);
return -1;
if (sr_isError(ret) || sr_Res(ret) != 1) {
if (sr_isError(ret)) {
sr_perror(ret, "readchar: poll error\n");
} else {
dlog(0, "readchar: poll got %d, expecting 1\n", (int)sr_Res(ret));
}
return -1;
}
if (single)
bufcnt = VG_(read) (remote_desc, buf, 1);

View File

@ -456,7 +456,7 @@ Bool VG_(get_startup_wd) ( HChar* buf, SizeT size )
return True;
}
Int VG_(poll) (struct vki_pollfd *fds, Int nfds, Int timeout)
SysRes VG_(poll) (struct vki_pollfd *fds, Int nfds, Int timeout)
{
SysRes res;
# if defined(VGO_linux)
@ -466,7 +466,7 @@ Int VG_(poll) (struct vki_pollfd *fds, Int nfds, Int timeout)
# else
# error "Unknown OS"
# endif
return sr_isError(res) ? -1 : sr_Res(res);
return res;
}

View File

@ -89,7 +89,7 @@ extern SysRes VG_(dup2) ( Int oldfd, Int newfd );
extern Int VG_(rename) ( const HChar* old_name, const HChar* new_name );
extern Int VG_(unlink) ( const HChar* file_name );
extern Int VG_(poll) (struct vki_pollfd *fds, Int nfds, Int timeout);
extern SysRes VG_(poll) (struct vki_pollfd *fds, Int nfds, Int timeout);
extern Int VG_(readlink)( const HChar* path, HChar* buf, UInt bufsize );
extern Int VG_(getdents)( Int fd, struct vki_dirent *dirp, UInt count );