mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Check and handle select() errors from waitsocket().
This commit is contained in:
parent
7ac12d84d0
commit
b667125065
@ -76,7 +76,6 @@ static int
|
|||||||
waitsocket(int socket_fd, LIBSSH2_SESSION * session)
|
waitsocket(int socket_fd, LIBSSH2_SESSION * session)
|
||||||
{
|
{
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
int rc;
|
|
||||||
fd_set fd;
|
fd_set fd;
|
||||||
fd_set *writefd = NULL;
|
fd_set *writefd = NULL;
|
||||||
fd_set *readfd = NULL;
|
fd_set *readfd = NULL;
|
||||||
@ -98,9 +97,7 @@ waitsocket(int socket_fd, LIBSSH2_SESSION * session)
|
|||||||
if (dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
if (dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||||
writefd = &fd;
|
writefd = &fd;
|
||||||
|
|
||||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
return select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this function is the layer that manipulates the ssh channel itself
|
/* this function is the layer that manipulates the ssh channel itself
|
||||||
@ -131,7 +128,11 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status,
|
|||||||
while ((channel = libssh2_channel_open_session(session)) == NULL &&
|
while ((channel = libssh2_channel_open_session(session)) == NULL &&
|
||||||
libssh2_session_last_error(session, NULL, NULL, 0) ==
|
libssh2_session_last_error(session, NULL, NULL, 0) ==
|
||||||
LIBSSH2_ERROR_EAGAIN) {
|
LIBSSH2_ERROR_EAGAIN) {
|
||||||
waitsocket(sock, session);
|
if (waitsocket(sock, session) < 0 && errno != EINTR) {
|
||||||
|
virReportSystemError(errno, "%s",
|
||||||
|
_("unable to wait on libssh2 socket"));
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel == NULL) {
|
if (channel == NULL) {
|
||||||
@ -140,7 +141,11 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status,
|
|||||||
|
|
||||||
while ((rc = libssh2_channel_exec(channel, cmd)) ==
|
while ((rc = libssh2_channel_exec(channel, cmd)) ==
|
||||||
LIBSSH2_ERROR_EAGAIN) {
|
LIBSSH2_ERROR_EAGAIN) {
|
||||||
waitsocket(sock, session);
|
if (waitsocket(sock, session) < 0 && errno != EINTR) {
|
||||||
|
virReportSystemError(errno, "%s",
|
||||||
|
_("unable to wait on libssh2 socket"));
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
@ -161,7 +166,11 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status,
|
|||||||
/* this is due to blocking that would occur otherwise so we loop on
|
/* this is due to blocking that would occur otherwise so we loop on
|
||||||
* this condition */
|
* this condition */
|
||||||
if (rc == LIBSSH2_ERROR_EAGAIN) {
|
if (rc == LIBSSH2_ERROR_EAGAIN) {
|
||||||
waitsocket(sock, session);
|
if (waitsocket(sock, session) < 0 && errno != EINTR) {
|
||||||
|
virReportSystemError(errno, "%s",
|
||||||
|
_("unable to wait on libssh2 socket"));
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -170,7 +179,11 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status,
|
|||||||
exitcode = 127;
|
exitcode = 127;
|
||||||
|
|
||||||
while ((rc = libssh2_channel_close(channel)) == LIBSSH2_ERROR_EAGAIN) {
|
while ((rc = libssh2_channel_close(channel)) == LIBSSH2_ERROR_EAGAIN) {
|
||||||
waitsocket(sock, session);
|
if (waitsocket(sock, session) < 0 && errno != EINTR) {
|
||||||
|
virReportSystemError(errno, "%s",
|
||||||
|
_("unable to wait on libssh2 socket"));
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
@ -735,7 +748,11 @@ phypUUIDTable_Pull(virConnectPtr conn)
|
|||||||
LIBSSH2_ERROR_EAGAIN) {
|
LIBSSH2_ERROR_EAGAIN) {
|
||||||
goto err;
|
goto err;
|
||||||
} else {
|
} else {
|
||||||
waitsocket(sock, session);
|
if (waitsocket(sock, session) < 0 && errno != EINTR) {
|
||||||
|
virReportSystemError(errno, "%s",
|
||||||
|
_("unable to wait on libssh2 socket"));
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (!channel);
|
} while (!channel);
|
||||||
@ -769,7 +786,12 @@ phypUUIDTable_Pull(virConnectPtr conn)
|
|||||||
/* this is due to blocking that would occur otherwise
|
/* this is due to blocking that would occur otherwise
|
||||||
* so we loop on this condition */
|
* so we loop on this condition */
|
||||||
|
|
||||||
waitsocket(sock, session); /* now we wait */
|
/* now we wait */
|
||||||
|
if (waitsocket(sock, session) < 0 && errno != EINTR) {
|
||||||
|
virReportSystemError(errno, "%s",
|
||||||
|
_("unable to wait on libssh2 socket"));
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user