Tighten up some variable scopes.

This commit is contained in:
Alex Young
2014-03-11 10:24:29 +00:00
parent b063f41ba8
commit f0911b5c6c
4 changed files with 7 additions and 13 deletions

View File

@@ -31,8 +31,6 @@ int build_allocation_map(struct bitset * allocation_map, int fd)
for (offset = 0; offset < allocation_map->size; ) { for (offset = 0; offset < allocation_map->size; ) {
unsigned int i;
fiemap->fm_start = offset; fiemap->fm_start = offset;
fiemap->fm_length = max_length; fiemap->fm_length = max_length;
@@ -49,7 +47,7 @@ int build_allocation_map(struct bitset * allocation_map, int fd)
return 0; /* it's up to the caller to free the map */ return 0; /* it's up to the caller to free the map */
} }
else { else {
for ( i = 0; i < fiemap->fm_mapped_extents; i++ ) { for ( unsigned int i = 0; i < fiemap->fm_mapped_extents; i++ ) {
bitset_set_range( allocation_map, bitset_set_range( allocation_map,
fiemap->fm_extents[i].fe_logical, fiemap->fm_extents[i].fe_logical,
fiemap->fm_extents[i].fe_length ); fiemap->fm_extents[i].fe_length );

View File

@@ -51,7 +51,6 @@ struct self_pipe * self_pipe_create(void)
{ {
struct self_pipe *sig = xmalloc( sizeof( struct self_pipe ) ); struct self_pipe *sig = xmalloc( sizeof( struct self_pipe ) );
int fds[2]; int fds[2];
int fcntl_err;
if ( NULL == sig ) { return NULL; } if ( NULL == sig ) { return NULL; }
@@ -62,7 +61,7 @@ struct self_pipe * self_pipe_create(void)
} }
if ( fcntl( fds[0], F_SETFL, O_NONBLOCK ) || fcntl( fds[1], F_SETFL, O_NONBLOCK ) ) { if ( fcntl( fds[0], F_SETFL, O_NONBLOCK ) || fcntl( fds[1], F_SETFL, O_NONBLOCK ) ) {
fcntl_err = errno; int fcntl_err = errno;
while( close( fds[0] ) == -1 && errno == EINTR ); while( close( fds[0] ) == -1 && errno == EINTR );
while( close( fds[1] ) == -1 && errno == EINTR ); while( close( fds[1] ) == -1 && errno == EINTR );
free( sig ); free( sig );

View File

@@ -233,7 +233,6 @@ int tryjoin_client_thread( struct client_tbl_entry *entry, int (*joinfunc)(pthre
int was_closed = 0; int was_closed = 0;
void * status=NULL; void * status=NULL;
int join_errno;
if (entry->thread != 0) { if (entry->thread != 0) {
char s_client_address[128]; char s_client_address[128];
@@ -241,7 +240,7 @@ int tryjoin_client_thread( struct client_tbl_entry *entry, int (*joinfunc)(pthre
sockaddr_address_string( &entry->address.generic, &s_client_address[0], 128 ); sockaddr_address_string( &entry->address.generic, &s_client_address[0], 128 );
debug( "%s(%p,...)", joinfunc == pthread_join ? "joining" : "tryjoining", entry->thread ); debug( "%s(%p,...)", joinfunc == pthread_join ? "joining" : "tryjoining", entry->thread );
join_errno = joinfunc(entry->thread, &status); int join_errno = joinfunc(entry->thread, &status);
/* join_errno can legitimately be ESRCH if the thread is /* join_errno can legitimately be ESRCH if the thread is
* already dead, but the client still needs tidying up. */ * already dead, but the client still needs tidying up. */
@@ -598,7 +597,6 @@ int server_accept( struct server * params )
{ {
NULLCHECK( params ); NULLCHECK( params );
debug("accept loop starting"); debug("accept loop starting");
int client_fd;
union mysockaddr client_address; union mysockaddr client_address;
fd_set fds; fd_set fds;
socklen_t socklen=sizeof(client_address); socklen_t socklen=sizeof(client_address);
@@ -638,7 +636,7 @@ int server_accept( struct server * params )
} }
if ( FD_ISSET( params->server_fd, &fds ) ){ if ( FD_ISSET( params->server_fd, &fds ) ){
client_fd = accept( params->server_fd, &client_address.generic, &socklen ); int client_fd = accept( params->server_fd, &client_address.generic, &socklen );
if ( params->allow_new_clients ) { if ( params->allow_new_clients ) {
debug("Accepted nbd client socket fd %d", client_fd); debug("Accepted nbd client socket fd %d", client_fd);
@@ -741,11 +739,11 @@ void server_join_clients( struct server * serve ) {
for (i=0; i < serve->max_nbd_clients; i++) { for (i=0; i < serve->max_nbd_clients; i++) {
pthread_t thread_id = serve->nbd_client[i].thread; pthread_t thread_id = serve->nbd_client[i].thread;
int err = 0;
if (thread_id != 0) { if (thread_id != 0) {
debug( "joining thread %p", thread_id ); debug( "joining thread %p", thread_id );
if ( 0 == (err = pthread_join( thread_id, &status ) ) ) { int err = pthread_join( thread_id, &status );
if ( 0 == err ) {
serve->nbd_client[i].thread = 0; serve->nbd_client[i].thread = 0;
} else { } else {
warn( "Error %s (%i) joining thread %p", strerror( err ), err, thread_id ); warn( "Error %s (%i) joining thread %p", strerror( err ), err, thread_id );

View File

@@ -39,7 +39,6 @@ const char* sockaddr_address_string( const struct sockaddr* sa, char* dest, size
struct sockaddr_un* un = ( struct sockaddr_un* ) sa; struct sockaddr_un* un = ( struct sockaddr_un* ) sa;
unsigned short real_port = ntohs( in->sin_port ); // common to in and in6 unsigned short real_port = ntohs( in->sin_port ); // common to in and in6
size_t size;
const char* ret = NULL; const char* ret = NULL;
memset( dest, 0, len ); memset( dest, 0, len );
@@ -57,7 +56,7 @@ const char* sockaddr_address_string( const struct sockaddr* sa, char* dest, size
} }
if ( NULL != ret && real_port > 0 && sa->sa_family != AF_UNIX ) { if ( NULL != ret && real_port > 0 && sa->sa_family != AF_UNIX ) {
size = strlen( dest ); size_t size = strlen( dest );
snprintf( dest + size, len - size, " port %d", real_port ); snprintf( dest + size, len - size, " port %d", real_port );
} }