generator.c revision b5efdb8af40ea759a1ea584c1bc44ecc81dd00ce
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
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 "alloc-util.h"
#include "dropin.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
#include "fstab-util.h"
#include "generator.h"
#include "mkdir.h"
#include "mount-util.h"
#include "path-util.h"
#include "special.h"
#include "string-util.h"
#include "unit-name.h"
#include "util.h"
const char *unit;
int r;
if (!escaped)
return log_oom();
if (r < 0)
if (!f)
fprintf(f,
"# Automatically generated by %1$s\n\n"
"[Unit]\n"
"Documentation=man:systemd-fsck-root.service(8)\n"
"Description=File System Check on %2$s\n"
"DefaultDependencies=no\n"
"BindsTo=%3$s\n"
"After=%3$s\n"
"Before=shutdown.target\n"
"\n"
"[Service]\n"
"Type=oneshot\n"
"RemainAfterExit=yes\n"
"TimeoutSec=0\n",
what,
escaped);
r = fflush_and_check(f);
if (r < 0)
return 0;
}
FILE *f,
const char *dir,
const char *what,
const char *where,
const char *fstype) {
int r;
assert(f);
if (!is_device_path(what)) {
return 0;
}
r = fsck_exists(fstype);
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) {
/* treat missing check as essentially OK */
return 0;
}
}
const char *lnk;
} else {
const char *fsck;
if (r < 0)
return r;
fsck = "systemd-fsck-root.service";
} else {
if (r < 0)
return log_error_errno(r, "Failed to create fsck service name: %m");
}
fprintf(f,
"RequiresOverridable=%1$s\n"
"After=%1$s\n",
fsck);
}
return 0;
}
const char *dir,
const char *what,
const char *where,
const char *opts,
char **filtered) {
/* 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. */
usec_t u;
int r;
if (r <= 0)
return r;
if (r < 0) {
return 0;
}
if (!node)
return log_oom();
if (r < 0)
return log_error_errno(r, "Failed to make unit name from path: %m");
"# Automatically generated by %s\n\n"
"[Unit]\nJobTimeoutSec=" USEC_FMT,
u / USEC_PER_SEC);
}