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

[Nbd] inetd mode



And now for my main point... the documentation says you can specify port 0 to
have nbd-server operate on stdin, making it inetd-friendly. That appears to
be a feature that exists only in the imagination of the author. But it
sounded like a good idea to me so I implemented it.

Index: nbd-server.c
===================================================================
RCS file: /cvsroot/nbd/nbd/nbd-server.c,v
retrieving revision 1.31
diff -u -r1.31 nbd-server.c
--- nbd-server.c	27 Jun 2004 11:34:55 -0000	1.31
+++ nbd-server.c	18 Jul 2004 23:20:31 -0000
@@ -964,7 +964,20 @@
 	logging();
 	cmdline(argc, argv);
 	
-	if (!port) return 1 ;
+	if (!port) {
+#ifndef ISSERVER
+          /* You really should define ISSERVER if you're going to use inetd
+           * mode, but if you don't, closing stdout and stderr (which inetd
+           * had connected to the client socket) will let it work. */
+          close(1);
+          close(2);
+          open("/dev/null", O_WRONLY);
+          open("/dev/null", O_WRONLY);
+#endif
+          set_peername(0,clientname);
+          serveconnection(0);
+          return 0;
+        }
 	connectme(port); /* serve infinitely */
 	return 0 ;
 }



Reply to: