Reset errno after EINTR
This commit is contained in:
		| @@ -207,9 +207,11 @@ static void *cache_thread(void *arg) { | |||||||
|         pthread_testcancel(); |         pthread_testcancel(); | ||||||
|         if (sem_wait(&sem_used) != 0) { |         if (sem_wait(&sem_used) != 0) { | ||||||
|             if (errno == EINTR) { |             if (errno == EINTR) { | ||||||
|  |                 errno = 0; | ||||||
|                 continue; |                 continue; | ||||||
|             } else { |             } else { | ||||||
|                 error("Unable to lock semaphore"); |                 error("Unable to lock semaphore"); | ||||||
|  |                 errno = 0; | ||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -294,9 +296,11 @@ static void cache_mark_entry_dirty(cache_entry_t *entry) { | |||||||
|     try_again_free: |     try_again_free: | ||||||
|     if (sem_wait(&sem_free) != 0) { |     if (sem_wait(&sem_free) != 0) { | ||||||
|         if (errno == EINTR) { |         if (errno == EINTR) { | ||||||
|  |             errno = 0; | ||||||
|             goto try_again_free; |             goto try_again_free; | ||||||
|         } else { |         } else { | ||||||
|             error("Unable to lock semaphore"); |             error("Unable to lock semaphore"); | ||||||
|  |             errno = 0; | ||||||
|         } |         } | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| @@ -305,9 +309,11 @@ static void cache_mark_entry_dirty(cache_entry_t *entry) { | |||||||
|     try_again_lock: |     try_again_lock: | ||||||
|     if (sem_wait(&sem_lock) != 0) { |     if (sem_wait(&sem_lock) != 0) { | ||||||
|         if (errno == EINTR) { |         if (errno == EINTR) { | ||||||
|  |             errno = 0; | ||||||
|             goto try_again_lock; |             goto try_again_lock; | ||||||
|         } else { |         } else { | ||||||
|             error("Unable to lock semaphore"); |             error("Unable to lock semaphore"); | ||||||
|  |             errno = 0; | ||||||
|         } |         } | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -54,6 +54,7 @@ int mpmc_queue(mpmc_t *ctx, void *obj) { | |||||||
|     try_again_1: |     try_again_1: | ||||||
|     if (sem_wait(&ctx->free) != 0) { |     if (sem_wait(&ctx->free) != 0) { | ||||||
|         if (errno == EINTR) { |         if (errno == EINTR) { | ||||||
|  |             errno = 0; | ||||||
|             goto try_again_1; |             goto try_again_1; | ||||||
|         } else { |         } else { | ||||||
|             return -1; |             return -1; | ||||||
| @@ -64,6 +65,7 @@ int mpmc_queue(mpmc_t *ctx, void *obj) { | |||||||
|     try_again_2: |     try_again_2: | ||||||
|     if (sem_wait(&ctx->lck_rd) != 0) { |     if (sem_wait(&ctx->lck_rd) != 0) { | ||||||
|         if (errno == EINTR) { |         if (errno == EINTR) { | ||||||
|  |             errno = 0; | ||||||
|             goto try_again_2; |             goto try_again_2; | ||||||
|         } else { |         } else { | ||||||
|             sem_post(&ctx->free); |             sem_post(&ctx->free); | ||||||
| @@ -92,9 +94,11 @@ static void *mpmc_worker(void *arg) { | |||||||
|         // wait for buffer to be filled |         // wait for buffer to be filled | ||||||
|         if (sem_wait(&ctx->used) != 0) { |         if (sem_wait(&ctx->used) != 0) { | ||||||
|             if (errno == EINTR) { |             if (errno == EINTR) { | ||||||
|  |                 errno = 0; | ||||||
|                 continue; |                 continue; | ||||||
|             } else { |             } else { | ||||||
|                 critical("Unable to lock semaphore"); |                 critical("Unable to lock semaphore"); | ||||||
|  |                 errno = 0; | ||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -102,10 +106,12 @@ static void *mpmc_worker(void *arg) { | |||||||
|         // lock wr field |         // lock wr field | ||||||
|         if (sem_wait(&ctx->lck_wr) != 0) { |         if (sem_wait(&ctx->lck_wr) != 0) { | ||||||
|             if (errno == EINTR) { |             if (errno == EINTR) { | ||||||
|  |                 errno = 0; | ||||||
|                 sem_post(&ctx->used); |                 sem_post(&ctx->used); | ||||||
|                 continue; |                 continue; | ||||||
|             } else { |             } else { | ||||||
|                 critical("Unable to lock semaphore"); |                 critical("Unable to lock semaphore"); | ||||||
|  |                 errno = 0; | ||||||
|                 sem_post(&ctx->used); |                 sem_post(&ctx->used); | ||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -93,9 +93,11 @@ void logmsgf(log_lvl_t level, const char *restrict format, ...) { | |||||||
|         try_again_free: |         try_again_free: | ||||||
|         if (sem_wait(&sem_buf_free) != 0) { |         if (sem_wait(&sem_buf_free) != 0) { | ||||||
|             if (errno == EINTR) { |             if (errno == EINTR) { | ||||||
|  |                 errno = 0; | ||||||
|                 goto try_again_free; |                 goto try_again_free; | ||||||
|             } else { |             } else { | ||||||
|                 err("Unable to lock semaphore"); |                 err("Unable to lock semaphore"); | ||||||
|  |                 errno = 0; | ||||||
|             } |             } | ||||||
|             // cleanup |             // cleanup | ||||||
|             va_end(args); |             va_end(args); | ||||||
| @@ -106,9 +108,11 @@ void logmsgf(log_lvl_t level, const char *restrict format, ...) { | |||||||
|         try_again_buf: |         try_again_buf: | ||||||
|         if (sem_wait(&sem_buf) != 0) { |         if (sem_wait(&sem_buf) != 0) { | ||||||
|             if (errno == EINTR) { |             if (errno == EINTR) { | ||||||
|  |                 errno = 0; | ||||||
|                 goto try_again_buf; |                 goto try_again_buf; | ||||||
|             } else { |             } else { | ||||||
|                 err("Unable to lock semaphore"); |                 err("Unable to lock semaphore"); | ||||||
|  |                 errno = 0; | ||||||
|             } |             } | ||||||
|             // cleanup |             // cleanup | ||||||
|             sem_post(&sem_buf_free); |             sem_post(&sem_buf_free); | ||||||
| @@ -204,9 +208,11 @@ static void *logger_thread(void *arg) { | |||||||
|         // wait for buffer to be filled |         // wait for buffer to be filled | ||||||
|         if (sem_wait(&sem_buf_used) != 0) { |         if (sem_wait(&sem_buf_used) != 0) { | ||||||
|             if (errno == EINTR) { |             if (errno == EINTR) { | ||||||
|  |                 errno = 0; | ||||||
|                 continue; |                 continue; | ||||||
|             } else { |             } else { | ||||||
|                 err("Unable to lock semaphore"); |                 err("Unable to lock semaphore"); | ||||||
|  |                 errno = 0; | ||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user