Don't close the same file descriptor more than once.
This commit is contained in:
22
src/client.c
22
src/client.c
@@ -490,11 +490,19 @@ void client_cleanup(struct client* client,
|
|||||||
{
|
{
|
||||||
info("client cleanup for client %p", client);
|
info("client cleanup for client %p", client);
|
||||||
|
|
||||||
if (client->socket) { close(client->socket); }
|
if (client->socket) {
|
||||||
|
close(client->socket);
|
||||||
|
client->socket = -1;
|
||||||
|
debug("Closed client socket fd %d", client->socket);
|
||||||
|
}
|
||||||
if (client->mapped) {
|
if (client->mapped) {
|
||||||
munmap(client->mapped, client->serve->size);
|
munmap(client->mapped, client->serve->size);
|
||||||
}
|
}
|
||||||
if (client->fileno) { close(client->fileno); }
|
if (client->fileno) {
|
||||||
|
close(client->fileno);
|
||||||
|
client->fileno = -1;
|
||||||
|
debug("Closed client file fd %d", client->fileno );
|
||||||
|
}
|
||||||
|
|
||||||
if ( server_io_locked( client->serve ) ) { server_unlock_io( client->serve ); }
|
if ( server_io_locked( client->serve ) ) { server_unlock_io( client->serve ); }
|
||||||
if ( server_acl_locked( client->serve ) ) { server_unlock_acl( client->serve ); }
|
if ( server_acl_locked( client->serve ) ) { server_unlock_acl( client->serve ); }
|
||||||
@@ -517,6 +525,7 @@ void* client_serve(void* client_uncast)
|
|||||||
),
|
),
|
||||||
"Couldn't open/mmap file %s: %s", client->serve->filename, strerror( errno )
|
"Couldn't open/mmap file %s: %s", client->serve->filename, strerror( errno )
|
||||||
);
|
);
|
||||||
|
debug( "Opened client file fd %d", client->fileno);
|
||||||
debug("client: sending hello");
|
debug("client: sending hello");
|
||||||
client_send_hello(client);
|
client_send_hello(client);
|
||||||
|
|
||||||
@@ -530,16 +539,7 @@ void* client_serve(void* client_uncast)
|
|||||||
debug("client: control arrived" );
|
debug("client: control arrived" );
|
||||||
server_control_arrived( client->serve );
|
server_control_arrived( client->serve );
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
warn( "client: control transfer failed." );
|
|
||||||
}
|
|
||||||
|
|
||||||
FATAL_IF_NEGATIVE(
|
|
||||||
close(client->socket),
|
|
||||||
"Couldn't close socket %d",
|
|
||||||
client->socket
|
|
||||||
);
|
|
||||||
|
|
||||||
debug("Cleaning client %p up normally in thread %p", client, pthread_self());
|
debug("Cleaning client %p up normally in thread %p", client, pthread_self());
|
||||||
client_cleanup(client, 0);
|
client_cleanup(client, 0);
|
||||||
debug("Client thread done" );
|
debug("Client thread done" );
|
||||||
|
@@ -426,6 +426,7 @@ int mode_serve( int argc, char *argv[] )
|
|||||||
if ( err ) { exit_err( serve_help_text ); }
|
if ( err ) { exit_err( serve_help_text ); }
|
||||||
|
|
||||||
flexnbd = flexnbd_create_serving( ip_addr, ip_port, file, sock, default_deny, argc - optind, argv + optind, MAX_NBD_CLIENTS );
|
flexnbd = flexnbd_create_serving( ip_addr, ip_port, file, sock, default_deny, argc - optind, argv + optind, MAX_NBD_CLIENTS );
|
||||||
|
info( "Serving file %s", file );
|
||||||
flexnbd_serve( flexnbd );
|
flexnbd_serve( flexnbd );
|
||||||
flexnbd_destroy( flexnbd );
|
flexnbd_destroy( flexnbd );
|
||||||
|
|
||||||
|
@@ -505,6 +505,7 @@ void accept_nbd_client(
|
|||||||
|
|
||||||
if ( !server_should_accept_client( params, client_address, s_client_address, 64 ) ) {
|
if ( !server_should_accept_client( params, client_address, s_client_address, 64 ) ) {
|
||||||
close( client_fd );
|
close( client_fd );
|
||||||
|
debug("Closed client socket fd %d", client_fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,6 +513,7 @@ void accept_nbd_client(
|
|||||||
if (slot < 0) {
|
if (slot < 0) {
|
||||||
warn("too many clients to accept connection");
|
warn("too many clients to accept connection");
|
||||||
close(client_fd);
|
close(client_fd);
|
||||||
|
debug("Closed client socket fd %d", client_fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,6 +530,7 @@ void accept_nbd_client(
|
|||||||
debug( "Thread creation problem." );
|
debug( "Thread creation problem." );
|
||||||
client_destroy( client_params );
|
client_destroy( client_params );
|
||||||
close(client_fd);
|
close(client_fd);
|
||||||
|
debug("Closed client socket fd %d", client_fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -655,7 +658,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 );
|
client_fd = accept( params->server_fd, &client_address.generic, &socklen );
|
||||||
debug("Accepted nbd client socket");
|
debug("Accepted nbd client socket fd %d", client_fd);
|
||||||
accept_nbd_client(params, client_fd, &client_address);
|
accept_nbd_client(params, client_fd, &client_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user