Systemd/src/shared/generator.c
Lennart Poettering e48fdd8443 generators: rework mount generators
- Add support for finding and mounting /srv based on GPT data, similar
  to how we already handly /home.

- Share the fsck logic between GPT, EFI and fstab generators

- Make sure we never run the EFI generator inside containers

- Drop DefaultDependencies=no from EFI mount units

- Other fixes
2014-03-06 04:00:41 +01:00

85 lines
2.6 KiB
C

/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <unistd.h>
#include "util.h"
#include "special.h"
#include "mkdir.h"
#include "unit-name.h"
#include "generator.h"
int generator_write_fsck_deps(
FILE *f,
const char *dest,
const char *what,
const char *where,
const char *type) {
assert(f);
if (!is_device_path(what)) {
log_warning("Checking was requested for \"%s\", but it is not a device.", what);
return 0;
}
if (type && !streq(type, "auto")) {
const char *checker;
int r;
checker = strappenda("/sbin/fsck.", type);
r = access(checker, X_OK);
if (r < 0) {
log_warning("Checking was requested for %s, but %s cannot be used: %m", what, checker);
/* treat missing check as essentially OK */
return errno == ENOENT ? 0 : -errno;
}
}
if (streq(where, "/")) {
char *lnk;
lnk = strappenda(dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service");
mkdir_parents(lnk, 0755);
if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) {
log_error("Failed to create symlink %s: %m", lnk);
return -errno;
}
} else {
_cleanup_free_ char *fsck = NULL;
fsck = unit_name_from_path_instance("systemd-fsck", what, ".service");
if (!fsck)
return log_oom();
fprintf(f,
"RequiresOverridable=%s\n"
"After=%s\n",
fsck,
fsck);
}
return 0;
}