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

Re: [Nbd] inetd mode



Sorry, I forgot to include a necessary part of the patch last time. This one
works.

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	19 Jul 2004 05:59:25 -0000
@@ -753,7 +753,7 @@
 			strncpy(exportname3, exportname2, 1024);
 		}
 		exportname3[1023]='\0';
-		printf( "Opening %s\n", exportname3 );
+		DEBUG2( "Opening %s\n", exportname3 );
 		if ((export[i/hunksize] = open(exportname3, (flags & F_READONLY) ? O_RDONLY : O_RDWR)) == -1) {
 			/* Read WRITE ACCESS was requested by media is only read only */
 			autoreadonly = 1;
@@ -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: