[Libguestfs] [PATCH nbdkit 1/3] server: Don't return connection status from handle_single_connection.

Richard W.M. Jones rjones at redhat.com
Mon Nov 4 15:42:32 UTC 2019


This was only used in one place: when using the -s option on the
command line.  In this case nbdkit -s would exit with EXIT_FAILURE if
there was some kind of I/O error or early client close.  This is not
particularly useful because: (1) It prevents the plugin being unloaded
properly. (2) Client close is a normal shutdown strategy for some
clients, so not really an error.  (3) It's undocumented and
inconsistent with other server modes.  (4) It's awkward when doing
fuzzing.

Note that connection_get_status (added in commit 0e1f158a1a
"connections: Add thread-safe status indicator") is still required to
coordinate connection shutdown across threads.
---
 server/connections.c | 21 +++++----------------
 server/internal.h    |  2 +-
 server/main.c        |  3 +--
 3 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/server/connections.c b/server/connections.c
index 95d8296..3adba7b 100644
--- a/server/connections.c
+++ b/server/connections.c
@@ -132,15 +132,17 @@ connection_worker (void *data)
   return NULL;
 }
 
-static int
-_handle_single_connection (int sockin, int sockout)
+void
+handle_single_connection (int sockin, int sockout)
 {
   const char *plugin_name;
-  int ret = -1, r;
+  int r;
   struct connection *conn;
   int nworkers = threads ? threads : DEFAULT_PARALLEL_REQUESTS;
   pthread_t *workers = NULL;
 
+  lock_connection ();
+
   if (backend->thread_model (backend) < NBDKIT_THREAD_MODEL_PARALLEL ||
       nworkers == 1)
     nworkers = 0;
@@ -222,22 +224,9 @@ _handle_single_connection (int sockin, int sockout)
   if (r == -1)
     goto done;
 
-  ret = connection_get_status (conn);
  done:
   free_connection (conn);
-  return ret;
-}
-
-int
-handle_single_connection (int sockin, int sockout)
-{
-  int r;
-
-  lock_connection ();
-  r = _handle_single_connection (sockin, sockout);
   unlock_connection ();
-
-  return r;
 }
 
 static struct connection *
diff --git a/server/internal.h b/server/internal.h
index bb667ce..b28b1c8 100644
--- a/server/internal.h
+++ b/server/internal.h
@@ -234,7 +234,7 @@ struct connection {
   connection_close_function close;
 };
 
-extern int handle_single_connection (int sockin, int sockout);
+extern void handle_single_connection (int sockin, int sockout);
 extern int connection_get_status (struct connection *conn)
   __attribute__((__nonnull__ (1)));
 extern int connection_set_status (struct connection *conn, int value)
diff --git a/server/main.c b/server/main.c
index 3e2ac2f..dcfdbde 100644
--- a/server/main.c
+++ b/server/main.c
@@ -894,8 +894,7 @@ start_serving (void)
     change_user ();
     write_pidfile ();
     threadlocal_new_server_thread ();
-    if (handle_single_connection (0, 1) == -1)
-      exit (EXIT_FAILURE);
+    handle_single_connection (0, 1);
     return;
   }
 
-- 
2.23.0




More information about the Libguestfs mailing list