]>
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" | |
29 | ||
30 | int generator_write_fsck_deps( | |
31 | FILE *f, | |
32 | const char *dest, | |
33 | const char *what, | |
34 | const char *where, | |
6db615c1 | 35 | const char *fstype) { |
e48fdd84 LP |
36 | |
37 | assert(f); | |
6db615c1 LP |
38 | assert(dest); |
39 | assert(what); | |
40 | assert(where); | |
e48fdd84 LP |
41 | |
42 | if (!is_device_path(what)) { | |
43 | log_warning("Checking was requested for \"%s\", but it is not a device.", what); | |
44 | return 0; | |
45 | } | |
46 | ||
6db615c1 | 47 | if (!isempty(fstype) && !streq(fstype, "auto")) { |
e48fdd84 LP |
48 | const char *checker; |
49 | int r; | |
50 | ||
6db615c1 | 51 | checker = strappenda("/sbin/fsck.", fstype); |
e48fdd84 LP |
52 | r = access(checker, X_OK); |
53 | if (r < 0) { | |
54 | log_warning("Checking was requested for %s, but %s cannot be used: %m", what, checker); | |
55 | ||
56 | /* treat missing check as essentially OK */ | |
57 | return errno == ENOENT ? 0 : -errno; | |
58 | } | |
59 | } | |
60 | ||
61 | if (streq(where, "/")) { | |
62 | char *lnk; | |
63 | ||
64 | lnk = strappenda(dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service"); | |
65 | ||
66 | mkdir_parents(lnk, 0755); | |
67 | if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) { | |
68 | log_error("Failed to create symlink %s: %m", lnk); | |
69 | return -errno; | |
70 | } | |
71 | ||
72 | } else { | |
73 | _cleanup_free_ char *fsck = NULL; | |
74 | ||
75 | fsck = unit_name_from_path_instance("systemd-fsck", what, ".service"); | |
76 | if (!fsck) | |
77 | return log_oom(); | |
78 | ||
79 | fprintf(f, | |
80 | "RequiresOverridable=%s\n" | |
81 | "After=%s\n", | |
82 | fsck, | |
83 | fsck); | |
84 | } | |
85 | ||
86 | return 0; | |
87 | } |