From 77e97612688142b4bdfa172f5c67560125812913 Mon Sep 17 00:00:00 2001
From: Wouter Verhelst <w@uter.be>
Date: Tue, 28 Jan 2014 08:39:41 +0100
Subject: [PATCH] Support systemd initrd kill protection
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 | 15 +++++++++++++++
nbd-client.c | 6 +++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/man/nbd-client.8.in.sgml b/man/nbd-client.8.in.sgml
index b5e2bd8..7b74d5a 100644
--- a/man/nbd-client.8.in.sgml
+++ b/man/nbd-client.8.in.sgml
@@ -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>
diff --git a/nbd-client.c b/nbd-client.c
index cc9a06e..8909268 100644
--- a/nbd-client.c
+++ b/nbd-client.c
@@ -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;
--
1.8.5.1