1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
28 #include "unit-name.h"
29 #include "generator.h"
30 #include "path-util.h"
33 int generator_write_fsck_deps(
45 if (!is_device_path(what)) {
46 log_warning("Checking was requested for \"%s\", but it is not a device.", what);
50 if (!isempty(fstype) && !streq(fstype, "auto")) {
52 r = fsck_exists(fstype);
54 /* treat missing check as essentially OK */
55 log_debug("Checking was requested for %s, but fsck.%s does not exist: %s", what, fstype, strerror(-r));
58 log_warning("Checking was requested for %s, but fsck.%s cannot be used: %s", what, fstype, strerror(-r));
63 if (streq(where, "/")) {
66 lnk = strappenda(dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service");
68 mkdir_parents(lnk, 0755);
69 if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) {
70 log_error("Failed to create symlink %s: %m", lnk);
75 _cleanup_free_ char *fsck = NULL;
77 fsck = unit_name_from_path_instance("systemd-fsck", what, ".service");
82 "RequiresOverridable=%s\n"
91 int generator_write_timeouts(const char *dir, const char *what, const char *where,
92 const char *opts, char **filtered) {
94 /* Allow configuration how long we wait for a device that
95 * backs a mount point to show up. This is useful to support
96 * endless device timeouts for devices that show up only after
97 * user input, like crypto devices. */
99 _cleanup_free_ char *node = NULL, *unit = NULL, *t = NULL;
100 char *start, *timeout;
105 if ((start = mount_test_option(opts, "comment=systemd.device-timeout")))
106 timeout = start + 31;
107 else if ((start = mount_test_option(opts, "x-systemd.device-timeout")))
108 timeout = start + 25;
111 *filtered = strdup(opts ?: "");
119 len = strcspn(timeout, ",;" WHITESPACE);
120 t = strndup(timeout, len);
125 char *prefix, *postfix;
127 prefix = strndupa(opts, start - opts - (start != opts));
128 postfix = timeout + len + (start == opts && timeout[len] != '\0');
129 *filtered = strjoin(prefix, *postfix ? postfix : NULL, NULL);
134 r = parse_sec(t, &u);
136 log_warning("Failed to parse timeout for %s, ignoring: %s",
141 node = fstab_node_to_udev_node(what);
145 unit = unit_name_from_path(node, ".device");
149 return write_drop_in_format(dir, unit, 50, "device-timeout",
150 "# Automatically generated by %s\n\n"
151 "[Unit]\nJobTimeoutSec=" USEC_FMT,
152 program_invocation_short_name,