summaryrefslogtreecommitdiff
path: root/src/syncevo/LocalTransportAgent.cpp
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2011-04-20 16:45:24 +0200
committerPatrick Ohly <patrick.ohly@intel.com>2011-04-20 16:47:24 +0200
commit6147f6f718c955914cf3c333ed3d3dad5029c9de (patch)
tree37c842fa40c3491b1a68ef0840a477977f6d8c73 /src/syncevo/LocalTransportAgent.cpp
parent2587fe93829c7df3a3249f202fd45ca7b74d554c (diff)
local sync: make a copy of errno before calling something which might overwrite it
Logging calls might end up calling functions which modify errno. Seen once where logging reported a "pipe error" and the following exception a "resource temporarily unavailable".
Diffstat (limited to 'src/syncevo/LocalTransportAgent.cpp')
-rw-r--r--src/syncevo/LocalTransportAgent.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/syncevo/LocalTransportAgent.cpp b/src/syncevo/LocalTransportAgent.cpp
index 2d69692e..de79c870 100644
--- a/src/syncevo/LocalTransportAgent.cpp
+++ b/src/syncevo/LocalTransportAgent.cpp
@@ -519,12 +519,13 @@ TransportAgent::Status LocalTransportAgent::writeMessage(int fd, Message::Type t
errno == EWOULDBLOCK) {
sent = 0;
} else {
+ int err = errno;
SE_LOG_DEBUG(NULL, NULL, "%s: sending %ld bytes failed: %s",
m_pid ? "parent" : "child",
(long)len,
- strerror(errno));
+ strerror(err));
SE_THROW_EXCEPTION(TransportException,
- StringPrintf("writev(): %s", strerror(errno)));
+ StringPrintf("writev(): %s", strerror(err)));
}
}
@@ -538,14 +539,16 @@ TransportAgent::Status LocalTransportAgent::writeMessage(int fd, Message::Type t
vec[1].iov_len -= part2;
break;
}
- default:
+ default: {
+ int err = errno;
SE_LOG_DEBUG(NULL, NULL, "%s: select errror: %s",
m_pid ? "parent" : "child",
- strerror(errno));
+ strerror(err));
SE_THROW_EXCEPTION(TransportException,
- StringPrintf("select(): %s", strerror(errno)));
+ StringPrintf("select(): %s", strerror(err)));
break;
}
+ }
} while (vec[1].iov_len);
SE_LOG_DEBUG(NULL, NULL, "%s: sending %ld bytes done",
@@ -657,18 +660,19 @@ TransportAgent::Status LocalTransportAgent::readMessage(int fd, Buffer &buffer,
(char *)buffer.m_message.get() + buffer.m_used,
buffer.m_size - buffer.m_used,
MSG_DONTWAIT);
+ int err = errno;
SE_LOG_DEBUG(NULL, NULL, "%s: received %ld: %s",
m_pid ? "parent" : "child",
(long)recvd,
- recvd < 0 ? strerror(errno) : "okay");
+ recvd < 0 ? strerror(err) : "okay");
if (recvd < 0) {
- if (errno == EAGAIN ||
- errno == EWOULDBLOCK) {
+ if (err == EAGAIN ||
+ err == EWOULDBLOCK) {
// try again
recvd = 0;
} else {
SE_THROW_EXCEPTION(TransportException,
- StringPrintf("message receive: %s", strerror(errno)));
+ StringPrintf("message receive: %s", strerror(err)));
}
} else if (!recvd) {
if (m_pid) {
@@ -686,14 +690,16 @@ TransportAgent::Status LocalTransportAgent::readMessage(int fd, Buffer &buffer,
buffer.m_used += recvd;
break;
}
- default:
+ default: {
+ int err = errno;
SE_LOG_DEBUG(NULL, NULL, "%s: select errror: %s",
m_pid ? "parent" : "child",
- strerror(errno));
+ strerror(err));
SE_THROW_EXCEPTION(TransportException,
- StringPrintf("select(): %s", strerror(errno)));
+ StringPrintf("select(): %s", strerror(err)));
break;
}
+ }
}
return ACTIVE;