Skip to content

Commit a3d7f86

Browse files
TedLyngmozuiderkwast
authored andcommitted
Fix assumptions that pthread functions set errno (#2526)
pthread functions return the error instead of setting errno. Fixes #2525 Signed-off-by: Ted Lyngmo <[email protected]>
1 parent 8c00586 commit a3d7f86

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/bio.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ void bioInit(void) {
142142
* responsible for. */
143143
for (j = 0; j < BIO_WORKER_NUM; j++) {
144144
void *arg = (void *)(unsigned long)j;
145-
if (pthread_create(&thread, &attr, bioProcessBackgroundJobs, arg) != 0) {
146-
serverLog(LL_WARNING, "Fatal: Can't initialize Background Jobs. Error message: %s", strerror(errno));
145+
int err = pthread_create(&thread, &attr, bioProcessBackgroundJobs, arg);
146+
if (err) {
147+
serverLog(LL_WARNING, "Fatal: Can't initialize Background Jobs. Error message: %s", strerror(err));
147148
exit(1);
148149
}
149150
bio_threads[j] = thread;
@@ -222,8 +223,9 @@ void *bioProcessBackgroundJobs(void *arg) {
222223
* receive the watchdog signal. */
223224
sigemptyset(&sigset);
224225
sigaddset(&sigset, SIGALRM);
225-
if (pthread_sigmask(SIG_BLOCK, &sigset, NULL))
226-
serverLog(LL_WARNING, "Warning: can't mask SIGALRM in bio.c thread: %s", strerror(errno));
226+
int err = pthread_sigmask(SIG_BLOCK, &sigset, NULL);
227+
if (err)
228+
serverLog(LL_WARNING, "Warning: can't mask SIGALRM in bio.c thread: %s", strerror(err));
227229

228230
while (1) {
229231
listNode *ln;

src/io_threads.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,9 @@ static void createIOThread(int id) {
265265
pthread_mutex_init(&io_threads_mutex[id], NULL);
266266
IOJobQueue_init(&io_jobs[id], IO_JOB_QUEUE_SIZE);
267267
pthread_mutex_lock(&io_threads_mutex[id]); /* Thread will be stopped. */
268-
if (pthread_create(&tid, NULL, IOThreadMain, (void *)(long)id) != 0) {
269-
serverLog(LL_WARNING, "Fatal: Can't initialize IO thread, pthread_create failed with: %s", strerror(errno));
268+
int err = pthread_create(&tid, NULL, IOThreadMain, (void *)(long)id);
269+
if (err) {
270+
serverLog(LL_WARNING, "Fatal: Can't initialize IO thread, pthread_create failed with: %s", strerror(err));
270271
exit(1);
271272
}
272273
io_threads[id] = tid;

0 commit comments

Comments
 (0)