* means they are shut down anyway at system power off if running. */
};
-static const char *arg_dest = "/tmp";
+static const char *arg_dest = NULL;
typedef struct SysvStub {
char *name;
assert(service);
assert(alias);
- link = strjoina(arg_dest, "/", alias);
+ link = prefix_roota(arg_dest, alias);
r = symlink(service, link);
if (r < 0) {
if (!path_escaped)
return log_oom();
- unit = strjoina(arg_dest, "/", s->name);
+ unit = prefix_roota(arg_dest, s->name);
/* We might already have a symlink with the same name from a Provides:,
* or from backup files like /etc/init.d/foo.bak. Real scripts always win,
for (;;) {
_cleanup_free_ char *word = NULL, *m = NULL;
- r = extract_first_word(&text, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);
+ r = extract_first_word(&text, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RELAX);
if (r < 0)
return log_error_errno(r, "[%s:%u] Failed to parse word from provides string: %m", s->path, line);
if (r == 0)
_cleanup_free_ char *word = NULL, *m = NULL;
bool is_before;
- r = extract_first_word(&text, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);
+ r = extract_first_word(&text, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RELAX);
if (r < 0)
return log_error_errno(r, "[%s:%u] Failed to parse word from provides string: %m", s->path, line);
if (r == 0)
if (description) {
char *d;
- d = strappend(s->has_lsb ? "LSB: " : "SYSV: ", description);
+ d = strjoin(s->has_lsb ? "LSB: " : "SYSV: ", description);
if (!d)
return log_oom();
continue;
}
- fpath = strjoin(*path, "/", de->d_name);
+ fpath = path_join(*path, de->d_name);
if (!fpath)
return log_oom();
- service = new0(SysvStub, 1);
+ log_warning("SysV service '%s' lacks a native systemd unit file. "
+ "Automatically generating a unit file for compatibility. "
+ "Please update package to include a native systemd unit file, in order to make it more safe and robust.", fpath);
+
+ service = new(SysvStub, 1);
if (!service)
return log_oom();
- service->sysv_start_priority = -1;
- service->name = TAKE_PTR(name);
- service->path = TAKE_PTR(fpath);
+ *service = (SysvStub) {
+ .sysv_start_priority = -1,
+ .name = TAKE_PTR(name),
+ .path = TAKE_PTR(fpath),
+ };
r = hashmap_put(all_services, service->name, service);
if (r < 0)
return log_oom();
- service = NULL;
+ TAKE_PTR(service);
}
}
_cleanup_free_ char *path = NULL;
struct dirent *de;
- path = strjoin(*p, "/", rcnd_table[i].path);
+ path = path_join(*p, rcnd_table[i].path);
if (!path) {
r = log_oom();
goto finish;
continue;
}
- FOREACH_DIRENT(de, d, log_error_errno(errno, "Failed to enumerate directory %s, ignoring: %m", path)) {
+ FOREACH_DIRENT(de, d, log_warning_errno(errno, "Failed to enumerate directory %s, ignoring: %m", path)) {
_cleanup_free_ char *name = NULL, *fpath = NULL;
int a, b;
if (a < 0 || b < 0)
continue;
- fpath = strjoin(*p, "/", de->d_name);
+ fpath = path_join(*p, de->d_name);
if (!fpath) {
r = log_oom();
goto finish;
service->sysv_start_priority = MAX(a*10 + b, service->sysv_start_priority);
- r = set_ensure_allocated(&runlevel_services[i], NULL);
- if (r < 0) {
- log_oom();
- goto finish;
- }
-
- r = set_put(runlevel_services[i], service);
+ r = set_ensure_put(&runlevel_services[i], NULL, service);
if (r < 0) {
log_oom();
goto finish;
return r;
}
-static int run(int argc, char *argv[]) {
+static int run(const char *dest, const char *dest_early, const char *dest_late) {
_cleanup_(free_sysvstub_hashmapp) Hashmap *all_services = NULL;
_cleanup_(lookup_paths_free) LookupPaths lp = {};
SysvStub *service;
Iterator j;
int r;
- log_set_prohibit_ipc(true);
- log_set_target(LOG_TARGET_AUTO);
- log_parse_environment();
- log_open();
-
- if (argc > 1 && argc != 4) {
- log_error("This program takes three or no arguments.");
- return -EINVAL;
- }
-
- if (argc > 1)
- arg_dest = argv[3];
-
- umask(0022);
+ assert_se(arg_dest = dest_late);
r = lookup_paths_init(&lp, UNIT_FILE_SYSTEM, LOOKUP_PATHS_EXCLUDE_GENERATED, NULL);
if (r < 0)
return 0;
}
-DEFINE_MAIN_FUNCTION(run);
+DEFINE_MAIN_GENERATOR_FUNCTION(run);