exec_context_init(&a->exec_context);
/* Load a .automount file */
- if ((r = unit_load_fragment(u)) < 0 && errno != -ENOENT)
+ if ((r = unit_load_fragment(u)) < 0)
return r;
/* Load entry from /etc/fstab */
}
int unit_load_fragment(Unit *u) {
- int r = -ENOENT;
+ int r = 0;
ExecContext *c;
assert(u);
if (r >= 0 && c &&
(c->output == EXEC_KERNEL || c->output == EXEC_SYSLOG)) {
+ int k;
+
/* If syslog or kernel logging is requested, make sure
* our own logging daemon is run first. */
- if ((r = unit_add_dependency(u, UNIT_AFTER, u->meta.manager->special_units[SPECIAL_LOGGER_SOCKET])) < 0)
- return r;
+ if ((k = unit_add_dependency(u, UNIT_AFTER, u->meta.manager->special_units[SPECIAL_LOGGER_SOCKET])) < 0)
+ return k;
- if ((r = unit_add_dependency(u, UNIT_REQUIRES, u->meta.manager->special_units[SPECIAL_LOGGER_SOCKET])) < 0)
- return r;
+ if ((k = unit_add_dependency(u, UNIT_REQUIRES, u->meta.manager->special_units[SPECIAL_LOGGER_SOCKET])) < 0)
+ return k;
}
return r;
goto finish;
}
+ printf("→ By units:\n");
+ manager_dump_units(m, stdout, "\t");
+
if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &job)) < 0) {
log_error("Failed to start default target: %s", strerror(-r));
goto finish;
}
- printf("→ By units:\n");
- manager_dump_units(m, stdout, "\t");
-
printf("→ By jobs:\n");
manager_dump_jobs(m, stdout, "\t");
assert(m);
/* Load a .mount file */
- if ((r = unit_load_fragment(u)) < 0 && errno != -ENOENT)
+ if ((r = unit_load_fragment(u)) < 0)
return r;
/* Load entry from /etc/fstab */
s->state = SERVICE_DEAD;
/* Load a .service file */
- r = unit_load_fragment(u);
-
- /* Load a classic init script as a fallback */
- if (r == -ENOENT)
- r = service_load_sysv(s);
-
- if (r < 0) {
+ if ((r = unit_load_fragment(u)) < 0) {
service_done(u);
return r;
}
+ /* Load a classic init script as a fallback, if we couldn*t find anything */
+ if (r == 0)
+ if ((r = service_load_sysv(s)) <= 0) {
+ service_done(u);
+ return r < 0 ? r : -ENOENT;
+ }
+
/* Load dropin directory data */
if ((r = unit_load_dropin(u)) < 0) {
service_done(u);
s->timeout_usec = DEFAULT_TIMEOUT_USEC;
exec_context_init(&s->exec_context);
- if ((r = unit_load_fragment_and_dropin(u)) < 0)
+ if ((r = unit_load_fragment_and_dropin(u)) <= 0) {
+ if (r == 0)
+ r = -ENOENT;
goto fail;
+ }
if (!(t = unit_name_change_suffix(unit_id(u), ".service"))) {
r = -ENOMEM;
/*-*- Mode: C; c-basic-offset: 8 -*-*/
+#include <errno.h>
+
#include "unit.h"
#include "target.h"
#include "load-fragment.h"
[TARGET_ACTIVE] = "active"
};
+static int target_init(Unit *u) {
+ int r;
+ assert(u);
+
+ /* Make sure this config file actually exists */
+
+ if ((r = unit_load_fragment_and_dropin(u)) <= 0)
+ return r < 0 ? r : -ENOENT;
+
+ return 0;
+}
+
static void target_dump(Unit *u, FILE *f, const char *prefix) {
Target *t = TARGET(u);
const UnitVTable target_vtable = {
.suffix = ".target",
- .init = unit_load_fragment_and_dropin,
+ .init = target_init,
.dump = target_dump,
/*-*- Mode: C; c-basic-offset: 8 -*-*/
+#include <errno.h>
+
#include "unit.h"
#include "timer.h"
assert(t);
}
+static int timer_init(Unit *u) {
+ int r;
+
+ assert(u);
+
+ /* Make sure this config file actually exists */
+
+ if ((r = unit_load_fragment_and_dropin(u)) <= 0)
+ return r < 0 ? r : -ENOENT;
+
+ return 0;
+}
+
static UnitActiveState timer_active_state(Unit *u) {
static const UnitActiveState table[_TIMER_STATE_MAX] = {
const UnitVTable timer_vtable = {
.suffix = ".timer",
- .init = unit_load_fragment_and_dropin,
+ .init = timer_init,
.done = timer_done,
.active_state = timer_active_state
/* Common implementation for multiple backends */
int unit_load_fragment_and_dropin(Unit *u) {
- int r;
+ int r, ret;
assert(u);
if ((r = unit_load_fragment(u)) < 0)
return r;
+ ret = r > 0;
+
/* Load drop-in directory data */
if ((r = unit_load_dropin(u)) < 0)
return r;
- return 0;
+ return ret;
}
int unit_load(Unit *u) {