2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2014-03-05 22:26:10 +01:00
|
|
|
|
2015-12-03 21:13:37 +01:00
|
|
|
#include <errno.h>
|
2017-12-09 19:23:26 +01:00
|
|
|
#include <stdio_ext.h>
|
2014-03-05 22:26:10 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "alloc-util.h"
|
2015-10-23 18:52:53 +02:00
|
|
|
#include "dropin.h"
|
|
|
|
#include "escape.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "fd-util.h"
|
2015-10-23 18:52:53 +02:00
|
|
|
#include "fileio.h"
|
|
|
|
#include "fstab-util.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "generator.h"
|
2015-12-03 21:13:37 +01:00
|
|
|
#include "log.h"
|
|
|
|
#include "macro.h"
|
2014-03-05 22:26:10 +01:00
|
|
|
#include "mkdir.h"
|
2015-10-23 18:52:53 +02:00
|
|
|
#include "path-util.h"
|
|
|
|
#include "special.h"
|
2017-11-21 20:09:31 +01:00
|
|
|
#include "specifier.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
2015-12-03 21:13:37 +01:00
|
|
|
#include "time-util.h"
|
2014-03-05 22:26:10 +01:00
|
|
|
#include "unit-name.h"
|
2015-10-23 18:52:53 +02:00
|
|
|
#include "util.h"
|
2014-03-05 22:26:10 +01:00
|
|
|
|
2017-12-09 19:23:26 +01:00
|
|
|
int generator_open_unit_file(
|
|
|
|
const char *dest,
|
|
|
|
const char *source,
|
|
|
|
const char *name,
|
|
|
|
FILE **file) {
|
|
|
|
|
|
|
|
const char *unit;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
unit = strjoina(dest, "/", name);
|
|
|
|
|
|
|
|
f = fopen(unit, "wxe");
|
|
|
|
if (!f) {
|
|
|
|
if (source && errno == EEXIST)
|
|
|
|
return log_error_errno(errno,
|
|
|
|
"Failed to create unit file %s, as it already exists. Duplicate entry in %s?",
|
|
|
|
unit, source);
|
|
|
|
else
|
|
|
|
return log_error_errno(errno,
|
|
|
|
"Failed to create unit file %s: %m",
|
|
|
|
unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) __fsetlocking(f, FSETLOCKING_BYCALLER);
|
|
|
|
|
|
|
|
fprintf(f,
|
|
|
|
"# Automatically generated by %s\n\n",
|
|
|
|
program_invocation_short_name);
|
|
|
|
|
|
|
|
*file = f;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-10 05:31:47 +02:00
|
|
|
int generator_add_symlink(const char *root, const char *dst, const char *dep_type, const char *src) {
|
|
|
|
/* Adds a symlink from <dst>.<dep_type>.d/ to ../<src> */
|
|
|
|
|
|
|
|
const char *from, *to;
|
|
|
|
|
|
|
|
from = strjoina("../", src);
|
|
|
|
to = strjoina(root, "/", dst, ".", dep_type, "/", src);
|
|
|
|
|
|
|
|
mkdir_parents_label(to, 0755);
|
|
|
|
if (symlink(from, to) < 0)
|
2017-07-10 05:59:30 +02:00
|
|
|
if (errno != EEXIST)
|
|
|
|
return log_error_errno(errno, "Failed to create symlink \"%s\": %m", to);
|
2017-07-10 05:31:47 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-06 07:09:53 +02:00
|
|
|
static int write_fsck_sysroot_service(const char *dir, const char *what) {
|
2017-11-21 20:09:31 +01:00
|
|
|
_cleanup_free_ char *device = NULL, *escaped = NULL, *escaped2 = NULL;
|
2015-05-06 07:09:53 +02:00
|
|
|
_cleanup_fclose_ FILE *f = NULL;
|
2015-10-22 18:24:59 +02:00
|
|
|
const char *unit;
|
2015-05-06 07:09:53 +02:00
|
|
|
int r;
|
|
|
|
|
2017-11-21 20:09:31 +01:00
|
|
|
escaped = specifier_escape(what);
|
2015-06-03 19:50:59 +02:00
|
|
|
if (!escaped)
|
|
|
|
return log_oom();
|
|
|
|
|
2017-11-21 20:09:31 +01:00
|
|
|
escaped2 = cescape(escaped);
|
|
|
|
if (!escaped2)
|
|
|
|
return log_oom();
|
|
|
|
|
2015-05-06 07:09:53 +02:00
|
|
|
unit = strjoina(dir, "/systemd-fsck-root.service");
|
|
|
|
log_debug("Creating %s", unit);
|
|
|
|
|
|
|
|
r = unit_name_from_path(what, ".device", &device);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to convert device \"%s\" to unit name: %m", what);
|
|
|
|
|
|
|
|
f = fopen(unit, "wxe");
|
|
|
|
if (!f)
|
|
|
|
return log_error_errno(errno, "Failed to create unit file %s: %m", unit);
|
|
|
|
|
|
|
|
fprintf(f,
|
|
|
|
"# Automatically generated by %1$s\n\n"
|
|
|
|
"[Unit]\n"
|
|
|
|
"Description=File System Check on %2$s\n"
|
2017-11-21 23:18:05 +01:00
|
|
|
"Documentation=man:systemd-fsck-root.service(8)\n"
|
2015-05-06 07:09:53 +02:00
|
|
|
"DefaultDependencies=no\n"
|
|
|
|
"BindsTo=%3$s\n"
|
2016-12-07 20:00:31 +01:00
|
|
|
"After=initrd-root-device.target local-fs-pre.target %3$s\n"
|
2015-05-06 07:09:53 +02:00
|
|
|
"Before=shutdown.target\n"
|
|
|
|
"\n"
|
|
|
|
"[Service]\n"
|
|
|
|
"Type=oneshot\n"
|
|
|
|
"RemainAfterExit=yes\n"
|
2015-06-03 19:50:59 +02:00
|
|
|
"ExecStart=" SYSTEMD_FSCK_PATH " %4$s\n"
|
2015-05-06 07:09:53 +02:00
|
|
|
"TimeoutSec=0\n",
|
|
|
|
program_invocation_short_name,
|
2017-11-21 20:09:31 +01:00
|
|
|
escaped,
|
2015-06-03 19:50:59 +02:00
|
|
|
device,
|
2017-11-21 20:09:31 +01:00
|
|
|
escaped2);
|
2015-05-06 07:09:53 +02:00
|
|
|
|
2015-05-15 17:06:59 +02:00
|
|
|
r = fflush_and_check(f);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to write unit file %s: %m", unit);
|
2015-05-06 07:09:53 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-05 22:26:10 +01:00
|
|
|
int generator_write_fsck_deps(
|
|
|
|
FILE *f,
|
2015-05-02 19:01:29 +02:00
|
|
|
const char *dir,
|
2014-03-05 22:26:10 +01:00
|
|
|
const char *what,
|
|
|
|
const char *where,
|
2014-03-06 21:14:26 +01:00
|
|
|
const char *fstype) {
|
2014-03-05 22:26:10 +01:00
|
|
|
|
2015-04-30 20:21:00 +02:00
|
|
|
int r;
|
|
|
|
|
2014-03-05 22:26:10 +01:00
|
|
|
assert(f);
|
2015-05-02 19:01:29 +02:00
|
|
|
assert(dir);
|
2014-03-06 21:14:26 +01:00
|
|
|
assert(what);
|
|
|
|
assert(where);
|
2014-03-05 22:26:10 +01:00
|
|
|
|
|
|
|
if (!is_device_path(what)) {
|
|
|
|
log_warning("Checking was requested for \"%s\", but it is not a device.", what);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-06 21:14:26 +01:00
|
|
|
if (!isempty(fstype) && !streq(fstype, "auto")) {
|
2014-04-12 22:07:45 +02:00
|
|
|
r = fsck_exists(fstype);
|
2015-10-22 18:24:59 +02:00
|
|
|
if (r < 0)
|
|
|
|
log_warning_errno(r, "Checking was requested for %s, but couldn't detect if fsck.%s may be used, proceeding: %m", what, fstype);
|
|
|
|
else if (r == 0) {
|
2014-03-05 22:26:10 +01:00
|
|
|
/* treat missing check as essentially OK */
|
2015-10-22 18:24:59 +02:00
|
|
|
log_debug("Checking was requested for %s, but fsck.%s does not exist.", what, fstype);
|
2014-06-24 19:37:22 +02:00
|
|
|
return 0;
|
2015-10-22 18:24:59 +02:00
|
|
|
}
|
2014-03-05 22:26:10 +01:00
|
|
|
}
|
|
|
|
|
2015-05-02 19:01:29 +02:00
|
|
|
if (path_equal(where, "/")) {
|
2015-10-22 18:24:59 +02:00
|
|
|
const char *lnk;
|
2014-03-05 22:26:10 +01:00
|
|
|
|
2015-05-02 19:01:29 +02:00
|
|
|
lnk = strjoina(dir, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service");
|
2014-03-05 22:26:10 +01:00
|
|
|
|
|
|
|
mkdir_parents(lnk, 0755);
|
2014-11-28 19:57:32 +01:00
|
|
|
if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0)
|
|
|
|
return log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
|
2014-03-05 22:26:10 +01:00
|
|
|
|
|
|
|
} else {
|
2015-05-06 07:09:53 +02:00
|
|
|
_cleanup_free_ char *_fsck = NULL;
|
|
|
|
const char *fsck;
|
|
|
|
|
|
|
|
if (in_initrd() && path_equal(where, "/sysroot")) {
|
|
|
|
r = write_fsck_sysroot_service(dir, what);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
fsck = "systemd-fsck-root.service";
|
|
|
|
} else {
|
|
|
|
r = unit_name_from_path_instance("systemd-fsck", what, ".service", &_fsck);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to create fsck service name: %m");
|
|
|
|
|
|
|
|
fsck = _fsck;
|
|
|
|
}
|
2014-03-05 22:26:10 +01:00
|
|
|
|
|
|
|
fprintf(f,
|
2015-11-12 19:21:47 +01:00
|
|
|
"Requires=%1$s\n"
|
2015-05-02 19:01:29 +02:00
|
|
|
"After=%1$s\n",
|
2014-03-05 22:26:10 +01:00
|
|
|
fsck);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-06-27 18:12:07 +02:00
|
|
|
|
2015-05-02 19:01:29 +02:00
|
|
|
int generator_write_timeouts(
|
|
|
|
const char *dir,
|
|
|
|
const char *what,
|
|
|
|
const char *where,
|
|
|
|
const char *opts,
|
|
|
|
char **filtered) {
|
2014-06-27 18:12:07 +02:00
|
|
|
|
|
|
|
/* Allow configuration how long we wait for a device that
|
|
|
|
* backs a mount point to show up. This is useful to support
|
|
|
|
* endless device timeouts for devices that show up only after
|
|
|
|
* user input, like crypto devices. */
|
|
|
|
|
2015-01-09 22:58:29 +01:00
|
|
|
_cleanup_free_ char *node = NULL, *unit = NULL, *timeout = NULL;
|
2014-06-27 18:12:07 +02:00
|
|
|
usec_t u;
|
|
|
|
int r;
|
|
|
|
|
2017-07-03 14:29:32 +02:00
|
|
|
r = fstab_filter_options(opts, "comment=systemd.device-timeout\0"
|
|
|
|
"x-systemd.device-timeout\0",
|
2015-01-09 22:58:29 +01:00
|
|
|
NULL, &timeout, filtered);
|
|
|
|
if (r <= 0)
|
|
|
|
return r;
|
2014-06-27 21:03:05 +02:00
|
|
|
|
2017-07-03 14:29:32 +02:00
|
|
|
r = parse_sec_fix_0(timeout, &u);
|
2014-06-27 18:12:07 +02:00
|
|
|
if (r < 0) {
|
2015-04-30 20:21:00 +02:00
|
|
|
log_warning("Failed to parse timeout for %s, ignoring: %s", where, timeout);
|
2014-06-27 18:12:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = fstab_node_to_udev_node(what);
|
|
|
|
if (!node)
|
|
|
|
return log_oom();
|
2017-07-17 10:03:34 +02:00
|
|
|
if (!is_device_path(node)) {
|
|
|
|
log_warning("x-systemd.device-timeout ignored for %s", what);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-06-27 18:12:07 +02:00
|
|
|
|
2015-04-30 20:21:00 +02:00
|
|
|
r = unit_name_from_path(node, ".device", &unit);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to make unit name from path: %m");
|
2014-06-27 18:12:07 +02:00
|
|
|
|
2014-07-01 00:41:17 +02:00
|
|
|
return write_drop_in_format(dir, unit, 50, "device-timeout",
|
|
|
|
"# Automatically generated by %s\n\n"
|
2017-09-27 17:33:09 +02:00
|
|
|
"[Unit]\n"
|
|
|
|
"JobRunningTimeoutSec=%s",
|
|
|
|
program_invocation_short_name,
|
|
|
|
timeout);
|
2014-06-27 18:12:07 +02:00
|
|
|
}
|
2016-05-12 18:42:39 +02:00
|
|
|
|
2017-01-24 17:04:32 +01:00
|
|
|
int generator_write_device_deps(
|
|
|
|
const char *dir,
|
|
|
|
const char *what,
|
|
|
|
const char *where,
|
|
|
|
const char *opts) {
|
|
|
|
|
|
|
|
/* fstab records that specify _netdev option should apply the network
|
|
|
|
* ordering on the actual device depending on network connection. If we
|
|
|
|
* are not mounting real device (NFS, CIFS), we rely on _netdev effect
|
|
|
|
* on the mount unit itself. */
|
|
|
|
|
|
|
|
_cleanup_free_ char *node = NULL, *unit = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (!fstab_test_option(opts, "_netdev\0"))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
node = fstab_node_to_udev_node(what);
|
|
|
|
if (!node)
|
|
|
|
return log_oom();
|
|
|
|
|
|
|
|
/* Nothing to apply dependencies to. */
|
|
|
|
if (!is_device_path(node))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
r = unit_name_from_path(node, ".device", &unit);
|
|
|
|
if (r < 0)
|
2017-11-21 23:18:05 +01:00
|
|
|
return log_error_errno(r, "Failed to make unit name from path \"%s\": %m",
|
|
|
|
node);
|
2017-01-24 17:04:32 +01:00
|
|
|
|
|
|
|
/* See mount_add_default_dependencies for explanation why we create such
|
|
|
|
* dependencies. */
|
|
|
|
return write_drop_in_format(dir, unit, 50, "netdev-dependencies",
|
|
|
|
"# Automatically generated by %s\n\n"
|
|
|
|
"[Unit]\n"
|
|
|
|
"After=" SPECIAL_NETWORK_ONLINE_TARGET " " SPECIAL_NETWORK_TARGET "\n"
|
|
|
|
"Wants=" SPECIAL_NETWORK_ONLINE_TARGET "\n",
|
|
|
|
program_invocation_short_name);
|
|
|
|
}
|
|
|
|
|
2016-05-12 18:42:39 +02:00
|
|
|
int generator_write_initrd_root_device_deps(const char *dir, const char *what) {
|
|
|
|
_cleanup_free_ char *unit = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = unit_name_from_path(what, ".device", &unit);
|
|
|
|
if (r < 0)
|
2017-11-21 23:18:05 +01:00
|
|
|
return log_error_errno(r, "Failed to make unit name from path \"%s\": %m",
|
|
|
|
what);
|
2016-05-12 18:42:39 +02:00
|
|
|
|
|
|
|
return write_drop_in_format(dir, SPECIAL_INITRD_ROOT_DEVICE_TARGET, 50, "root-device",
|
|
|
|
"# Automatically generated by %s\n\n"
|
2017-09-27 17:33:09 +02:00
|
|
|
"[Unit]\n"
|
|
|
|
"Requires=%s\n"
|
|
|
|
"After=%s",
|
|
|
|
program_invocation_short_name,
|
|
|
|
unit,
|
|
|
|
unit);
|
2016-05-12 18:42:39 +02:00
|
|
|
}
|
2017-11-21 23:18:05 +01:00
|
|
|
|
|
|
|
int generator_hook_up_mkswap(
|
|
|
|
const char *dir,
|
|
|
|
const char *what) {
|
|
|
|
|
|
|
|
_cleanup_free_ char *node = NULL, *unit = NULL, *escaped = NULL, *where_unit = NULL;
|
|
|
|
_cleanup_fclose_ FILE *f = NULL;
|
|
|
|
const char *unit_file;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
node = fstab_node_to_udev_node(what);
|
|
|
|
if (!node)
|
|
|
|
return log_oom();
|
|
|
|
|
|
|
|
/* Nothing to work on. */
|
|
|
|
if (!is_device_path(node)) {
|
|
|
|
log_error("Cannot format something that is not a device node: %s", node);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = unit_name_from_path_instance("systemd-mkswap", node, ".service", &unit);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to make unit instance name from path \"%s\": %m",
|
|
|
|
node);
|
|
|
|
|
|
|
|
unit_file = strjoina(dir, "/", unit);
|
|
|
|
log_debug("Creating %s", unit_file);
|
|
|
|
|
|
|
|
escaped = cescape(node);
|
|
|
|
if (!escaped)
|
|
|
|
return log_oom();
|
|
|
|
|
|
|
|
r = unit_name_from_path(what, ".swap", &where_unit);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to make unit name from path \"%s\": %m",
|
|
|
|
what);
|
|
|
|
|
|
|
|
f = fopen(unit_file, "wxe");
|
|
|
|
if (!f)
|
|
|
|
return log_error_errno(errno, "Failed to create unit file %s: %m",
|
|
|
|
unit_file);
|
|
|
|
|
|
|
|
fprintf(f,
|
|
|
|
"# Automatically generated by %s\n\n"
|
|
|
|
"[Unit]\n"
|
|
|
|
"Description=Make Swap on %%f\n"
|
|
|
|
"Documentation=man:systemd-mkswap@.service(8)\n"
|
|
|
|
"DefaultDependencies=no\n"
|
|
|
|
"BindsTo=%%i.device\n"
|
|
|
|
"After=%%i.device\n"
|
|
|
|
"Before=%s\n"
|
|
|
|
"Before=shutdown.target\n"
|
|
|
|
"\n"
|
|
|
|
"[Service]\n"
|
|
|
|
"Type=oneshot\n"
|
|
|
|
"RemainAfterExit=yes\n"
|
|
|
|
"ExecStart="SYSTEMD_MAKEFS_PATH " swap %s\n"
|
|
|
|
"TimeoutSec=0\n",
|
|
|
|
program_invocation_short_name,
|
|
|
|
where_unit,
|
|
|
|
escaped);
|
|
|
|
|
|
|
|
r = fflush_and_check(f);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to write unit file %s: %m", unit_file);
|
|
|
|
|
|
|
|
return generator_add_symlink(dir, where_unit, "requires", unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
int generator_hook_up_mkfs(
|
|
|
|
const char *dir,
|
|
|
|
const char *what,
|
|
|
|
const char *where,
|
|
|
|
const char *type) {
|
|
|
|
|
|
|
|
_cleanup_free_ char *node = NULL, *unit = NULL, *escaped = NULL, *where_unit = NULL;
|
|
|
|
_cleanup_fclose_ FILE *f = NULL;
|
|
|
|
const char *unit_file;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
node = fstab_node_to_udev_node(what);
|
|
|
|
if (!node)
|
|
|
|
return log_oom();
|
|
|
|
|
|
|
|
/* Nothing to work on. */
|
|
|
|
if (!is_device_path(node)) {
|
|
|
|
log_error("Cannot format something that is not a device node: %s", node);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!type || streq(type, "auto")) {
|
|
|
|
log_error("Cannot format partition %s, filesystem type is not specified", node);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = unit_name_from_path_instance("systemd-mkfs", node, ".service", &unit);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to make unit instance name from path \"%s\": %m",
|
|
|
|
node);
|
|
|
|
|
|
|
|
unit_file = strjoina(dir, "/", unit);
|
|
|
|
log_debug("Creating %s", unit_file);
|
|
|
|
|
|
|
|
escaped = cescape(node);
|
|
|
|
if (!escaped)
|
|
|
|
return log_oom();
|
|
|
|
|
|
|
|
r = unit_name_from_path(where, ".mount", &where_unit);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to make unit name from path \"%s\": %m",
|
|
|
|
where);
|
|
|
|
|
|
|
|
f = fopen(unit_file, "wxe");
|
|
|
|
if (!f)
|
|
|
|
return log_error_errno(errno, "Failed to create unit file %s: %m",
|
|
|
|
unit_file);
|
|
|
|
|
|
|
|
fprintf(f,
|
|
|
|
"# Automatically generated by %s\n\n"
|
|
|
|
"[Unit]\n"
|
|
|
|
"Description=Make File System on %%f\n"
|
|
|
|
"Documentation=man:systemd-mkfs@.service(8)\n"
|
|
|
|
"DefaultDependencies=no\n"
|
|
|
|
"BindsTo=%%i.device\n"
|
|
|
|
"After=%%i.device\n"
|
|
|
|
/* fsck might or might not be used, so let's be safe and order
|
|
|
|
* ourselves before both systemd-fsck@.service and the mount unit. */
|
|
|
|
"Before=systemd-fsck@%%i.service\n"
|
|
|
|
"Before=%s\n"
|
|
|
|
"Before=shutdown.target\n"
|
|
|
|
"\n"
|
|
|
|
"[Service]\n"
|
|
|
|
"Type=oneshot\n"
|
|
|
|
"RemainAfterExit=yes\n"
|
|
|
|
"ExecStart="SYSTEMD_MAKEFS_PATH " %s %s\n"
|
|
|
|
"TimeoutSec=0\n",
|
|
|
|
program_invocation_short_name,
|
|
|
|
where_unit,
|
|
|
|
type,
|
|
|
|
escaped);
|
|
|
|
// XXX: what about local-fs-pre.target?
|
|
|
|
|
|
|
|
r = fflush_and_check(f);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to write unit file %s: %m", unit_file);
|
|
|
|
|
|
|
|
return generator_add_symlink(dir, where_unit, "requires", unit);
|
|
|
|
}
|
2017-11-29 20:02:11 +01:00
|
|
|
|
|
|
|
int generator_hook_up_growfs(
|
|
|
|
const char *dir,
|
|
|
|
const char *where,
|
|
|
|
const char *target) {
|
|
|
|
|
|
|
|
_cleanup_free_ char *unit = NULL, *escaped = NULL, *where_unit = NULL;
|
|
|
|
_cleanup_fclose_ FILE *f = NULL;
|
|
|
|
const char *unit_file;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
escaped = cescape(where);
|
|
|
|
if (!escaped)
|
|
|
|
return log_oom();
|
|
|
|
|
|
|
|
r = unit_name_from_path_instance("systemd-growfs", where, ".service", &unit);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to make unit instance name from path \"%s\": %m",
|
|
|
|
where);
|
|
|
|
|
|
|
|
r = unit_name_from_path(where, ".mount", &where_unit);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to make unit name from path \"%s\": %m",
|
|
|
|
where);
|
|
|
|
|
|
|
|
unit_file = strjoina(dir, "/", unit);
|
|
|
|
log_debug("Creating %s", unit_file);
|
|
|
|
|
|
|
|
f = fopen(unit_file, "wxe");
|
|
|
|
if (!f)
|
|
|
|
return log_error_errno(errno, "Failed to create unit file %s: %m",
|
|
|
|
unit_file);
|
|
|
|
|
|
|
|
fprintf(f,
|
|
|
|
"# Automatically generated by %s\n\n"
|
|
|
|
"[Unit]\n"
|
|
|
|
"Description=Grow File System on %%f\n"
|
|
|
|
"Documentation=man:systemd-growfs@.service(8)\n"
|
|
|
|
"DefaultDependencies=no\n"
|
|
|
|
"BindsTo=%%i.mount\n"
|
|
|
|
"After=%%i.mount\n"
|
|
|
|
"Before=shutdown.target\n"
|
|
|
|
"Before=%s\n"
|
|
|
|
"\n"
|
|
|
|
"[Service]\n"
|
|
|
|
"Type=oneshot\n"
|
|
|
|
"RemainAfterExit=yes\n"
|
|
|
|
"ExecStart="SYSTEMD_GROWFS_PATH " %s\n"
|
|
|
|
"TimeoutSec=0\n",
|
|
|
|
program_invocation_short_name,
|
|
|
|
target,
|
|
|
|
escaped);
|
|
|
|
|
|
|
|
return generator_add_symlink(dir, where_unit, "wants", unit);
|
|
|
|
}
|