[systemd-commits] 6 commits - Makefile.am man/crypttab.xml man/systemd-fsck at .service.xml man/systemd.mount.xml man/systemd.special.xml src/core src/cryptsetup src/fstab-generator src/shared tools/make-directive-index.py
Zbigniew JÄdrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Mon Jun 30 15:44:47 PDT 2014
Makefile.am | 8 +-
man/crypttab.xml | 80 ++++++++++++-------------
man/systemd-fsck at .service.xml | 60 ++++++++++++++-----
man/systemd.mount.xml | 105 +++++++++++++++++++++++-----------
man/systemd.special.xml | 7 --
src/core/mount.c | 55 -----------------
src/core/unit.c | 70 +++++++++-------------
src/cryptsetup/cryptsetup-generator.c | 25 +++-----
src/fstab-generator/fstab-generator.c | 17 ++++-
src/shared/dropin.c | 102 +++++++++++++++++++++++++++++++++
src/shared/dropin.h | 31 ++++++++++
src/shared/generator.c | 66 +++++++++++++++++++++
src/shared/generator.h | 3
src/shared/path-lookup.h | 2
tools/make-directive-index.py | 5 -
15 files changed, 428 insertions(+), 208 deletions(-)
New commits:
commit ee43f49b7889b546fe05a141459d7f1ddf129bd4
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Mon Jun 30 09:41:01 2014 -0400
man: mention x-initrd.mount option in fstab options list
diff --git a/man/systemd.mount.xml b/man/systemd.mount.xml
index 34a1ac8..3bc4d3a 100644
--- a/man/systemd.mount.xml
+++ b/man/systemd.mount.xml
@@ -207,6 +207,17 @@
opposite meaning and is the default.</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><option>x-initrd.mount</option></term>
+
+ <listitem><para>An additional filesystem to be
+ mounted in the initramfs. See
+ <filename>initrd-fs.target</filename> description
+ in
+ <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
+ </para></listitem>
+ </varlistentry>
</variablelist>
<para>If a mount point is configured in both
diff --git a/man/systemd.special.xml b/man/systemd.special.xml
index f590b3f..f84639e 100644
--- a/man/systemd.special.xml
+++ b/man/systemd.special.xml
@@ -322,11 +322,10 @@
<filename>sysroot-usr.mount</filename>
and all mount points found in
<filename>/etc/fstab</filename>
- that have the
- <option>auto</option> and
+ that have
<option>x-initrd.mount</option>
- mount options set.
- </para>
+ and not have <option>noauto</option>
+ mount options set.</para>
</listitem>
</varlistentry>
<varlistentry>
commit 63b03c0b2889dd490b3511f12f00268c154a655c
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Mon Jun 30 09:27:16 2014 -0400
man: mention that x-systemd.device-timeout is only for fstab
Reformat fstab options description. Now they are easier to read and
show up in systemd.directives(7).
Use a single sublist for both /etc/fstab and /etc/crypttab options.
Many of them can be used in both places. crypttab(5) is updated to use
the same docbook elements, so formatting is uniform.
diff --git a/man/crypttab.xml b/man/crypttab.xml
index 9030015..9dbf154 100644
--- a/man/crypttab.xml
+++ b/man/crypttab.xml
@@ -109,10 +109,10 @@
comma-delimited list of options. The following
options are recognized:</para>
- <variablelist class='crypttab-options'>
+ <variablelist class='fstab-options'>
<varlistentry>
- <term><varname>discard</varname></term>
+ <term><option>discard</option></term>
<listitem><para>Allow discard requests to be
passed through the encrypted block device. This
@@ -121,7 +121,7 @@
</varlistentry>
<varlistentry>
- <term><varname>cipher=</varname></term>
+ <term><option>cipher=</option></term>
<listitem><para>Specifies the cipher to use. See
<citerefentry><refentrytitle>cryptsetup</refentrytitle><manvolnum>8</manvolnum></citerefentry>
@@ -132,7 +132,7 @@
</varlistentry>
<varlistentry>
- <term><varname>hash=</varname></term>
+ <term><option>hash=</option></term>
<listitem><para>Specifies the hash to use for
password hashing. See
@@ -142,7 +142,7 @@
</varlistentry>
<varlistentry>
- <term><varname>keyfile-offset=</varname></term>
+ <term><option>keyfile-offset=</option></term>
<listitem><para>Specifies the number of bytes to
skip at the start of the key file. See
@@ -152,7 +152,7 @@
</varlistentry>
<varlistentry>
- <term><varname>keyfile-size=</varname></term>
+ <term><option>keyfile-size=</option></term>
<listitem><para>Specifies the maximum number
of bytes to read from the key file. See
@@ -164,39 +164,39 @@
</varlistentry>
<varlistentry>
- <term><varname>key-slot=</varname></term>
+ <term><option>key-slot=</option></term>
<listitem><para>Specifies the key slot to
compare the passphrase or key against.
If the key slot does not match the given
passphrase or key, but another would, the
setup of the device will fail regardless.
- This option implies <varname>luks</varname>. See
+ This option implies <option>luks</option>. See
<citerefentry><refentrytitle>cryptsetup</refentrytitle><manvolnum>8</manvolnum></citerefentry>
for possible values. The default is to try
all key slots in sequential order.</para></listitem>
</varlistentry>
<varlistentry>
- <term><varname>luks</varname></term>
+ <term><option>luks</option></term>
<listitem><para>Force LUKS mode. When this mode
is used, the following options are ignored since
they are provided by the LUKS header on the
- device: <varname>cipher=</varname>,
- <varname>hash=</varname>,
- <varname>size=</varname>.</para></listitem>
+ device: <option>cipher=</option>,
+ <option>hash=</option>,
+ <option>size=</option>.</para></listitem>
</varlistentry>
<varlistentry>
- <term><varname>noauto</varname></term>
+ <term><option>noauto</option></term>
<listitem><para>This device will not be
automatically unlocked on boot.</para></listitem>
</varlistentry>
<varlistentry>
- <term><varname>nofail</varname></term>
+ <term><option>nofail</option></term>
<listitem><para>The system will not wait for the
device to show up and be unlocked at boot, and
@@ -204,20 +204,20 @@
</varlistentry>
<varlistentry>
- <term><varname>plain</varname></term>
+ <term><option>plain</option></term>
<listitem><para>Force plain encryption mode.</para></listitem>
</varlistentry>
<varlistentry>
- <term><varname>read-only</varname></term><term><varname>readonly</varname></term>
+ <term><option>read-only</option></term><term><option>readonly</option></term>
<listitem><para>Set up the encrypted block
device in read-only mode.</para></listitem>
</varlistentry>
<varlistentry>
- <term><varname>size=</varname></term>
+ <term><option>size=</option></term>
<listitem><para>Specifies the key size
in bits. See
@@ -227,33 +227,33 @@
</varlistentry>
<varlistentry>
- <term><varname>swap</varname></term>
+ <term><option>swap</option></term>
<listitem><para>The encrypted block device will
be used as a swap device, and will be formatted
accordingly after setting up the encrypted
block device, with
<citerefentry><refentrytitle>mkswap</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
- This option implies <varname>plain</varname>.</para>
+ This option implies <option>plain</option>.</para>
- <para>WARNING: Using the <varname>swap</varname>
+ <para>WARNING: Using the <option>swap</option>
option will destroy the contents of the named
partition during every boot, so make sure the
underlying block device is specified correctly.</para></listitem>
</varlistentry>
<varlistentry>
- <term><varname>tcrypt</varname></term>
+ <term><option>tcrypt</option></term>
<listitem><para>Use TrueCrypt encryption mode.
When this mode is used, the following options are
ignored since they are provided by the TrueCrypt
header on the device or do not apply:
- <varname>cipher=</varname>,
- <varname>hash=</varname>,
- <varname>keyfile-offset=</varname>,
- <varname>keyfile-size=</varname>,
- <varname>size=</varname>.</para>
+ <option>cipher=</option>,
+ <option>hash=</option>,
+ <option>keyfile-offset=</option>,
+ <option>keyfile-size=</option>,
+ <option>size=</option>.</para>
<para>When this mode is used, the passphrase is
read from the key file given in the third field.
@@ -264,7 +264,7 @@
passphrase and key files to derive a password
for the volume. Therefore, the passphrase and
all key files need to be provided. Use
- <varname>tcrypt-keyfile=</varname> to provide
+ <option>tcrypt-keyfile=</option> to provide
the absolute path to all key files. When using
an empty passphrase in combination with one or
more key files, use <literal>/dev/null</literal>
@@ -272,10 +272,10 @@
</varlistentry>
<varlistentry>
- <term><varname>tcrypt-hidden</varname></term>
+ <term><option>tcrypt-hidden</option></term>
<listitem><para>Use the hidden TrueCrypt volume.
- This option implies <varname>tcrypt</varname>.</para>
+ This option implies <option>tcrypt</option>.</para>
<para>This will map the hidden volume that is
inside of the volume provided in the second
@@ -287,29 +287,29 @@
</varlistentry>
<varlistentry>
- <term><varname>tcrypt-keyfile=</varname></term>
+ <term><option>tcrypt-keyfile=</option></term>
<listitem><para>Specifies the absolute path to a
key file to use for a TrueCrypt volume. This
- implies <varname>tcrypt</varname> and can be
+ implies <option>tcrypt</option> and can be
used more than once to provide several key
files.</para>
- <para>See the entry for <varname>tcrypt</varname>
+ <para>See the entry for <option>tcrypt</option>
on the behavior of the passphrase and key files
when using TrueCrypt encryption mode.</para></listitem>
</varlistentry>
<varlistentry>
- <term><varname>tcrypt-system</varname></term>
+ <term><option>tcrypt-system</option></term>
<listitem><para>Use TrueCrypt in system
encryption mode. This option implies
- <varname>tcrypt</varname>.</para></listitem>
+ <option>tcrypt</option>.</para></listitem>
</varlistentry>
<varlistentry>
- <term><varname>timeout=</varname></term>
+ <term><option>timeout=</option></term>
<listitem><para>Specifies the timeout for
querying for a password. If no unit is
@@ -319,22 +319,22 @@
</varlistentry>
<varlistentry>
- <term><varname>tmp</varname></term>
+ <term><option>tmp</option></term>
<listitem><para>The encrypted block device will
be prepared for using it as <filename>/tmp</filename>;
it will be formatted using
<citerefentry><refentrytitle>mke2fs</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
- This option implies <varname>plain</varname>.</para>
+ This option implies <option>plain</option>.</para>
- <para>WARNING: Using the <varname>tmp</varname>
+ <para>WARNING: Using the <option>tmp</option>
option will destroy the contents of the named
partition during every boot, so make sure the
underlying block device is specified correctly.</para></listitem>
</varlistentry>
<varlistentry>
- <term><varname>tries=</varname></term>
+ <term><option>tries=</option></term>
<listitem><para>Specifies the maximum number of
times the user is queried for a password.
@@ -343,7 +343,7 @@
</varlistentry>
<varlistentry>
- <term><varname>verify</varname></term>
+ <term><option>verify</option></term>
<listitem><para> If the encryption password is
read from console, it has to be entered twice to
diff --git a/man/systemd.mount.xml b/man/systemd.mount.xml
index 126b75c..34a1ac8 100644
--- a/man/systemd.mount.xml
+++ b/man/systemd.mount.xml
@@ -144,38 +144,70 @@
which influence how dependencies are created for mount
points from <filename>/etc/fstab</filename>. systemd
will create a dependency of type
- <option>Wants</option> from either
- <filename>local-fs.target</filename> or
+ <option>Wants</option> or <option>Requires</option>
+ (see option <option>nofail</option> below), from
+ either <filename>local-fs.target</filename> or
<filename>remote-fs.target</filename>, depending
- whether the file system is local or remote. If
- <option>x-systemd.automount</option> is set, an
- automount unit will be created for the file
- system. See
- <citerefentry><refentrytitle>systemd.automount</refentrytitle><manvolnum>5</manvolnum></citerefentry>
- for details. If
- <option>x-systemd.device-timeout=</option> is
- specified, it may be used to configure how long systemd
- should wait for a device to show up before giving up
- on an entry from
- <filename>/etc/fstab</filename>. Specify a time in
- seconds or explicitly specify a unit as
- <literal>s</literal>, <literal>min</literal>,
- <literal>h</literal>, <literal>ms</literal>.</para>
-
- <para>If <option>nofail</option> is given, this mount
- will be only wanted, not required, by the
- <filename>local-fs.target</filename>. This means that
- the boot will continue even if this mount point is not
- mounted successfully. Option <option>fail</option> has
- the opposite meaning and is the default.</para>
-
- <para>If <option>noauto</option> is given, this mount
- will not be added as a dependency for
- <filename>local-fs.target</filename>. This means that
- it will not be mounted automatically during boot,
- unless it is pulled in by some other unit. Option
- <option>auto</option> has the opposite meaning and is
- the default.</para>
+ whether the file system is local or remote.</para>
+
+ <variablelist class='fstab-options'>
+
+ <varlistentry>
+ <term><option>x-systemd.automount</option></term>
+
+ <listitem><para>An automount unit will be created
+ for the file system. See
+ <citerefentry><refentrytitle>systemd.automount</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+ for details.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>x-systemd.device-timeout=</option></term>
+
+ <listitem><para>Configure how long systemd should
+ wait for a device to show up before giving up on
+ an entry from
+ <filename>/etc/fstab</filename>. Specify a time in
+ seconds or explicitly append a unit as
+ <literal>s</literal>, <literal>min</literal>,
+ <literal>h</literal>,
+ <literal>ms</literal>.</para>
+
+ <para>Note that this option can only be used in
+ <filename>/etc/fstab</filename>, and will be
+ ignored when part of <varname>Options=</varname>
+ setting in a unit file.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>nofail</option></term>
+ <term><option>fail</option></term>
+
+ <listitem><para>With <option>nofail</option> this
+ mount will be only wanted, not required, by the
+ <filename>local-fs.target</filename>. This means
+ that the boot will continue even if this mount
+ point is not mounted successfully. Option
+ <option>fail</option> has the opposite meaning and
+ is the default.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>noauto</option></term>
+ <term><option>auto</option></term>
+
+ <listitem><para>With <option>noauto</option>, this
+ mount will not be added as a dependency for
+ <filename>local-fs.target</filename>. This means
+ that it will not be mounted automatically during
+ boot, unless it is pulled in by some other
+ unit. Option <option>auto</option> has the
+ opposite meaning and is the default.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
<para>If a mount point is configured in both
<filename>/etc/fstab</filename> and a unit file that
diff --git a/tools/make-directive-index.py b/tools/make-directive-index.py
index 2ff304f..5c80a7b 100755
--- a/tools/make-directive-index.py
+++ b/tools/make-directive-index.py
@@ -113,12 +113,13 @@ TEMPLATE = '''\
</refsect1>
<refsect1>
- <title>crypttab options</title>
+ <title><filename>/etc/crypttab</filename> and
+ <filename>/etc/fstab</filename> options</title>
<para>Options which influence mounted filesystems and
encrypted volumes.</para>
- <variablelist id='crypttab-options' />
+ <variablelist id='fstab-options' />
</refsect1>
<refsect1>
commit a17f2dc15b84c158a13968b4dbef92ae4f45c572
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Sat Jun 28 13:21:01 2014 -0400
man: beef up systemd-fsck description
diff --git a/man/systemd-fsck at .service.xml b/man/systemd-fsck at .service.xml
index afd8d9b..ee66f37 100644
--- a/man/systemd-fsck at .service.xml
+++ b/man/systemd-fsck at .service.xml
@@ -56,21 +56,41 @@
<refsect1>
<title>Description</title>
- <para><filename>systemd-fsck at .service</filename> is a
- service responsible for file system checks. It is
- instantiated for each device that requires a file
- system
- check. <filename>systemd-fsck-root.service</filename> is
- responsible for file system checks on the root
- file system. The root file system check is performed
- before the other file systems. Either service is enabled
- at boot if passno in <filename>/etc/fstab</filename> for
- the file system is set to a value greater than zero.</para>
-
- <para><filename>systemd-fsck</filename> will
- forward file system checking progress to the
- console. If a file system check fails, emergency mode
- is activated, by isolating to
+ <para><filename>systemd-fsck at .service</filename> and
+ <filename>systemd-fsck-root.service</filename> are
+ services responsible for file system checks. They are
+ instantiated for each device that is configured for
+ file system checking.
+ <filename>systemd-fsck-root.service</filename> is
+ responsible for file system checks on the root file
+ system, but in only if the root filesystem wasn't
+ checked in the initramfs.
+ <filename>systemd-fsck at .service</filename> is used for
+ all other file systems and for the root file system in
+ the initramfs.</para>
+
+ <para>Those services are started at boot if
+ <option>passno</option> in
+ <filename>/etc/fstab</filename> for the file system is
+ set to a value greater than zero. The file system
+ check for root is performed before the other file
+ systems. Other file systems may be checked in
+ parallel, except when they are one the same rotating
+ disk.</para>
+
+ <para><filename>systemd-fsck</filename> does not know
+ any details about specific filesystems, and simply
+ executes file system checkers specific to each
+ filesystem type (<filename>/sbin/fsck.*</filename>).
+ This helper will decide if the filesystem should
+ actually be checked based on the time since last
+ check, number of mounts, unclean unmount, etc.</para>
+
+ <para><filename>systemd-fsck</filename> will forward
+ file system checking progress to the console. If a
+ file system check fails for a service without
+ <option>nofail</option>, emergency mode is activated,
+ by isolating to
<filename>emergency.target</filename>.</para>
</refsect1>
@@ -122,7 +142,15 @@
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>fsck</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>systemd-quotacheck.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+ <citerefentry><refentrytitle>systemd-quotacheck.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>fsck.btrfs</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>fsck.cramfs</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>fsck.ext4</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>fsck.fat</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>fsck.hfsplus</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>fsck.minix</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>fsck.ntfs</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>fsck.xfs</refentrytitle><manvolnum>8</manvolnum></citerefentry>
</para>
</refsect1>
commit 8eea868708923a092ee85d6146ba4c04b7baea06
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Mon Jun 30 18:41:17 2014 -0400
cryptsetup: allow x-systemd.device-timeout
https://bugs.freedesktop.org/show_bug.cgi?id=54210
diff --git a/src/core/unit.c b/src/core/unit.c
index bace69f..0e4ebfd 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2998,7 +2998,7 @@ static int unit_drop_in_file(Unit *u,
if (r < 0)
return r;
- return drop_in_file(dir, u->id, name, p, q);
+ return drop_in_file(dir, u->id, 50, name, p, q);
}
int unit_write_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *data) {
@@ -3015,7 +3015,7 @@ int unit_write_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name, co
if (r < 0)
return r;
- return write_drop_in(dir, u->id, name, data);
+ return write_drop_in(dir, u->id, 50, name, data);
}
int unit_write_drop_in_format(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *format, ...) {
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index da16324..3233e15 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -30,6 +30,8 @@
#include "strv.h"
#include "fileio.h"
#include "path-util.h"
+#include "dropin.h"
+#include "generator.h"
static const char *arg_dest = "/tmp";
static bool arg_enabled = true;
@@ -73,7 +75,8 @@ static int create_disk(
const char *password,
const char *options) {
- _cleanup_free_ char *p = NULL, *n = NULL, *d = NULL, *u = NULL, *to = NULL, *e = NULL;
+ _cleanup_free_ char *p = NULL, *n = NULL, *d = NULL, *u = NULL, *to = NULL, *e = NULL,
+ *filtered = NULL;
_cleanup_fclose_ FILE *f = NULL;
bool noauto, nofail, tmp, swap;
char *from;
@@ -172,6 +175,10 @@ static int create_disk(
"RequiresMountsFor=%s\n",
u);
+ r = generator_write_timeouts(arg_dest, device, name, options, &filtered);
+ if (r < 0)
+ return r;
+
fprintf(f,
"\n[Service]\n"
"Type=oneshot\n"
@@ -179,7 +186,7 @@ static int create_disk(
"TimeoutSec=0\n" /* the binary handles timeouts anyway */
"ExecStart=" SYSTEMD_CRYPTSETUP_PATH " attach '%s' '%s' '%s' '%s'\n"
"ExecStop=" SYSTEMD_CRYPTSETUP_PATH " detach '%s'\n",
- name, u, strempty(password), strempty(options),
+ name, u, strempty(password), strempty(filtered),
name);
if (tmp)
@@ -239,17 +246,9 @@ static int create_disk(
}
if (!noauto && !nofail) {
-
- free(p);
- p = strjoin(arg_dest, "/dev-mapper-", e, ".device.d/50-job-timeout-sec-0.conf", NULL);
- if (!p)
- return log_oom();
-
- mkdir_parents_label(p, 0755);
- r = write_string_file(p,
- "# Automatically generated by systemd-cryptsetup-generator\n\n"
- "[Unit]\n"
- "JobTimeoutSec=0\n"); /* the binary handles timeouts anyway */
+ r = write_drop_in(arg_dest, name, 90, "device-timeout",
+ "# Automatically generated by systemd-cryptsetup-generator \n\n"
+ "[Unit]\nJobTimeoutSec=0");
if (r < 0) {
log_error("Failed to write device drop-in: %s", strerror(-r));
return r;
diff --git a/src/shared/dropin.c b/src/shared/dropin.c
index 7774236..ac09be9 100644
--- a/src/shared/dropin.c
+++ b/src/shared/dropin.c
@@ -24,17 +24,21 @@
#include "mkdir.h"
#include "fileio-label.h"
-int drop_in_file(const char *dir, const char *unit,
+int drop_in_file(const char *dir, const char *unit, unsigned level,
const char *name, char **_p, char **_q) {
_cleanup_free_ char *b = NULL;
char *p, *q;
+ char prefix[DECIMAL_STR_MAX(unsigned)];
+
assert(unit);
assert(name);
assert(_p);
assert(_q);
+ sprintf(prefix, "%u", level);
+
b = xescape(name, "/.");
if (!b)
return -ENOMEM;
@@ -46,7 +50,7 @@ int drop_in_file(const char *dir, const char *unit,
if (!p)
return -ENOMEM;
- q = strjoin(p, "/90-", b, ".conf", NULL);
+ q = strjoin(p, "/", prefix, "-", b, ".conf", NULL);
if (!q) {
free(p);
return -ENOMEM;
@@ -57,7 +61,7 @@ int drop_in_file(const char *dir, const char *unit,
return 0;
}
-int write_drop_in(const char *dir, const char *unit,
+int write_drop_in(const char *dir, const char *unit, unsigned level,
const char *name, const char *data) {
_cleanup_free_ char *p = NULL, *q = NULL;
@@ -68,7 +72,7 @@ int write_drop_in(const char *dir, const char *unit,
assert(name);
assert(data);
- r = drop_in_file(dir, unit, name, &p, &q);
+ r = drop_in_file(dir, unit, level, name, &p, &q);
if (r < 0)
return r;
@@ -76,7 +80,7 @@ int write_drop_in(const char *dir, const char *unit,
return write_string_file_atomic_label(q, data);
}
-int write_drop_in_format(const char *dir, const char *unit,
+int write_drop_in_format(const char *dir, const char *unit, unsigned level,
const char *name, const char *format, ...) {
_cleanup_free_ char *p = NULL;
va_list ap;
@@ -94,5 +98,5 @@ int write_drop_in_format(const char *dir, const char *unit,
if (r < 0)
return -ENOMEM;
- return write_drop_in(dir, unit, name, p);
+ return write_drop_in(dir, unit, level, name, p);
}
diff --git a/src/shared/dropin.h b/src/shared/dropin.h
index 2958632..27a2b29 100644
--- a/src/shared/dropin.h
+++ b/src/shared/dropin.h
@@ -21,11 +21,11 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-int drop_in_file(const char *dir, const char *unit,
+int drop_in_file(const char *dir, const char *unit, unsigned level,
const char *name, char **_p, char **_q);
-int write_drop_in(const char *dir, const char *unit,
+int write_drop_in(const char *dir, const char *unit, unsigned level,
const char *name, const char *data);
-int write_drop_in_format(const char *dir, const char *unit,
+int write_drop_in_format(const char *dir, const char *unit, unsigned level,
const char *name, const char *format, ...);
diff --git a/src/shared/generator.c b/src/shared/generator.c
index 1db5f8f..5d5b6a0 100644
--- a/src/shared/generator.c
+++ b/src/shared/generator.c
@@ -108,7 +108,7 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
timeout = start + 25;
else {
if (filtered) {
- *filtered = strdup(opts);
+ *filtered = strdup(opts ?: "");
if (!*filtered)
return log_oom();
}
@@ -146,6 +146,9 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
if (!unit)
return -ENOMEM;
- return write_drop_in_format(dir, unit, "device-timeout",
- "[Unit]\nJobTimeoutSec=%u", u / USEC_PER_SEC);
+ return write_drop_in_format(dir, unit, 50, "device-timeout",
+ "# Automatically generated by %s\n\n"
+ "[Unit]\nJobTimeoutSec=%u",
+ program_invocation_short_name,
+ u / USEC_PER_SEC);
}
commit b3208b662948b51ff34e7b7752e28ec7a48708ae
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Fri Jun 27 15:03:05 2014 -0400
fstab-generator: allow x-systemd.device-timeout for swap units
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 6f392df..1256a1c 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -129,6 +129,11 @@ static int add_swap(const char *what, struct mntent *me) {
return -errno;
}
+ /* use what as where, to have a nicer error message */
+ r = generator_write_timeouts(arg_dest, what, what, me->mnt_opts, NULL);
+ if (r < 0)
+ return r;
+
if (!noauto) {
lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
if (!lnk)
diff --git a/src/shared/generator.c b/src/shared/generator.c
index 762033b..1db5f8f 100644
--- a/src/shared/generator.c
+++ b/src/shared/generator.c
@@ -97,7 +97,7 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
* user input, like crypto devices. */
_cleanup_free_ char *node = NULL, *unit = NULL, *t = NULL;
- char *prefix, *start, *timeout, *postfix;
+ char *start, *timeout;
usec_t u;
int r;
size_t len;
@@ -107,9 +107,11 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
else if ((start = mount_test_option(opts, "x-systemd.device-timeout")))
timeout = start + 25;
else {
- *filtered = strdup(opts);
- if (!*filtered)
- return log_oom();
+ if (filtered) {
+ *filtered = strdup(opts);
+ if (!*filtered)
+ return log_oom();
+ }
return 0;
}
@@ -119,11 +121,15 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
if (!t)
return -ENOMEM;
- prefix = strndupa(opts, start - opts - (start != opts));
- postfix = timeout + len + (timeout[len] != '\0');
- *filtered = strjoin(prefix, *postfix ? postfix : NULL, NULL);
- if (!*filtered)
- return log_oom();
+ if (filtered) {
+ char *prefix, *postfix;
+
+ prefix = strndupa(opts, start - opts - (start != opts));
+ postfix = timeout + len + (timeout[len] != '\0');
+ *filtered = strjoin(prefix, *postfix ? postfix : NULL, NULL);
+ if (!*filtered)
+ return log_oom();
+ }
r = parse_sec(t, &u);
if (r < 0) {
commit 2968644080fd103062f070e83edd620e0a58c44d
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Fri Jun 27 12:12:07 2014 -0400
Move x-systemd-device.timeout handling from core to fstab-generator
Instead of adjusting job timeouts in the core, let fstab-generator
write out a dropin snippet with the appropriate JobTimeout.
x-systemd-device.timeout option is removed from Options= line
in the generated unit.
The functions to write dropins are moved from core/unit.c to
shared/dropin.c, to make them available outside of core.
generator.c is moved to libsystemd-label, because it now uses
functions defined in dropin.c, which are in libsystemd-label.
diff --git a/Makefile.am b/Makefile.am
index 60f69fe..783f5fe 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -816,8 +816,6 @@ libsystemd_shared_la_SOURCES = \
src/shared/bus-label.c \
src/shared/bus-label.h \
src/shared/gpt.h \
- src/shared/generator.h \
- src/shared/generator.c \
src/shared/clean-ipc.h \
src/shared/clean-ipc.c \
src/shared/login-shared.c \
@@ -874,7 +872,11 @@ libsystemd_label_la_SOURCES = \
src/shared/fileio-label.c \
src/shared/fileio-label.h \
src/shared/dev-setup.c \
- src/shared/dev-setup.h
+ src/shared/dev-setup.h \
+ src/shared/dropin.c \
+ src/shared/dropin.h \
+ src/shared/generator.h \
+ src/shared/generator.c
libsystemd_label_la_CFLAGS = \
$(AM_CFLAGS) \
diff --git a/src/core/mount.c b/src/core/mount.c
index aea2ab1..102bbef 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -418,57 +418,6 @@ static int mount_add_default_dependencies(Mount *m) {
return 0;
}
-static int mount_fix_timeouts(Mount *m) {
- MountParameters *p;
- const char *timeout = NULL;
- Unit *other;
- Iterator i;
- usec_t u;
- char *t;
- int r;
-
- assert(m);
-
- p = get_mount_parameters_fragment(m);
- if (!p)
- return 0;
-
- /* Allow configuration how long we wait for a device that
- * backs a mount point to show up. This is useful to support
- * endless device timeouts for devices that show up only after
- * user input, like crypto devices. */
-
- if ((timeout = mount_test_option(p->options, "comment=systemd.device-timeout")))
- timeout += 31;
- else if ((timeout = mount_test_option(p->options, "x-systemd.device-timeout")))
- timeout += 25;
- else
- return 0;
-
- t = strndup(timeout, strcspn(timeout, ",;" WHITESPACE));
- if (!t)
- return -ENOMEM;
-
- r = parse_sec(t, &u);
- free(t);
-
- if (r < 0) {
- log_warning_unit(UNIT(m)->id,
- "Failed to parse timeout for %s, ignoring: %s",
- m->where, timeout);
- return r;
- }
-
- SET_FOREACH(other, UNIT(m)->dependencies[UNIT_AFTER], i) {
- if (other->type != UNIT_DEVICE)
- continue;
-
- other->job_timeout = u;
- }
-
- return 0;
-}
-
static int mount_verify(Mount *m) {
_cleanup_free_ char *e = NULL;
bool b;
@@ -556,10 +505,6 @@ static int mount_add_extras(Mount *m) {
if (r < 0)
return r;
- r = mount_fix_timeouts(m);
- if (r < 0)
- return r;
-
if (u->default_dependencies) {
r = mount_add_default_dependencies(m);
if (r < 0)
diff --git a/src/core/unit.c b/src/core/unit.c
index 6e40bc6..bace69f 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -51,6 +51,7 @@
#include "dbus.h"
#include "execute.h"
#include "virt.h"
+#include "dropin.h"
const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = {
[UNIT_SERVICE] = &service_vtable,
@@ -2966,68 +2967,55 @@ ExecRuntime *unit_get_exec_runtime(Unit *u) {
return *(ExecRuntime**) ((uint8_t*) u + offset);
}
-static int drop_in_file(Unit *u, UnitSetPropertiesMode mode, const char *name, char **_p, char **_q) {
- _cleanup_free_ char *b = NULL;
- char *p, *q;
- int r;
-
- assert(u);
- assert(name);
- assert(_p);
- assert(_q);
-
- b = xescape(name, "/.");
- if (!b)
- return -ENOMEM;
-
- if (!filename_is_safe(b))
- return -EINVAL;
-
+static int unit_drop_in_dir(Unit *u, UnitSetPropertiesMode mode, bool transient, char **dir) {
if (u->manager->running_as == SYSTEMD_USER) {
- _cleanup_free_ char *c = NULL;
+ int r;
- r = user_config_home(&c);
- if (r < 0)
- return r;
+ r = user_config_home(dir);
if (r == 0)
return -ENOENT;
+ return r;
+ }
- p = strjoin(c, "/", u->id, ".d", NULL);
- } else if (mode == UNIT_PERSISTENT && !u->transient)
- p = strjoin("/etc/systemd/system/", u->id, ".d", NULL);
+ if (mode == UNIT_PERSISTENT && !transient)
+ *dir = strdup("/etc/systemd/system");
else
- p = strjoin("/run/systemd/system/", u->id, ".d", NULL);
- if (!p)
+ *dir = strdup("/run/systemd/system");
+ if (!*dir)
return -ENOMEM;
- q = strjoin(p, "/90-", b, ".conf", NULL);
- if (!q) {
- free(p);
- return -ENOMEM;
- }
-
- *_p = p;
- *_q = q;
return 0;
}
+static int unit_drop_in_file(Unit *u,
+ UnitSetPropertiesMode mode, const char *name, char **p, char **q) {
+ _cleanup_free_ char *dir = NULL;
+ int r;
+
+ assert(u);
+
+ r = unit_drop_in_dir(u, mode, u->transient, &dir);
+ if (r < 0)
+ return r;
+
+ return drop_in_file(dir, u->id, name, p, q);
+}
+
int unit_write_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *data) {
- _cleanup_free_ char *p = NULL, *q = NULL;
+
+ _cleanup_free_ char *dir = NULL;
int r;
assert(u);
- assert(name);
- assert(data);
if (!IN_SET(mode, UNIT_PERSISTENT, UNIT_RUNTIME))
return 0;
- r = drop_in_file(u, mode, name, &p, &q);
+ r = unit_drop_in_dir(u, mode, u->transient, &dir);
if (r < 0)
return r;
- mkdir_p(p, 0755);
- return write_string_file_atomic_label(q, data);
+ return write_drop_in(dir, u->id, name, data);
}
int unit_write_drop_in_format(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *format, ...) {
@@ -3103,7 +3091,7 @@ int unit_remove_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name) {
if (!IN_SET(mode, UNIT_PERSISTENT, UNIT_RUNTIME))
return 0;
- r = drop_in_file(u, mode, name, &p, &q);
+ r = unit_drop_in_file(u, mode, name, &p, &q);
if (r < 0)
return r;
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 98772fb..6f392df 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -44,6 +44,7 @@ static char *arg_root_fstype = NULL;
static char *arg_root_options = NULL;
static int arg_root_rw = -1;
+
static int mount_find_pri(struct mntent *me, int *ret) {
char *end, *pri;
unsigned long r;
@@ -173,7 +174,8 @@ static int add_mount(
_cleanup_free_ char
*name = NULL, *unit = NULL, *lnk = NULL,
- *automount_name = NULL, *automount_unit = NULL;
+ *automount_name = NULL, *automount_unit = NULL,
+ *filtered = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
@@ -245,8 +247,12 @@ static int add_mount(
if (!isempty(fstype) && !streq(fstype, "auto"))
fprintf(f, "Type=%s\n", fstype);
- if (!isempty(opts) && !streq(opts, "defaults"))
- fprintf(f, "Options=%s\n", opts);
+ r = generator_write_timeouts(arg_dest, what, where, opts, &filtered);
+ if (r < 0)
+ return r;
+
+ if (!isempty(filtered) && !streq(filtered, "defaults"))
+ fprintf(f, "Options=%s\n", filtered);
fflush(f);
if (ferror(f)) {
diff --git a/src/shared/dropin.c b/src/shared/dropin.c
new file mode 100644
index 0000000..7774236
--- /dev/null
+++ b/src/shared/dropin.c
@@ -0,0 +1,98 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Zbigniew JÄdrzejewski-Szmek
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "dropin.h"
+#include "util.h"
+#include "mkdir.h"
+#include "fileio-label.h"
+
+int drop_in_file(const char *dir, const char *unit,
+ const char *name, char **_p, char **_q) {
+
+ _cleanup_free_ char *b = NULL;
+ char *p, *q;
+
+ assert(unit);
+ assert(name);
+ assert(_p);
+ assert(_q);
+
+ b = xescape(name, "/.");
+ if (!b)
+ return -ENOMEM;
+
+ if (!filename_is_safe(b))
+ return -EINVAL;
+
+ p = strjoin(dir, "/", unit, ".d", NULL);
+ if (!p)
+ return -ENOMEM;
+
+ q = strjoin(p, "/90-", b, ".conf", NULL);
+ if (!q) {
+ free(p);
+ return -ENOMEM;
+ }
+
+ *_p = p;
+ *_q = q;
+ return 0;
+}
+
+int write_drop_in(const char *dir, const char *unit,
+ const char *name, const char *data) {
+
+ _cleanup_free_ char *p = NULL, *q = NULL;
+ int r;
+
+ assert(dir);
+ assert(unit);
+ assert(name);
+ assert(data);
+
+ r = drop_in_file(dir, unit, name, &p, &q);
+ if (r < 0)
+ return r;
+
+ mkdir_p(p, 0755);
+ return write_string_file_atomic_label(q, data);
+}
+
+int write_drop_in_format(const char *dir, const char *unit,
+ const char *name, const char *format, ...) {
+ _cleanup_free_ char *p = NULL;
+ va_list ap;
+ int r;
+
+ assert(dir);
+ assert(unit);
+ assert(name);
+ assert(format);
+
+ va_start(ap, format);
+ r = vasprintf(&p, format, ap);
+ va_end(ap);
+
+ if (r < 0)
+ return -ENOMEM;
+
+ return write_drop_in(dir, unit, name, p);
+}
diff --git a/src/shared/dropin.h b/src/shared/dropin.h
new file mode 100644
index 0000000..2958632
--- /dev/null
+++ b/src/shared/dropin.h
@@ -0,0 +1,31 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Zbigniew JÄdrzejewski-Szmek
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+int drop_in_file(const char *dir, const char *unit,
+ const char *name, char **_p, char **_q);
+
+int write_drop_in(const char *dir, const char *unit,
+ const char *name, const char *data);
+
+int write_drop_in_format(const char *dir, const char *unit,
+ const char *name, const char *format, ...);
diff --git a/src/shared/generator.c b/src/shared/generator.c
index dcfddaa..762033b 100644
--- a/src/shared/generator.c
+++ b/src/shared/generator.c
@@ -28,6 +28,7 @@
#include "unit-name.h"
#include "generator.h"
#include "path-util.h"
+#include "dropin.h"
int generator_write_fsck_deps(
FILE *f,
@@ -86,3 +87,59 @@ int generator_write_fsck_deps(
return 0;
}
+
+int generator_write_timeouts(const char *dir, const char *what, const char *where,
+ const char *opts, char **filtered) {
+
+ /* Allow configuration how long we wait for a device that
+ * backs a mount point to show up. This is useful to support
+ * endless device timeouts for devices that show up only after
+ * user input, like crypto devices. */
+
+ _cleanup_free_ char *node = NULL, *unit = NULL, *t = NULL;
+ char *prefix, *start, *timeout, *postfix;
+ usec_t u;
+ int r;
+ size_t len;
+
+ if ((start = mount_test_option(opts, "comment=systemd.device-timeout")))
+ timeout = start + 31;
+ else if ((start = mount_test_option(opts, "x-systemd.device-timeout")))
+ timeout = start + 25;
+ else {
+ *filtered = strdup(opts);
+ if (!*filtered)
+ return log_oom();
+
+ return 0;
+ }
+
+ len = strcspn(timeout, ",;" WHITESPACE);
+ t = strndup(timeout, len);
+ if (!t)
+ return -ENOMEM;
+
+ prefix = strndupa(opts, start - opts - (start != opts));
+ postfix = timeout + len + (timeout[len] != '\0');
+ *filtered = strjoin(prefix, *postfix ? postfix : NULL, NULL);
+ if (!*filtered)
+ return log_oom();
+
+ r = parse_sec(t, &u);
+ if (r < 0) {
+ log_warning("Failed to parse timeout for %s, ignoring: %s",
+ where, timeout);
+ return 0;
+ }
+
+ node = fstab_node_to_udev_node(what);
+ if (!node)
+ return log_oom();
+
+ unit = unit_name_from_path(node, ".device");
+ if (!unit)
+ return -ENOMEM;
+
+ return write_drop_in_format(dir, unit, "device-timeout",
+ "[Unit]\nJobTimeoutSec=%u", u / USEC_PER_SEC);
+}
diff --git a/src/shared/generator.h b/src/shared/generator.h
index 0140aa9..64bd28f 100644
--- a/src/shared/generator.h
+++ b/src/shared/generator.h
@@ -24,3 +24,6 @@
#include <stdio.h>
int generator_write_fsck_deps(FILE *f, const char *dest, const char *what, const char *where, const char *type);
+
+int generator_write_timeouts(const char *dir, const char *what, const char *where,
+ const char *opts, char **filtered);
diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h
index 847a52f..4c77bee 100644
--- a/src/shared/path-lookup.h
+++ b/src/shared/path-lookup.h
@@ -21,6 +21,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "macro.h"
+
typedef struct LookupPaths {
char **unit_path;
#ifdef HAVE_SYSV_COMPAT
More information about the systemd-commits
mailing list