From 8c8496a7f40d5c505cd1c38d9efb2029d26f0d57 Mon Sep 17 00:00:00 2001 From: yoe Date: Sat, 24 Jul 2004 08:56:34 +0000 Subject: [PATCH] r78: Make inetd mode actually work (Thanks, Alan Curry) --- nbd-server.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/nbd-server.c b/nbd-server.c index ed2ed48..0bff357 100644 --- a/nbd-server.c +++ b/nbd-server.c @@ -752,7 +752,7 @@ int splitexport(void) { 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; @@ -963,7 +963,20 @@ int main(int argc, char *argv[]) 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 ; } -- 1.7.10.4