2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2011-12-02 10:18:46 +01:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-11-19 21:32:11 +01:00
|
|
|
#include "generator.h"
|
2011-12-02 10:18:46 +01:00
|
|
|
#include "log.h"
|
2012-04-10 21:54:31 +02:00
|
|
|
#include "mkdir.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
|
|
|
#include "util.h"
|
2011-12-02 10:18:46 +01:00
|
|
|
|
2016-02-13 12:28:28 +01:00
|
|
|
static const char *arg_dest = "/tmp";
|
2011-12-02 10:18:46 +01:00
|
|
|
|
2018-11-16 22:00:35 +01:00
|
|
|
/* So you are reading this, and might wonder: why is this implemented as a generator rather than as a plain, statically
|
|
|
|
* enabled service that carries appropriate ConditionFileIsExecutable= lines? The answer is this: conditions bypass
|
|
|
|
* execution of a service's binary, but they have no influence on unit dependencies. Thus, a service that is
|
|
|
|
* conditioned out will still act as synchronization point in the dependency tree, and we'd rather not have that for
|
|
|
|
* these two legacy scripts. */
|
|
|
|
|
2012-05-03 15:55:38 +02:00
|
|
|
static int add_symlink(const char *service, const char *where) {
|
2017-12-24 16:51:28 +01:00
|
|
|
const char *from, *to;
|
2011-12-02 10:18:46 +01:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(service);
|
2013-10-29 19:34:11 +01:00
|
|
|
assert(where);
|
2011-12-02 10:18:46 +01:00
|
|
|
|
2017-12-24 16:51:28 +01:00
|
|
|
from = strjoina(SYSTEM_DATA_UNIT_PATH "/", service);
|
|
|
|
to = strjoina(arg_dest, "/", where, ".wants/", service);
|
2011-12-02 10:18:46 +01:00
|
|
|
|
2017-12-24 16:51:28 +01:00
|
|
|
(void) mkdir_parents_label(to, 0755);
|
2011-12-02 10:18:46 +01:00
|
|
|
|
|
|
|
r = symlink(from, to);
|
|
|
|
if (r < 0) {
|
|
|
|
if (errno == EEXIST)
|
2013-10-29 19:34:11 +01:00
|
|
|
return 0;
|
2011-12-02 10:18:46 +01:00
|
|
|
|
2015-11-05 13:44:20 +01:00
|
|
|
return log_error_errno(errno, "Failed to create symlink %s: %m", to);
|
2013-10-29 19:34:11 +01:00
|
|
|
}
|
2011-12-02 10:18:46 +01:00
|
|
|
|
2013-10-29 19:34:11 +01:00
|
|
|
return 1;
|
2011-12-02 10:18:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2017-12-24 16:51:28 +01:00
|
|
|
int ret = EXIT_SUCCESS;
|
2011-12-02 10:18:46 +01:00
|
|
|
|
2012-05-23 03:43:29 +02:00
|
|
|
if (argc > 1 && argc != 4) {
|
|
|
|
log_error("This program takes three or no arguments.");
|
2011-12-02 10:18:46 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-05-23 03:43:29 +02:00
|
|
|
if (argc > 1)
|
|
|
|
arg_dest = argv[1];
|
|
|
|
|
2018-11-19 21:32:11 +01:00
|
|
|
log_setup_generator();
|
2011-12-02 10:18:46 +01:00
|
|
|
|
2013-10-29 19:34:11 +01:00
|
|
|
if (access(RC_LOCAL_SCRIPT_PATH_START, X_OK) >= 0) {
|
2011-12-02 10:18:46 +01:00
|
|
|
log_debug("Automatically adding rc-local.service.");
|
|
|
|
|
2012-05-03 15:55:38 +02:00
|
|
|
if (add_symlink("rc-local.service", "multi-user.target") < 0)
|
2017-12-24 16:51:28 +01:00
|
|
|
ret = EXIT_FAILURE;
|
2012-05-03 15:55:38 +02:00
|
|
|
}
|
2011-12-02 10:18:46 +01:00
|
|
|
|
2013-10-29 19:34:11 +01:00
|
|
|
if (access(RC_LOCAL_SCRIPT_PATH_STOP, X_OK) >= 0) {
|
2012-05-03 15:55:38 +02:00
|
|
|
log_debug("Automatically adding halt-local.service.");
|
|
|
|
|
|
|
|
if (add_symlink("halt-local.service", "final.target") < 0)
|
2017-12-24 16:51:28 +01:00
|
|
|
ret = EXIT_FAILURE;
|
2011-12-02 10:18:46 +01:00
|
|
|
}
|
|
|
|
|
2017-12-24 16:51:28 +01:00
|
|
|
return ret;
|
2011-12-02 10:18:46 +01:00
|
|
|
}
|