[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Nbd] [PATCH 4/4] nbd-server: remove global variables: modern_listen and modernport



Address and port of the modern socket are read from the main
configuration file and used only when opening the socket. There is no
need to keep them hanging in the global scope.

Signed-off-by: Tuomas Jorma Juhani Räsänen <tuomasjjrasanen@...1261...>
---
 nbd-server.c |   18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/nbd-server.c b/nbd-server.c
index a2f64ea..debe881 100644
--- a/nbd-server.c
+++ b/nbd-server.c
@@ -182,9 +182,6 @@ int modernsock=-1;	  /**< Socket for the modern handler. Not used
 			       command line; only port used if
 			       oldstyle is set to false (and then the
 			       command-line client isn't used, gna gna) */
-char* modern_listen;	  /**< listenaddr value for modernsock */
-char* modernport=NBD_DEFAULT_PORT; /**< Port number on which to listen for
-			              new-style nbd-client connections */
 
 bool logged_oversized=false;  /**< whether we logged oversized requests already */
 
@@ -2502,7 +2499,7 @@ int setup_serve(SERVER *serve) {
 	}
 }
 
-void open_modern(void) {
+void open_modern(const gchar *const addr, const gchar *const port) {
 	struct addrinfo hints;
 	struct addrinfo* ai = NULL;
 	struct sock_flags;
@@ -2514,7 +2511,7 @@ void open_modern(void) {
 	hints.ai_socktype = SOCK_STREAM;
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_protocol = IPPROTO_TCP;
-	e = getaddrinfo(modern_listen, modernport, &hints, &ai);
+	e = getaddrinfo(addr, port ? port : NBD_DEFAULT_PORT, &hints, &ai);
 	if(e != 0) {
 		fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(e));
 		exit(EXIT_FAILURE);
@@ -2543,7 +2540,8 @@ void open_modern(void) {
 /**
  * Connect our servers.
  **/
-void setup_servers(GArray* servers) {
+void setup_servers(GArray *const servers, const gchar *const modernaddr,
+                   const gchar *const modernport) {
 	int i;
 	struct sigaction sa;
 	int want_modern=0;
@@ -2552,7 +2550,7 @@ void setup_servers(GArray* servers) {
 		want_modern |= setup_serve(&(g_array_index(servers, SERVER, i)));
 	}
 	if(want_modern) {
-		open_modern();
+		open_modern(modernaddr, modernport);
 	}
 	children=g_hash_table_new_full(g_int_hash, g_int_equal, NULL, destroy_pid_t);
 
@@ -2701,8 +2699,6 @@ int main(int argc, char *argv[]) {
 	
         /* Update global variables with parsed values. This will be
          * removed once we get rid of global configuration variables. */
-        modern_listen = genconf.modernaddr ? genconf.modernaddr : modern_listen;
-        modernport    = genconf.modernport ? genconf.modernport : modernport;
         glob_flags   |= genconf.flags;
 
 	if(serve) {
@@ -2752,11 +2748,13 @@ int main(int argc, char *argv[]) {
 	}
 	if (!dontfork)
 		daemonize(serve);
-	setup_servers(servers);
+	setup_servers(servers, genconf.modernaddr, genconf.modernport);
 	dousers(genconf.user, genconf.group);
 
         g_free(genconf.user);
         g_free(genconf.group);
+        g_free(genconf.modernaddr);
+        g_free(genconf.modernport);
 
 	serveloop(servers);
 }
-- 
1.7.10.4




Reply to: