Check for more interrupted conditions in util.c and handle them gracefully.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
diff --git a/util.c b/util.c
index f664cf0..1cda5f0 100644
--- a/util.c
+++ b/util.c
@@ -2582,19 +2582,24 @@ void _cgsem_post(cgsem_t *cgsem, const char *file, const char *func, const int l
const char buf = 1;
int ret;
+retry:
ret = write(cgsem->pipefd[1], &buf, 1);
if (unlikely(ret == 0))
applog(LOG_WARNING, "Failed to write errno=%d" IN_FMT_FFL, errno, file, func, line);
+ else if (unlikely(ret < 0 && interrupted))
+ goto retry;
}
void _cgsem_wait(cgsem_t *cgsem, const char *file, const char *func, const int line)
{
char buf;
int ret;
-
+retry:
ret = read(cgsem->pipefd[0], &buf, 1);
if (unlikely(ret == 0))
applog(LOG_WARNING, "Failed to read errno=%d" IN_FMT_FFL, errno, file, func, line);
+ else if (unlikely(ret < 0 && interrupted))
+ goto retry;
}
void cgsem_destroy(cgsem_t *cgsem)
@@ -2647,6 +2652,8 @@ void cgsem_reset(cgsem_t *cgsem)
ret = select(fd + 1, &rd, NULL, NULL, &timeout);
if (ret > 0)
ret = read(fd, &buf, 1);
+ else if (unlikely(ret < 0 && interrupted()))
+ ret = 1;
} while (ret > 0);
}
#else
@@ -2665,8 +2672,12 @@ void _cgsem_post(cgsem_t *cgsem, const char *file, const char *func, const int l
void _cgsem_wait(cgsem_t *cgsem, const char *file, const char *func, const int line)
{
- if (unlikely(sem_wait(cgsem)))
+retry:
+ if (unlikely(sem_wait(cgsem))) {
+ if (interrupted())
+ goto retry;
quitfrom(1, file, func, line, "Failed to sem_wait errno=%d cgsem=0x%p", errno, cgsem);
+ }
}
int _cgsem_mswait(cgsem_t *cgsem, int ms, const char *file, const char *func, const int line)
@@ -2678,12 +2689,15 @@ int _cgsem_mswait(cgsem_t *cgsem, int ms, const char *file, const char *func, co
cgtime(&tv_now);
timeval_to_spec(&ts_now, &tv_now);
ms_to_timespec(&abs_timeout, ms);
+retry:
timeraddspec(&abs_timeout, &ts_now);
ret = sem_timedwait(cgsem, &abs_timeout);
if (ret) {
if (likely(sock_timeout()))
return ETIMEDOUT;
+ if (interrupted())
+ goto retry;
quitfrom(1, file, func, line, "Failed to sem_timedwait errno=%d cgsem=0x%p", errno, cgsem);
}
return 0;
@@ -2695,6 +2709,8 @@ void cgsem_reset(cgsem_t *cgsem)
do {
ret = sem_trywait(cgsem);
+ if (unlikely(ret < 0 && interrupted()))
+ ret = 0;
} while (!ret);
}