rc-local-generator: minor modernizations

This commit is contained in:
Lennart Poettering 2017-12-24 16:51:28 +01:00
parent 245992a0c0
commit 449f4fc2c1

View file

@ -23,7 +23,6 @@
#include <stdio.h>
#include <unistd.h>
#include "alloc-util.h"
#include "log.h"
#include "mkdir.h"
#include "string-util.h"
@ -32,21 +31,16 @@
static const char *arg_dest = "/tmp";
static int add_symlink(const char *service, const char *where) {
_cleanup_free_ char *from = NULL, *to = NULL;
const char *from, *to;
int r;
assert(service);
assert(where);
from = strjoin(SYSTEM_DATA_UNIT_PATH, "/", service);
if (!from)
return log_oom();
from = strjoina(SYSTEM_DATA_UNIT_PATH "/", service);
to = strjoina(arg_dest, "/", where, ".wants/", service);
to = strjoin(arg_dest, "/", where, ".wants/", service);
if (!to)
return log_oom();
mkdir_parents_label(to, 0755);
(void) mkdir_parents_label(to, 0755);
r = symlink(from, to);
if (r < 0) {
@ -60,7 +54,7 @@ static int add_symlink(const char *service, const char *where) {
}
int main(int argc, char *argv[]) {
int r = EXIT_SUCCESS;
int ret = EXIT_SUCCESS;
if (argc > 1 && argc != 4) {
log_error("This program takes three or no arguments.");
@ -80,15 +74,15 @@ int main(int argc, char *argv[]) {
log_debug("Automatically adding rc-local.service.");
if (add_symlink("rc-local.service", "multi-user.target") < 0)
r = EXIT_FAILURE;
ret = EXIT_FAILURE;
}
if (access(RC_LOCAL_SCRIPT_PATH_STOP, X_OK) >= 0) {
log_debug("Automatically adding halt-local.service.");
if (add_symlink("halt-local.service", "final.target") < 0)
r = EXIT_FAILURE;
ret = EXIT_FAILURE;
}
return r;
return ret;
}