Fix broken error checking around pthread functions

This commit is contained in:
Alex Young
2012-06-11 16:08:19 +01:00
parent 5996c8f7ba
commit 2a71b4e7a4
4 changed files with 10 additions and 9 deletions

View File

@@ -179,7 +179,7 @@ int client_read_request( struct client * client , struct nbd_request *out_reques
return 0; /* neat point to close the socket */ return 0; /* neat point to close the socket */
} }
else { else {
FATAL_IF_NEGATIVE(-1, "Error reading request"); fatal("Error reading request");
} }
} }

View File

@@ -258,8 +258,8 @@ int control_mirror(struct control_params* client, int linesc, char** lines)
client->serve->mirror = mirror; client->serve->mirror = mirror;
FATAL_IF_NEGATIVE( /* FIXME should free mirror on error */ FATAL_IF( /* FIXME should free mirror on error */
pthread_create( 0 != pthread_create(
&mirror->thread, &mirror->thread,
NULL, NULL,
mirror_runner, mirror_runner,
@@ -373,8 +373,8 @@ void accept_control_connection(struct server* params, int client_fd,
control_params->socket = client_fd; control_params->socket = client_fd;
control_params->serve = params; control_params->serve = params;
FATAL_IF_NEGATIVE( FATAL_IF(
pthread_create( 0 != pthread_create(
&control_thread, &control_thread,
NULL, NULL,
control_serve, control_serve,

View File

@@ -112,11 +112,11 @@ void server_dirty(struct server *serve, off64_t from, int len)
} }
#define SERVER_LOCK( s, f, msg ) \ #define SERVER_LOCK( s, f, msg ) \
{ NULLCHECK( s ); \ do { NULLCHECK( s ); \
FATAL_IF_NEGATIVE( pthread_mutex_lock( &s->f ), msg ); } FATAL_IF( 0 != pthread_mutex_lock( &s->f ), msg ); } while (0)
#define SERVER_UNLOCK( s, f, msg ) \ #define SERVER_UNLOCK( s, f, msg ) \
{ NULLCHECK( s ); \ do { NULLCHECK( s ); \
FATAL_IF_NEGATIVE( pthread_mutex_unlock( &s->f ), msg ); } FATAL_IF( 0 != pthread_mutex_unlock( &s->f ), msg ); } while (0)
void server_lock_io( struct server * serve) void server_lock_io( struct server * serve)
{ {

View File

@@ -94,6 +94,7 @@ void mylog(int line_level, const char* format, ...);
error_handler(1); \ error_handler(1); \
} while(0) } while(0)
#define ERROR_IF( test, msg, ... ) do { if ((test)) { error(msg, ##__VA_ARGS__); } } 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) #define FATAL_IF( test, msg, ... ) do { if ((test)) { fatal(msg, ##__VA_ARGS__); } } while(0)