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