aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2018-09-26 21:52:17 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2018-09-26 21:52:17 +0200
commit8ee5d4b415403d57a0669be5fa7605491b988c74 (patch)
tree348e2ce9cf4a3cbc03bb900c7331a3dd09c52991
parentca925e8b5231d96f93b1b8513b9348fdec8c1071 (diff)
downloadlibrb-8ee5d4b415403d57a0669be5fa7605491b988c74.tar.gz
librb-8ee5d4b415403d57a0669be5fa7605491b988c74.tar.bz2
librb-8ee5d4b415403d57a0669be5fa7605491b988c74.zip
fix: posix function may return EINTR instead of ECANCELED after rb_stop()
-rw-r--r--rb.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/rb.c b/rb.c
index 273c3d3..026a761 100644
--- a/rb.c
+++ b/rb.c
@@ -939,6 +939,12 @@ static long rb_recvt
if (sact == -1)
{
trace(("e/select() %s", strerror(errno)));
+
+ if (rb->force_exit == 1)
+ {
+ errno = ECANCELED;
+ }
+
pthread_mutex_unlock(&rb->lock);
trace(("i/rb unlock"));
return -1;
@@ -1441,10 +1447,23 @@ long rb_sendt
if (sact == -1)
{
trace(("e/select() %s", strerror(errno)));
+
+ if (rb->force_exit == 1)
+ {
+ /*
+ * if select was interrupted by us, overwrite errno to
+ * ECANCELED, or else it might be EINTR, which may be
+ * missleading for user.
+ */
+
+ errno = ECANCELED;
+ }
+
pthread_mutex_unlock(&rb->lock);
trace(("i/rb unlock"));
pthread_mutex_unlock(&rb->wlock);
trace(("i/write unlock"));
+
return -1;
}