Support systemd initrd kill protection
authorWouter Verhelst <w@uter.be>
Tue, 28 Jan 2014 07:39:41 +0000 (08:39 +0100)
committerWouter Verhelst <w@uter.be>
Tue, 28 Jan 2014 07:39:41 +0000 (08:39 +0100)
systemd wants us to mark our argv[0] when we don't want to be killed.

Since I think that's a bit ugly, add an option so it's only done when
necessary.

man/nbd-client.8.in.sgml
nbd-client.c

index b5e2bd8..7b74d5a 100644 (file)
@@ -62,6 +62,7 @@ manpage.1: manpage.sgml
       <arg>-swap</arg>
       <arg>-persist</arg>
       <arg>-nofork</arg>
+      <arg>-systemd-mark</arg>
       <arg>-block-size <replaceable>block size</replaceable></arg>
       <arg>-timeout <replaceable>seconds</replaceable></arg>
       <arg>-name <replaceable>name</replaceable></arg>
@@ -224,6 +225,20 @@ manpage.1: manpage.sgml
        </listitem>
       </varlistentry>
       <varlistentry>
+       <term><option>-systemd-mark</option></term>
+       <term><option>-m</option></term>
+       <listitem>
+         <para>The systemd init system requires that processes which
+           should not be killed at shutdown time be marked appropriately
+           by replacing the first letter of their argv[0] with an '@'
+           sign.</para>
+         <para>This option will cause nbd-client to do so.</para>
+         <para>Note that this only works if nbd-client is run from an
+           initrd; i.e., systemd will ignore such a mark if run from a
+           systemd unit file or from the command line.</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
         <term><option>-nofork</option></term>
        <term><option>-n</option></term>
        <listitem>
index cc9a06e..8909268 100644 (file)
@@ -396,7 +396,7 @@ void usage(char* errmsg, ...) {
        } else {
                fprintf(stderr, "nbd-client version %s\n", PACKAGE_VERSION);
        }
-       fprintf(stderr, "Usage: nbd-client host port nbd_device [-block-size|-b block size] [-timeout|-t timeout] [-swap|-s] [-sdp|-S] [-persist|-p] [-nofork|-n]\n");
+       fprintf(stderr, "Usage: nbd-client host port nbd_device [-block-size|-b block size] [-timeout|-t timeout] [-swap|-s] [-sdp|-S] [-persist|-p] [-nofork|-n] [-systemd-mark|-m]\n");
        fprintf(stderr, "Or   : nbd-client -name|-N name host [port] nbd_device [-block-size|-b block size] [-timeout|-t timeout] [-swap|-s] [-sdp|-S] [-persist|-p] [-nofork|-n]\n");
        fprintf(stderr, "Or   : nbd-client -d nbd_device\n");
        fprintf(stderr, "Or   : nbd-client -c nbd_device\n");
@@ -455,6 +455,7 @@ int main(int argc, char *argv[]) {
                { "persist", no_argument, NULL, 'p' },
                { "sdp", no_argument, NULL, 'S' },
                { "swap", no_argument, NULL, 's' },
+               { "systemd-mark", no_argument, NULL, 'm' },
                { "timeout", required_argument, NULL, 't' },
                { 0, 0, 0, 0 }, 
        };
@@ -524,6 +525,9 @@ int main(int argc, char *argv[]) {
                        nbddev="";
                        port = NBD_DEFAULT_PORT;
                        break;
+               case 'm':
+                       argv[0][0] = '@';
+                       break;
                case 'n':
                        nofork=1;
                        break;