Saggi Mizrahi has uploaded a new change for review.
Change subject: cpopen: Fix signal handling in sync points
......................................................................
cpopen: Fix signal handling in sync points
Change-Id: Id2883091c377c1e4ff9f69b87fc137326b583ab8
Signed-off-by: Saggi Mizrahi <smizrahi(a)redhat.com>
---
M lib/cpopen/cpopen.c
1 file changed, 36 insertions(+), 21 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/65/15165/1
diff --git a/lib/cpopen/cpopen.c b/lib/cpopen/cpopen.c
index ca39406..620bf1e 100644
--- a/lib/cpopen/cpopen.c
+++ b/lib/cpopen/cpopen.c
@@ -64,6 +64,32 @@
return rv;
}
+/* Just like close() but retries on interrupt and tries to fill the buffer */
+static int
+safeRead(int fd, void *buff, size_t count) {
+ size_t bread = 0;
+ char* cbuff = buff;
+ int rv = 0;
+ while (bread < count) {
+ rv = read(fd, cbuff + bread, count - bread);
+ bread += rv;
+ /* EOF */
+ if (rv == 0) {
+ return bread;
+ } else if (rv < 0) {
+ switch (errno) {
+ case EINTR:
+ case EAGAIN:
+ break;
+ default:
+ return rv;
+ }
+ }
+ }
+
+ return bread;
+}
+
static int
setCloseOnExec(int fd) {
int flags;
@@ -311,35 +337,24 @@
if (deathSignal) {
/* death signal sync point */
- while (1) {
- rv = read(errnofd[0], &childErrno, sizeof(int));
- if (rv < 0) {
- switch (errno) {
- case EINTR:
- case EAGAIN:
- break;
- default:
- PyErr_SetString(PyExc_OSError, strerror(childErrno));
- goto fail;
-
- }
- } else if (rv < sizeof(int)) {
- PyErr_SetString(PyExc_OSError, strerror(childErrno));
- goto fail;
- }
- break;
- }
-
- if (childErrno != 0) {
+ rv = safeRead(errnofd[0], &childErrno, sizeof(int));
+ if (rv != sizeof(int)) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ goto fail;
+ } else if (childErrno != 0) {
PyErr_SetString(PyExc_OSError, strerror(childErrno));
goto fail;
}
}
/* error sync point */
- if (read(errnofd[0], &childErrno, sizeof(int)) == sizeof(int)) {
+ rv = safeRead(errnofd[0], &childErrno, sizeof(int));
+ if (rv == sizeof(int)) {
PyErr_SetString(PyExc_OSError, strerror(childErrno));
goto fail;
+ } else if (rv < 0) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ goto fail;
}
safeClose(errnofd[0]);
--
To view, visit
http://gerrit.ovirt.org/15165
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id2883091c377c1e4ff9f69b87fc137326b583ab8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Saggi Mizrahi <smizrahi(a)redhat.com>