]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/generator.c
man: reference $TMPDIR, not $TMP in file-hierarchy(7)
[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
eb66db55 22#include <string.h>
e48fdd84
LP
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"
eb66db55 30#include "path-util.h"
e48fdd84
LP
31
32int generator_write_fsck_deps(
33 FILE *f,
34 const char *dest,
35 const char *what,
36 const char *where,
6db615c1 37 const char *fstype) {
e48fdd84
LP
38
39 assert(f);
6db615c1
LP
40 assert(dest);
41 assert(what);
42 assert(where);
e48fdd84
LP
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
6db615c1 49 if (!isempty(fstype) && !streq(fstype, "auto")) {
e48fdd84 50 int r;
eb66db55 51 r = fsck_exists(fstype);
571d0134 52 if (r == -ENOENT) {
e48fdd84 53 /* treat missing check as essentially OK */
571d0134
LP
54 log_debug("Checking was requested for %s, but fsck.%s does not exist: %s", what, fstype, strerror(-r));
55 return 0;
56 } else if (r < 0) {
57 log_warning("Checking was requested for %s, but fsck.%s cannot be used: %s", what, fstype, strerror(-r));
58 return r;
e48fdd84
LP
59 }
60 }
61
62 if (streq(where, "/")) {
63 char *lnk;
64
65 lnk = strappenda(dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service");
66
67 mkdir_parents(lnk, 0755);
68 if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) {
69 log_error("Failed to create symlink %s: %m", lnk);
70 return -errno;
71 }
72
73 } else {
74 _cleanup_free_ char *fsck = NULL;
75
76 fsck = unit_name_from_path_instance("systemd-fsck", what, ".service");
77 if (!fsck)
78 return log_oom();
79
80 fprintf(f,
81 "RequiresOverridable=%s\n"
82 "After=%s\n",
83 fsck,
84 fsck);
85 }
86
87 return 0;
88}