]>
Commit | Line | Data |
---|---|---|
e48fdd84 LP |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2014 Lennart Poettering | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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/>. | |
20 | ***/ | |
21 | ||
22 | #include <unistd.h> | |
23 | ||
24 | #include "util.h" | |
25 | #include "special.h" | |
26 | #include "mkdir.h" | |
27 | #include "unit-name.h" | |
28 | #include "generator.h" | |
eb66db55 | 29 | #include "path-util.h" |
d15d0333 | 30 | #include "fstab-util.h" |
29686440 | 31 | #include "dropin.h" |
e48fdd84 LP |
32 | |
33 | int generator_write_fsck_deps( | |
34 | FILE *f, | |
35 | const char *dest, | |
36 | const char *what, | |
37 | const char *where, | |
6db615c1 | 38 | const char *fstype) { |
e48fdd84 LP |
39 | |
40 | assert(f); | |
6db615c1 LP |
41 | assert(dest); |
42 | assert(what); | |
43 | assert(where); | |
e48fdd84 LP |
44 | |
45 | if (!is_device_path(what)) { | |
46 | log_warning("Checking was requested for \"%s\", but it is not a device.", what); | |
47 | return 0; | |
48 | } | |
49 | ||
6db615c1 | 50 | if (!isempty(fstype) && !streq(fstype, "auto")) { |
e48fdd84 | 51 | int r; |
eb66db55 | 52 | r = fsck_exists(fstype); |
571d0134 | 53 | if (r == -ENOENT) { |
e48fdd84 | 54 | /* treat missing check as essentially OK */ |
da927ba9 | 55 | log_debug_errno(r, "Checking was requested for %s, but fsck.%s does not exist: %m", what, fstype); |
571d0134 | 56 | return 0; |
f647962d MS |
57 | } else if (r < 0) |
58 | return log_warning_errno(r, "Checking was requested for %s, but fsck.%s cannot be used: %m", what, fstype); | |
e48fdd84 LP |
59 | } |
60 | ||
61 | if (streq(where, "/")) { | |
62 | char *lnk; | |
63 | ||
63c372cb | 64 | lnk = strjoina(dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service"); |
e48fdd84 LP |
65 | |
66 | mkdir_parents(lnk, 0755); | |
4a62c710 MS |
67 | if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) |
68 | return log_error_errno(errno, "Failed to create symlink %s: %m", lnk); | |
e48fdd84 LP |
69 | |
70 | } else { | |
71 | _cleanup_free_ char *fsck = NULL; | |
72 | ||
73 | fsck = unit_name_from_path_instance("systemd-fsck", what, ".service"); | |
74 | if (!fsck) | |
75 | return log_oom(); | |
76 | ||
77 | fprintf(f, | |
78 | "RequiresOverridable=%s\n" | |
79 | "After=%s\n", | |
80 | fsck, | |
81 | fsck); | |
82 | } | |
83 | ||
84 | return 0; | |
85 | } | |
29686440 ZJS |
86 | |
87 | int generator_write_timeouts(const char *dir, const char *what, const char *where, | |
88 | const char *opts, char **filtered) { | |
89 | ||
90 | /* Allow configuration how long we wait for a device that | |
91 | * backs a mount point to show up. This is useful to support | |
92 | * endless device timeouts for devices that show up only after | |
93 | * user input, like crypto devices. */ | |
94 | ||
d15d0333 | 95 | _cleanup_free_ char *node = NULL, *unit = NULL, *timeout = NULL; |
29686440 ZJS |
96 | usec_t u; |
97 | int r; | |
29686440 | 98 | |
d15d0333 ZJS |
99 | r = fstab_filter_options(opts, "comment=systemd.device-timeout\0" "x-systemd.device-timeout\0", |
100 | NULL, &timeout, filtered); | |
101 | if (r <= 0) | |
102 | return r; | |
b3208b66 | 103 | |
d15d0333 | 104 | r = parse_sec(timeout, &u); |
29686440 ZJS |
105 | if (r < 0) { |
106 | log_warning("Failed to parse timeout for %s, ignoring: %s", | |
107 | where, timeout); | |
108 | return 0; | |
109 | } | |
110 | ||
111 | node = fstab_node_to_udev_node(what); | |
112 | if (!node) | |
113 | return log_oom(); | |
114 | ||
115 | unit = unit_name_from_path(node, ".device"); | |
116 | if (!unit) | |
d15d0333 | 117 | return log_oom(); |
29686440 | 118 | |
8eea8687 ZJS |
119 | return write_drop_in_format(dir, unit, 50, "device-timeout", |
120 | "# Automatically generated by %s\n\n" | |
de48d5ab | 121 | "[Unit]\nJobTimeoutSec=" USEC_FMT, |
8eea8687 ZJS |
122 | program_invocation_short_name, |
123 | u / USEC_PER_SEC); | |
29686440 | 124 | } |