From 2a71b4e7a4d8fceb4e3039dac90eafaf66d0296e Mon Sep 17 00:00:00 2001 From: Alex Young Date: Mon, 11 Jun 2012 16:08:19 +0100 Subject: [PATCH] Fix broken error checking around pthread functions --- src/client.c | 2 +- src/control.c | 8 ++++---- src/serve.c | 8 ++++---- src/util.h | 1 + 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/client.c b/src/client.c index f905a13..f72b8a1 100644 --- a/src/client.c +++ b/src/client.c @@ -179,7 +179,7 @@ int client_read_request( struct client * client , struct nbd_request *out_reques return 0; /* neat point to close the socket */ } else { - FATAL_IF_NEGATIVE(-1, "Error reading request"); + fatal("Error reading request"); } } diff --git a/src/control.c b/src/control.c index 9586853..08f0d2e 100644 --- a/src/control.c +++ b/src/control.c @@ -258,8 +258,8 @@ int control_mirror(struct control_params* client, int linesc, char** lines) client->serve->mirror = mirror; - FATAL_IF_NEGATIVE( /* FIXME should free mirror on error */ - pthread_create( + FATAL_IF( /* FIXME should free mirror on error */ + 0 != pthread_create( &mirror->thread, NULL, mirror_runner, @@ -373,8 +373,8 @@ void accept_control_connection(struct server* params, int client_fd, control_params->socket = client_fd; control_params->serve = params; - FATAL_IF_NEGATIVE( - pthread_create( + FATAL_IF( + 0 != pthread_create( &control_thread, NULL, control_serve, diff --git a/src/serve.c b/src/serve.c index c243af2..c127780 100644 --- a/src/serve.c +++ b/src/serve.c @@ -112,11 +112,11 @@ void server_dirty(struct server *serve, off64_t from, int len) } #define SERVER_LOCK( s, f, msg ) \ - { NULLCHECK( s ); \ - FATAL_IF_NEGATIVE( pthread_mutex_lock( &s->f ), msg ); } + do { NULLCHECK( s ); \ + FATAL_IF( 0 != pthread_mutex_lock( &s->f ), msg ); } while (0) #define SERVER_UNLOCK( s, f, msg ) \ - { NULLCHECK( s ); \ - FATAL_IF_NEGATIVE( pthread_mutex_unlock( &s->f ), msg ); } + do { NULLCHECK( s ); \ + FATAL_IF( 0 != pthread_mutex_unlock( &s->f ), msg ); } while (0) void server_lock_io( struct server * serve) { diff --git a/src/util.h b/src/util.h index b775581..4bc92ff 100644 --- a/src/util.h +++ b/src/util.h @@ -94,6 +94,7 @@ void mylog(int line_level, const char* format, ...); error_handler(1); \ } while(0) + #define ERROR_IF( test, msg, ... ) do { if ((test)) { error(msg, ##__VA_ARGS__); } } while(0) #define FATAL_IF( test, msg, ... ) do { if ((test)) { fatal(msg, ##__VA_ARGS__); } } while(0)