chiark / gitweb /
fsck: Search for fsck.type in PATH
[elogind.git] / src / shared / generator.c
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 <string.h>
23 #include <unistd.h>
24
25 #include "util.h"
26 #include "special.h"
27 #include "mkdir.h"
28 #include "unit-name.h"
29 #include "generator.h"
30 #include "path-util.h"
31
32 int generator_write_fsck_deps(
33                 FILE *f,
34                 const char *dest,
35                 const char *what,
36                 const char *where,
37                 const char *fstype) {
38
39         assert(f);
40         assert(dest);
41         assert(what);
42         assert(where);
43
44         if (!is_device_path(what)) {
45                 log_warning("Checking was requested for \"%s\", but it is not a device.", what);
46                 return 0;
47         }
48
49         if (!isempty(fstype) && !streq(fstype, "auto")) {
50                 int r;
51                 r = fsck_exists(fstype);
52                 if (r < 0) {
53                         log_warning("Checking was requested for %s, but fsck.%s cannot be used: %s", what, fstype, strerror(-r));
54                         /* treat missing check as essentially OK */
55                         return r == -ENOENT ? 0 : r;
56                 }
57         }
58
59         if (streq(where, "/")) {
60                 char *lnk;
61
62                 lnk = strappenda(dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service");
63
64                 mkdir_parents(lnk, 0755);
65                 if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) {
66                         log_error("Failed to create symlink %s: %m", lnk);
67                         return -errno;
68                 }
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 }