#include <stdio.h>
#include <unistd.h>
-#include "util.h"
+#include "alloc-util.h"
+#include "fd-util.h"
+#include "hashmap.h"
+#include "hexdecoct.h"
+#include "install.h"
+#include "log.h"
#include "mkdir.h"
-#include "strv.h"
-#include "path-util.h"
#include "path-lookup.h"
-#include "log.h"
-#include "unit.h"
-#include "unit-name.h"
+#include "path-util.h"
+#include "set.h"
#include "special.h"
-#include "hashmap.h"
+#include "stat-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "unit-name.h"
+#include "util.h"
typedef enum RunlevelType {
RUNLEVEL_UP,
STRV_FOREACH(p, s->wanted_by) {
r = add_symlink(s->name, *p);
if (r < 0)
- log_unit_error_errno(s->name, r, "Failed to create 'Wants' symlink to %s: %m", *p);
+ log_error_errno(r, "Failed to create 'Wants' symlink to %s: %m", *p);
}
return 0;
}
static char *sysv_translate_name(const char *name) {
- char *r;
+ _cleanup_free_ char *c = NULL;
+ char *res;
- r = new(char, strlen(name) + strlen(".service") + 1);
- if (!r)
+ c = strdup(name);
+ if (!c)
return NULL;
- if (endswith(name, ".sh"))
- /* Drop .sh suffix */
- strcpy(stpcpy(r, name) - 3, ".service");
- else
- /* Normal init script name */
- strcpy(stpcpy(r, name), ".service");
+ res = endswith(c, ".sh");
+ if (res)
+ *res = 0;
- return r;
+ if (unit_name_mangle(c, UNIT_NAME_NOGLOB, &res) < 0)
+ return NULL;
+
+ return res;
}
static int sysv_translate_facility(const char *name, const char *filename, char **_r) {
FOREACH_WORD_QUOTED(word, z, text, state_) {
_cleanup_free_ char *n = NULL, *m = NULL;
+ UnitType t;
n = strndup(word, z);
if (!n)
if (r == 0)
continue;
- if (unit_name_to_type(m) == UNIT_SERVICE) {
+ t = unit_name_to_type(m);
+ if (t == UNIT_SERVICE) {
log_debug("Adding Provides: alias '%s' for '%s'", m, s->name);
r = add_alias(s->name, m);
if (r < 0)
- log_unit_warning_errno(s->name, r,
- "[%s:%u] Failed to add LSB Provides name %s, ignoring: %m",
- s->path, line, m);
- } else {
+ log_warning_errno(r, "[%s:%u] Failed to add LSB Provides name %s, ignoring: %m", s->path, line, m);
+ } else if (t == UNIT_TARGET) {
/* NB: SysV targets which are provided by a
* service are pulled in by the services, as
* an indication that the generic service is
if (r < 0)
return log_oom();
}
- }
+ } else if (t == _UNIT_TYPE_INVALID)
+ log_warning("Unit name '%s' is invalid", m);
+ else
+ log_warning("Unknown unit type for unit '%s'", m);
}
if (!isempty(state_))
- log_unit_error(s->name,
- "[%s:%u] Trailing garbage in Provides, ignoring.",
- s->path, line);
+ log_error("[%s:%u] Trailing garbage in Provides, ignoring.", s->path, line);
return 0;
}
r = sysv_translate_facility(n, basename(s->path), &m);
if (r < 0) {
- log_unit_warning_errno(s->name, r,
- "[%s:%u] Failed to translate LSB dependency %s, ignoring: %m",
- s->path, line, n);
+ log_warning_errno(r, "[%s:%u] Failed to translate LSB dependency %s, ignoring: %m", s->path, line, n);
continue;
}
if (r == 0)
return log_oom();
}
if (!isempty(state_))
- log_unit_warning(s->name,
- "[%s:%u] Trailing garbage in %*s, ignoring.",
- s->path, line, (int)(strchr(full_text, ':') - full_text), full_text);
+ log_warning("[%s:%u] Trailing garbage in %*s, ignoring.", s->path, line, (int)(strchr(full_text, ':') - full_text), full_text);
return 0;
}
if (feof(f))
break;
- return log_unit_error_errno(s->name, errno,
- "Failed to read configuration file '%s': %m",
- s->path);
+ return log_error_errno(errno, "Failed to read configuration file '%s': %m", s->path);
}
line++;
fn = strstrip(t+8);
if (!path_is_absolute(fn)) {
- log_unit_error(s->name,
- "[%s:%u] PID file not absolute. Ignoring.",
- s->path, line);
+ log_error("[%s:%u] PID file not absolute. Ignoring.", s->path, line);
continue;
}
if (hidden_file(de->d_name))
continue;
- if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) {
+ if (fstatat(dirfd(d), de->d_name, &st, 0) < 0) {
log_warning_errno(errno, "stat() failed on %s/%s: %m", *path, de->d_name);
continue;
}
if (!path)
return -ENOMEM;
- if (d)
- closedir(d);
+ safe_closedir(d);
d = opendir(path);
if (!d) {
umask(0022);
- r = lookup_paths_init(&lp, SYSTEMD_SYSTEM, true, NULL, NULL, NULL, NULL);
+ r = lookup_paths_init(&lp, MANAGER_SYSTEM, true, NULL, NULL, NULL, NULL);
if (r < 0) {
log_error("Failed to find lookup paths.");
return EXIT_FAILURE;