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

[Nbd] [PATCH] nbd-server: add -D/-dont-daemonize option



When this option is specified, nbd-server will not detach and will not
become a daemon, allowing easy monitoring by service managers like
systemd.

Signed-off-by: Dmitry V. Levin <ldv@...1147...>
---
 man/nbd-server.1.in.sgml |   10 +++++++++-
 nbd-server.c             |   10 ++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/man/nbd-server.1.in.sgml b/man/nbd-server.1.in.sgml
index 7a5832e..e656358 100644
--- a/man/nbd-server.1.in.sgml
+++ b/man/nbd-server.1.in.sgml
@@ -68,6 +68,7 @@ manpage.1: manpage.sgml
       <arg><option>-C <replaceable>config file</replaceable></option></arg>
       <arg><option>-M <replaceable>max connections</replaceable></option></arg>
       <arg><option>-d</option></arg>
+      <arg><option>-D</option></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
   <refsect1>
@@ -217,9 +218,16 @@ manpage.1: manpage.sgml
 	</listitem>
       </varlistentry>
       <varlistentry>
+        <term><option>-D</option></term>
+	<listitem>
+	  <para>Do not detach and do not become a daemon. This allows
+	  easy monitoring by service managers like systemd.</para>
+	</listitem>
+      </varlistentry>
+      <varlistentry>
         <term><option>-d</option></term>
 	<listitem>
-	  <para>Do not fork. Useful for debugging.</para>
+	  <para>Do not fork at all. Useful for debugging.</para>
 	</listitem>
       </varlistentry>
       <varlistentry>
diff --git a/nbd-server.c b/nbd-server.c
index 49822a7..d025a39 100644
--- a/nbd-server.c
+++ b/nbd-server.c
@@ -125,6 +125,7 @@ int glob_flags=0;
 
 /* Whether we should avoid forking */
 int dontfork = 0;
+int dont_daemonize = 0;
 
 /** Logging macros, now nothing goes to syslog unless you say ISSERVER */
 #ifdef ISSERVER
@@ -431,6 +432,7 @@ void usage() {
 	       "\t-r|--read-only\t\tread only\n"
 	       "\t-m|--multi-file\t\tmultiple file\n"
 	       "\t-c|--copy-on-write\tcopy on write\n"
+	       "\t-D|--dont-daemonize\tdo not detach and do not become a daemon\n"
 	       "\t-C|--config-file\tspecify an alternate configuration file\n"
 	       "\t-l|--authorize-file\tfile with list of hosts that are allowed to\n\t\t\t\tconnect.\n"
 	       "\t-p|--pid-file\t\tspecify a filename to write our PID to\n"
@@ -481,6 +483,7 @@ SERVER* cmdline(int argc, char *argv[]) {
 		{"read-only", no_argument, NULL, 'r'},
 		{"multi-file", no_argument, NULL, 'm'},
 		{"copy-on-write", no_argument, NULL, 'c'},
+		{"dont-daemonize", no_argument, NULL, 'D'},
 		{"dont-fork", no_argument, NULL, 'd'},
 		{"authorize-file", required_argument, NULL, 'l'},
 		{"config-file", required_argument, NULL, 'C'},
@@ -503,7 +506,7 @@ SERVER* cmdline(int argc, char *argv[]) {
 	serve=g_new0(SERVER, 1);
 	serve->authname = g_strdup(default_authname);
 	serve->virtstyle=VIRT_IPLIT;
-	while((c=getopt_long(argc, argv, "-C:cdl:mo:rp:M:", long_options, &i))>=0) {
+	while((c=getopt_long(argc, argv, "-C:cDdl:mo:rp:M:", long_options, &i))>=0) {
 		switch (c) {
 		case 1:
 			/* non-option argument */
@@ -574,6 +577,9 @@ SERVER* cmdline(int argc, char *argv[]) {
 		        break;
 		case 'd': 
 			dontfork = 1;
+			/* fall through */
+		case 'D':
+			dont_daemonize = 1;
 		        break;
 		case 'C':
 			g_free(config_file_pos);
@@ -2655,7 +2661,7 @@ int main(int argc, char *argv[]) {
 		g_message("No configured exports; quitting.");
 		exit(EXIT_FAILURE);
 	}
-	if (!dontfork)
+	if (!dont_daemonize)
 		daemonize(serve);
 	setup_servers(servers);
 	dousers();
-- 
ldv



Reply to: