[systemd-commits] 6 commits - Makefile.am man/systemd.service.xml src/automount.c src/dbus.c src/dbus-manager.c src/dbus-unit.c src/execute.c src/execute.h src/kmod-setup.c src/load-fragment.c src/main.c src/manager.c src/manager.h src/mount.c src/path.c src/service.c src/snapshot.c src/snapshot.h src/socket.c src/strv.c src/strv.h src/swap.c src/test-engine.c src/test-loopback.c src/timer.c src/unit.c src/util.c src/util.h units/emergency.service
Lennart Poettering
lennart at kemper.freedesktop.org
Wed Jul 7 19:22:05 PDT 2010
Makefile.am | 3 -
man/systemd.service.xml | 44 +++++++++++++++---
src/automount.c | 9 +++
src/dbus-manager.c | 53 ++++++++++++++--------
src/dbus-unit.c | 17 ++++---
src/dbus.c | 25 +++++-----
src/execute.c | 38 ++++++++++------
src/execute.h | 1
src/kmod-setup.c | 2
src/load-fragment.c | 27 +++++++++--
src/main.c | 20 ++++++--
src/manager.c | 101 ++++++++++++++++++++++++++-----------------
src/manager.h | 8 +--
src/mount.c | 3 -
src/path.c | 10 +++-
src/service.c | 75 +++++++++++++++++++-------------
src/snapshot.c | 17 +++++--
src/snapshot.h | 2
src/socket.c | 14 ++++--
src/strv.c | 17 +++++++
src/strv.h | 3 +
src/swap.c | 2
src/test-engine.c | 34 +++++++-------
src/test-loopback.c | 1
src/timer.c | 10 +++-
src/unit.c | 28 ++++++------
src/util.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++--
src/util.h | 4 +
units/emergency.service | 4 +
29 files changed, 487 insertions(+), 197 deletions(-)
New commits:
commit 319346674c5665af895e854e1754eed4b5e36f42
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 8 04:21:53 2010 +0200
units: kill the emergency shell with SIGHUP
diff --git a/units/emergency.service b/units/emergency.service
index 83b7d72..8745d10 100644
--- a/units/emergency.service
+++ b/units/emergency.service
@@ -17,3 +17,7 @@ StandardInput=tty
Restart=restart-always
RestartSec=0
KillMode=process-group
+
+# Bash ignores SIGTERM, so we send SIGHUP first, to ensure that bash
+# terminates cleanly.
+ExecStop=/bin/kill -HUP $(MAINPID)
commit 420a0166a2f02939de22569b37168395772a5be9
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 8 04:19:54 2010 +0200
man: document variable substitution
diff --git a/man/systemd.service.xml b/man/systemd.service.xml
index 7eaf9cb..709a448 100644
--- a/man/systemd.service.xml
+++ b/man/systemd.service.xml
@@ -257,11 +257,19 @@
<literal>argv[0]</literal> to the
executed process, followed by the
further arguments specified. Unless
- <varname>Type=forking</varname> is set,
- the process started via this command
- line will be considered the main
- process of the
- daemon.</para></listitem>
+ <varname>Type=forking</varname> is
+ set, the process started via this
+ command line will be considered the
+ main process of the daemon. The
+ command line accepts % specifiers as
+ described in
+ <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. On
+ top of that basic environment variable
+ substitution is supported, where
+ <literal>$(FOO)</literal> is replaced
+ by the value of the environment
+ variable of the same
+ name.</para></listitem>
</varlistentry>
<varlistentry>
@@ -285,7 +293,9 @@
suitable for XDG
<filename>.desktop</filename> files.
Use of these settings is
- optional.</para></listitem>
+ optional. Specifier and environment
+ variable substitution is
+ supported.</para></listitem>
</varlistentry>
<varlistentry>
@@ -297,7 +307,17 @@
scheme as pointed out for
<varname>ExecStartPre=</varname>
above. Use of this setting is
- optional. </para></listitem>
+ optional. Specifier and environment
+ variable substitution is supported
+ here following the same scheme as for
+ <varname>ExecStart=</varname>. One
+ special environment variable is set:
+ if known <literal>$MAINPID</literal> is
+ set to the main process of the
+ daemon, and may be used for command
+ lines like the following:
+ <command>/bin/kill -HUP
+ $(MAINPID)</command>.</para></listitem>
</varlistentry>
<varlistentry>
@@ -318,7 +338,11 @@
(see below). If this option is not
specified the process is terminated
right-away when service stop is
- requested.</para></listitem>
+ requested. Specifier and environment
+ variable substitution is supported
+ (including
+ <literal>$(MAINPID)</literal>, see
+ above).</para></listitem>
</varlistentry>
<varlistentry>
@@ -333,7 +357,9 @@
out for
<varname>ExecStartPre</varname>. Use
of these settings is
- optional.</para></listitem>
+ optional. Specifier and environment
+ variable substitution is
+ supported.</para></listitem>
</varlistentry>
<varlistentry>
diff --git a/src/test-loopback.c b/src/test-loopback.c
index 5cd7b41..478f2f6 100644
--- a/src/test-loopback.c
+++ b/src/test-loopback.c
@@ -24,6 +24,7 @@
#include <stdio.h>
#include "loopback-setup.h"
+#include "util.h"
int main(int argc, char* argv[]) {
int r;
commit fab56fc541cebdbbc4cc273c3f0807eb7807b9fd
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 8 04:09:59 2010 +0200
execute: support minimal environment variable replacement when executing processes
diff --git a/src/execute.c b/src/execute.c
index 138d388..955a3e2 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -943,7 +943,7 @@ int exec_spawn(ExecCommand *command,
const char *username = NULL, *home = NULL;
uid_t uid = (uid_t) -1;
gid_t gid = (gid_t) -1;
- char **our_env = NULL, **pam_env = NULL, **final_env = NULL;
+ char **our_env = NULL, **pam_env = NULL, **final_env = NULL, **final_argv = NULL;
unsigned n_env = 0;
int saved_stdout = -1, saved_stdin = -1;
bool keep_stdout = false, keep_stdin = false;
@@ -1260,13 +1260,19 @@ int exec_spawn(ExecCommand *command,
goto fail;
}
- execve(command->path, argv, final_env);
+ if (!(final_argv = replace_env_argv(argv, final_env))) {
+ r = EXIT_MEMORY;
+ goto fail;
+ }
+
+ execve(command->path, final_argv, final_env);
r = EXIT_EXEC;
fail:
strv_free(our_env);
strv_free(final_env);
strv_free(pam_env);
+ strv_free(final_argv);
if (saved_stdin >= 0)
close_nointr_nofail(saved_stdin);
diff --git a/src/strv.c b/src/strv.c
index a663696..9dbab29 100644
--- a/src/strv.c
+++ b/src/strv.c
@@ -539,3 +539,20 @@ fail:
return NULL;
}
+
+char *strv_env_get_with_length(char **l, const char *name, size_t k) {
+ char **i;
+
+ assert(name);
+
+ STRV_FOREACH(i, l)
+ if (strncmp(*i, name, k) == 0 &&
+ (*i)[k] == '=')
+ return *i + k + 1;
+
+ return NULL;
+}
+
+char *strv_env_get(char **l, const char *name) {
+ return strv_env_get_with_length(l, name, strlen(name));
+}
diff --git a/src/strv.h b/src/strv.h
index 0d50b02..8cb35ef 100644
--- a/src/strv.h
+++ b/src/strv.h
@@ -60,6 +60,9 @@ char **strv_env_delete(char **x, unsigned n_lists, ...);
char **strv_env_set(char **x, const char *p);
+char *strv_env_get_with_length(char **l, const char *name, size_t k);
+char *strv_env_get(char **x, const char *n);
+
#define STRV_FOREACH(s, l) \
for ((s) = (l); (s) && *(s); (s)++)
diff --git a/src/util.c b/src/util.c
index a01229e..cdfc9e0 100644
--- a/src/util.c
+++ b/src/util.c
@@ -613,15 +613,23 @@ int get_process_cmdline(pid_t pid, size_t max_length, char **line) {
return 0;
}
-char *strappend(const char *s, const char *suffix) {
- size_t a, b;
+char *strnappend(const char *s, const char *suffix, size_t b) {
+ size_t a;
char *r;
+ if (!s && !suffix)
+ return strdup("");
+
+ if (!s)
+ return strndup(suffix, b);
+
+ if (!suffix)
+ return strdup(s);
+
assert(s);
assert(suffix);
a = strlen(s);
- b = strlen(suffix);
if (!(r = new(char, a+b+1)))
return NULL;
@@ -633,6 +641,10 @@ char *strappend(const char *s, const char *suffix) {
return r;
}
+char *strappend(const char *s, const char *suffix) {
+ return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
+}
+
int readlink_malloc(const char *p, char **r) {
size_t l = 100;
@@ -2692,6 +2704,100 @@ void status_welcome(void) {
#endif
}
+char *replace_env(const char *format, char **env) {
+ enum {
+ WORD,
+ DOLLAR,
+ VARIABLE
+ } state = WORD;
+
+ const char *e, *word = format;
+ char *r = NULL, *k;
+
+ assert(format);
+
+ for (e = format; *e; e ++) {
+
+ switch (state) {
+
+ case WORD:
+ if (*e == '$')
+ state = DOLLAR;
+ break;
+
+ case DOLLAR:
+ if (*e == '(') {
+ if (!(k = strnappend(r, word, e-word-1)))
+ goto fail;
+
+ free(r);
+ r = k;
+
+ word = e-1;
+ state = VARIABLE;
+
+ } else if (*e == '$') {
+ if (!(k = strnappend(r, word, e-word)))
+ goto fail;
+
+ free(r);
+ r = k;
+
+ word = e+1;
+ state = WORD;
+ } else
+ state = WORD;
+ break;
+
+ case VARIABLE:
+ if (*e == ')') {
+ char *t;
+
+ if ((t = strv_env_get_with_length(env, word+2, e-word-2))) {
+ if (!(k = strappend(r, t)))
+ goto fail;
+
+ free(r);
+ r = k;
+
+ word = e+1;
+ }
+
+ state = WORD;
+ }
+ break;
+ }
+ }
+
+ if (!(k = strnappend(r, word, e-word)))
+ goto fail;
+
+ free(r);
+ return k;
+
+fail:
+ free(r);
+ return NULL;
+}
+
+char **replace_env_argv(char **argv, char **env) {
+ char **r, **i;
+ unsigned k;
+
+ if (!(r = new(char*, strv_length(argv)+1)))
+ return NULL;
+
+ STRV_FOREACH(i, argv) {
+ if (!(r[k++] = replace_env(*i, env))) {
+ strv_free(r);
+ return NULL;
+ }
+ }
+
+ r[k] = NULL;
+ return r;
+}
+
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",
diff --git a/src/util.h b/src/util.h
index ff79583..b29f890 100644
--- a/src/util.h
+++ b/src/util.h
@@ -183,6 +183,10 @@ int write_one_line_file(const char *fn, const char *line);
int read_one_line_file(const char *fn, char **line);
char *strappend(const char *s, const char *suffix);
+char *strnappend(const char *s, const char *suffix, size_t length);
+
+char *replace_env(const char *format, char **env);
+char **replace_env_argv(char **argv, char **env);
int readlink_malloc(const char *p, char **r);
int readlink_and_make_absolute(const char *p, char **r);
commit 1e3ad081efda42dd1cc737ce7e98be8889c78340
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 8 04:09:17 2010 +0200
execute: if the main process of a service already owns the TTY, don't wait for acquiring it again in the reload/stop step
diff --git a/src/execute.c b/src/execute.c
index d7239d5..138d388 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -232,7 +232,10 @@ static bool is_terminal_input(ExecInput i) {
i == EXEC_INPUT_TTY_FAIL;
}
-static int fixup_input(ExecInput std_input, int socket_fd) {
+static int fixup_input(ExecInput std_input, int socket_fd, bool apply_tty_stdin) {
+
+ if (is_terminal_input(std_input) && !apply_tty_stdin)
+ return EXEC_INPUT_NULL;
if (std_input == EXEC_INPUT_SOCKET && socket_fd < 0)
return EXEC_INPUT_NULL;
@@ -248,12 +251,12 @@ static int fixup_output(ExecOutput std_output, int socket_fd) {
return std_output;
}
-static int setup_input(const ExecContext *context, int socket_fd) {
+static int setup_input(const ExecContext *context, int socket_fd, bool apply_tty_stdin) {
ExecInput i;
assert(context);
- i = fixup_input(context->std_input, socket_fd);
+ i = fixup_input(context->std_input, socket_fd, apply_tty_stdin);
switch (i) {
@@ -289,14 +292,14 @@ static int setup_input(const ExecContext *context, int socket_fd) {
}
}
-static int setup_output(const ExecContext *context, int socket_fd, const char *ident) {
+static int setup_output(const ExecContext *context, int socket_fd, const char *ident, bool apply_tty_stdin) {
ExecOutput o;
ExecInput i;
assert(context);
assert(ident);
- i = fixup_input(context->std_input, socket_fd);
+ i = fixup_input(context->std_input, socket_fd, apply_tty_stdin);
o = fixup_output(context->std_output, socket_fd);
/* This expects the input is already set up */
@@ -339,14 +342,14 @@ static int setup_output(const ExecContext *context, int socket_fd, const char *i
}
}
-static int setup_error(const ExecContext *context, int socket_fd, const char *ident) {
+static int setup_error(const ExecContext *context, int socket_fd, const char *ident, bool apply_tty_stdin) {
ExecOutput o, e;
ExecInput i;
assert(context);
assert(ident);
- i = fixup_input(context->std_input, socket_fd);
+ i = fixup_input(context->std_input, socket_fd, apply_tty_stdin);
o = fixup_output(context->std_output, socket_fd);
e = fixup_output(context->std_error, socket_fd);
@@ -889,6 +892,7 @@ int exec_spawn(ExecCommand *command,
char **environment,
bool apply_permissions,
bool apply_chroot,
+ bool apply_tty_stdin,
bool confirm_spawn,
CGroupBonding *cgroup_bondings,
pid_t *ret) {
@@ -985,7 +989,9 @@ int exec_spawn(ExecCommand *command,
}
}
- if (confirm_spawn) {
+ /* We skip the confirmation step if we shall not apply the TTY */
+ if (confirm_spawn &&
+ (!is_terminal_input(context->std_input) || apply_tty_stdin)) {
char response;
/* Set up terminal for the question */
@@ -1018,18 +1024,18 @@ int exec_spawn(ExecCommand *command,
}
if (!keep_stdin)
- if (setup_input(context, socket_fd) < 0) {
+ if (setup_input(context, socket_fd, apply_tty_stdin) < 0) {
r = EXIT_STDIN;
goto fail;
}
if (!keep_stdout)
- if (setup_output(context, socket_fd, file_name_from_path(command->path)) < 0) {
+ if (setup_output(context, socket_fd, file_name_from_path(command->path), apply_tty_stdin) < 0) {
r = EXIT_STDOUT;
goto fail;
}
- if (setup_error(context, socket_fd, file_name_from_path(command->path)) < 0) {
+ if (setup_error(context, socket_fd, file_name_from_path(command->path), apply_tty_stdin) < 0) {
r = EXIT_STDERR;
goto fail;
}
diff --git a/src/execute.h b/src/execute.h
index 2e0e6cc..a9075fe 100644
--- a/src/execute.h
+++ b/src/execute.h
@@ -196,6 +196,7 @@ int exec_spawn(ExecCommand *command,
char **environment,
bool apply_permissions,
bool apply_chroot,
+ bool apply_tty_stdin,
bool confirm_spawn,
struct CGroupBonding *cgroup_bondings,
pid_t *ret);
diff --git a/src/kmod-setup.c b/src/kmod-setup.c
index e3925c5..3ce6fcc 100644
--- a/src/kmod-setup.c
+++ b/src/kmod-setup.c
@@ -70,7 +70,7 @@ int kmod_setup(void) {
command.argv = (char**) cmdline;
exec_context_init(&context);
- r = exec_spawn(&command, NULL, &context, NULL, 0, NULL, false, false, false, NULL, &pid);
+ r = exec_spawn(&command, NULL, &context, NULL, 0, NULL, false, false, false, false, NULL, &pid);
exec_context_done(&context);
if (r < 0)
diff --git a/src/manager.c b/src/manager.c
index 9cbf9c8..adff546 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -1273,7 +1273,7 @@ static int transaction_add_job_and_dependencies(
assert(unit);
if (unit->meta.load_state != UNIT_LOADED) {
- dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s failed to load.", unit->meta.id);
+ dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s failed to load. See logs for details.", unit->meta.id);
return -EINVAL;
}
diff --git a/src/mount.c b/src/mount.c
index 50fe85c..e7fdcc8 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -535,6 +535,7 @@ static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) {
true,
true,
m->meta.manager->confirm_spawn,
+ true,
m->meta.cgroup_bondings,
&pid)) < 0)
goto fail;
diff --git a/src/service.c b/src/service.c
index 75439be..2ca0c17 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1323,6 +1323,7 @@ static int service_spawn(
bool pass_fds,
bool apply_permissions,
bool apply_chroot,
+ bool apply_tty_stdin,
bool set_notify_socket,
pid_t *_pid) {
@@ -1395,6 +1396,7 @@ static int service_spawn(
final_env,
apply_permissions,
apply_chroot,
+ apply_tty_stdin,
s->meta.manager->confirm_spawn,
s->meta.cgroup_bondings,
&pid);
@@ -1505,6 +1507,7 @@ static void service_enter_stop_post(Service *s, bool success) {
false,
!s->permissions_start_only,
!s->root_directory_start_only,
+ true,
false,
&s->control_pid)) < 0)
goto fail;
@@ -1605,6 +1608,7 @@ static void service_enter_stop(Service *s, bool success) {
!s->permissions_start_only,
!s->root_directory_start_only,
false,
+ false,
&s->control_pid)) < 0)
goto fail;
@@ -1653,6 +1657,7 @@ static void service_enter_start_post(Service *s) {
!s->permissions_start_only,
!s->root_directory_start_only,
false,
+ false,
&s->control_pid)) < 0)
goto fail;
@@ -1687,6 +1692,7 @@ static void service_enter_start(Service *s) {
true,
true,
true,
+ true,
s->notify_access != NOTIFY_NONE,
&pid)) < 0)
goto fail;
@@ -1747,6 +1753,7 @@ static void service_enter_start_pre(Service *s) {
false,
!s->permissions_start_only,
!s->root_directory_start_only,
+ true,
false,
&s->control_pid)) < 0)
goto fail;
@@ -1800,6 +1807,7 @@ static void service_enter_reload(Service *s) {
!s->permissions_start_only,
!s->root_directory_start_only,
false,
+ false,
&s->control_pid)) < 0)
goto fail;
@@ -1835,6 +1843,7 @@ static void service_run_next(Service *s, bool success) {
!s->permissions_start_only,
!s->root_directory_start_only,
false,
+ false,
&s->control_pid)) < 0)
goto fail;
diff --git a/src/socket.c b/src/socket.c
index b8643d9..ee75de0 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -822,6 +822,7 @@ static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) {
s->meta.manager->environment,
true,
true,
+ true,
s->meta.manager->confirm_spawn,
s->meta.cgroup_bondings,
&pid);
commit 398ef8ba0266cca453d90a90b3a2aa1caa44189f
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 8 02:43:18 2010 +0200
dbus: make errors reported via D-Bus more useful
diff --git a/Makefile.am b/Makefile.am
index b444c02..dfea23d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -311,7 +311,8 @@ EXTRA_DIST += \
src/initreq.h \
src/sd-daemon.h \
src/special.h \
- src/dbus-common.h
+ src/dbus-common.h \
+ src/bus-errors.h
MANPAGES = \
man/systemd.1 \
diff --git a/src/automount.c b/src/automount.c
index 0689ec7..39eb3dd 100644
--- a/src/automount.c
+++ b/src/automount.c
@@ -35,6 +35,7 @@
#include "load-dropin.h"
#include "unit-name.h"
#include "dbus-automount.h"
+#include "bus-errors.h"
static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
[AUTOMOUNT_DEAD] = UNIT_INACTIVE,
@@ -533,10 +534,13 @@ fail:
static void automount_enter_runnning(Automount *a) {
int r;
struct stat st;
+ DBusError error;
assert(a);
assert(a->mount);
+ dbus_error_init(&error);
+
mkdir_p(a->where, a->directory_mode);
/* Before we do anything, let's see if somebody is playing games with us? */
@@ -547,8 +551,8 @@ static void automount_enter_runnning(Automount *a) {
if (!S_ISDIR(st.st_mode) || st.st_dev != a->dev_id)
log_info("%s's automount point already active?", a->meta.id);
- else if ((r = manager_add_job(a->meta.manager, JOB_START, UNIT(a->mount), JOB_REPLACE, true, NULL)) < 0) {
- log_warning("%s failed to queue mount startup job: %s", a->meta.id, strerror(-r));
+ else if ((r = manager_add_job(a->meta.manager, JOB_START, UNIT(a->mount), JOB_REPLACE, true, &error, NULL)) < 0) {
+ log_warning("%s failed to queue mount startup job: %s", a->meta.id, bus_error(&error, r));
goto fail;
}
@@ -557,6 +561,7 @@ static void automount_enter_runnning(Automount *a) {
fail:
automount_enter_dead(a, false);
+ dbus_error_free(&error);
}
static int automount_start(Unit *u) {
diff --git a/src/dbus-manager.c b/src/dbus-manager.c
index dda7c77..5daccb1 100644
--- a/src/dbus-manager.c
+++ b/src/dbus-manager.c
@@ -25,6 +25,7 @@
#include "log.h"
#include "dbus-manager.h"
#include "strv.h"
+#include "bus-errors.h"
#define BUS_MANAGER_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Manager\">\n" \
@@ -254,8 +255,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
DBUS_TYPE_INVALID))
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
- if (!(u = manager_get_unit(m, name)))
- return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
+ if (!(u = manager_get_unit(m, name))) {
+ dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
+ return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ }
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -280,8 +283,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
DBUS_TYPE_INVALID))
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
- if ((r = manager_load_unit(m, name, NULL, &u)) < 0)
- return bus_send_error_reply(m, connection, message, NULL, r);
+ if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
+ return bus_send_error_reply(m, connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -316,8 +319,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
DBUS_TYPE_INVALID))
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
- if (!(j = manager_get_job(m, id)))
- return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
+ if (!(j = manager_get_job(m, id))) {
+ dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
+ return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ }
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -496,8 +501,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
char *client;
- if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message))))
- return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
+ if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message)))) {
+ dbus_set_error(&error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
+ return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ }
free(client);
@@ -548,8 +555,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if (name && name[0] == 0)
name = NULL;
- if ((r = snapshot_create(m, name, cleanup, &s)) < 0)
- return bus_send_error_reply(m, connection, message, NULL, r);
+ if ((r = snapshot_create(m, name, cleanup, &error, &s)) < 0)
+ return bus_send_error_reply(m, connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -648,8 +655,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
- if (m->running_as == MANAGER_SYSTEM)
- return bus_send_error_reply(m, connection, message, NULL, -ENOTSUP);
+ if (m->running_as == MANAGER_SYSTEM) {
+ dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for session managers.");
+ return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
+ }
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -720,17 +729,21 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
DBUS_TYPE_INVALID))
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
- if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
- return bus_send_error_reply(m, connection, message, NULL, -EINVAL);
+ if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
+ dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
+ return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ }
- if ((r = manager_load_unit(m, name, NULL, &u)) < 0)
- return bus_send_error_reply(m, connection, message, NULL, r);
+ if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
+ return bus_send_error_reply(m, connection, message, &error, r);
- if (job_type == JOB_START && u->meta.only_by_dependency)
- return bus_send_error_reply(m, connection, message, NULL, -EPERM);
+ if (job_type == JOB_START && u->meta.only_by_dependency) {
+ dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Unit may be activated by dependency only.");
+ return bus_send_error_reply(m, connection, message, &error, -EPERM);
+ }
- if ((r = manager_add_job(m, job_type, u, mode, true, &j)) < 0)
- return bus_send_error_reply(m, connection, message, NULL, r);
+ if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
+ return bus_send_error_reply(m, connection, message, &error, r);
if (!(j->bus_client = strdup(message_get_sender_with_fallback(message))))
goto oom;
diff --git a/src/dbus-unit.c b/src/dbus-unit.c
index 85125c9..840eaa5 100644
--- a/src/dbus-unit.c
+++ b/src/dbus-unit.c
@@ -24,6 +24,7 @@
#include "dbus.h"
#include "log.h"
#include "dbus-unit.h"
+#include "bus-errors.h"
const char bus_unit_interface[] = BUS_UNIT_INTERFACE;
@@ -285,8 +286,10 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn
Job *j;
int r;
- if (job_type == JOB_START && u->meta.only_by_dependency)
- return bus_send_error_reply(m, connection, message, NULL, -EPERM);
+ if (job_type == JOB_START && u->meta.only_by_dependency) {
+ dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Unit may be activated by dependency only.");
+ return bus_send_error_reply(m, connection, message, &error, -EPERM);
+ }
if (!dbus_message_get_args(
message,
@@ -295,11 +298,13 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn
DBUS_TYPE_INVALID))
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
- if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
- return bus_send_error_reply(m, connection, message, NULL, -EINVAL);
+ if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
+ dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
+ return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ }
- if ((r = manager_add_job(m, job_type, u, mode, true, &j)) < 0)
- return bus_send_error_reply(m, connection, message, NULL, r);
+ if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
+ return bus_send_error_reply(m, connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
diff --git a/src/dbus.c b/src/dbus.c
index 0008cfd..2998c58 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -42,6 +42,7 @@
#include "dbus-swap.h"
#include "dbus-timer.h"
#include "dbus-path.h"
+#include "bus-errors.h"
#define CONNECTIONS_MAX 52
@@ -380,13 +381,13 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBus
log_debug("Got D-Bus activation request for %s", name);
- r = manager_load_unit(m, name, NULL, &u);
+ r = manager_load_unit(m, name, NULL, &error, &u);
if (r >= 0 && u->meta.only_by_dependency)
r = -EPERM;
if (r >= 0)
- r = manager_add_job(m, JOB_START, u, JOB_REPLACE, true, NULL);
+ r = manager_add_job(m, JOB_START, u, JOB_REPLACE, true, &error, NULL);
if (r < 0) {
const char *id, *text;
@@ -396,8 +397,8 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBus
if (!(reply = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure")))
goto oom;
- id = error_to_dbus(r);
- text = strerror(-r);
+ id = error.name ? error.name : error_to_dbus(r);
+ text = bus_error(&error, r);
if (!dbus_message_set_destination(reply, DBUS_SERVICE_DBUS) ||
!dbus_message_append_args(reply,
@@ -1324,13 +1325,13 @@ static const char *error_to_dbus(int error) {
return DBUS_ERROR_FAILED;
}
-DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *bus_error, int error) {
+DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *berror, int error) {
DBusMessage *reply = NULL;
const char *name, *text;
- if (bus_error && dbus_error_is_set(bus_error)) {
- name = bus_error->name;
- text = bus_error->message;
+ if (berror && dbus_error_is_set(berror)) {
+ name = berror->name;
+ text = berror->message;
} else {
name = error_to_dbus(error);
text = strerror(-error);
@@ -1344,8 +1345,8 @@ DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessag
dbus_message_unref(reply);
- if (bus_error)
- dbus_error_free(bus_error);
+ if (berror)
+ dbus_error_free(berror);
return DBUS_HANDLER_RESULT_HANDLED;
@@ -1353,8 +1354,8 @@ oom:
if (reply)
dbus_message_unref(reply);
- if (bus_error)
- dbus_error_free(bus_error);
+ if (berror)
+ dbus_error_free(berror);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
diff --git a/src/load-fragment.c b/src/load-fragment.c
index c3909e9..d474c9a 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -39,6 +39,7 @@
#include "securebits.h"
#include "missing.h"
#include "unit-name.h"
+#include "bus-errors.h"
#define COMMENTS "#;\n"
@@ -1057,14 +1058,23 @@ static int config_parse_timer_unit(
Timer *t = data;
int r;
+ DBusError error;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ dbus_error_init(&error);
if (endswith(rvalue, ".timer")) {
log_error("[%s:%u] Unit cannot be of type timer: %s", filename, line, rvalue);
return -EINVAL;
}
- if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &t->unit)) < 0) {
- log_error("[%s:%u] Failed to load unit: %s", filename, line, rvalue);
+ if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, NULL, &t->unit)) < 0) {
+ log_error("[%s:%u] Failed to load unit %s: %s", filename, line, rvalue, bus_error(&error, r));
+ dbus_error_free(&error);
return r;
}
@@ -1128,14 +1138,23 @@ static int config_parse_path_unit(
Path *t = data;
int r;
+ DBusError error;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ dbus_error_init(&error);
if (endswith(rvalue, ".path")) {
log_error("[%s:%u] Unit cannot be of type path: %s", filename, line, rvalue);
return -EINVAL;
}
- if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &t->unit)) < 0) {
- log_error("[%s:%u] Failed to load unit: %s", filename, line, rvalue);
+ if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &error, &t->unit)) < 0) {
+ log_error("[%s:%u] Failed to load unit %s: %s", filename, line, rvalue, bus_error(&error, r));
+ dbus_error_free(&error);
return r;
}
diff --git a/src/main.c b/src/main.c
index d5902b3..3124b76 100644
--- a/src/main.c
+++ b/src/main.c
@@ -43,6 +43,7 @@
#include "fdset.h"
#include "special.h"
#include "conf-parser.h"
+#include "bus-errors.h"
static enum {
ACTION_RUN,
@@ -963,14 +964,20 @@ int main(int argc, char *argv[]) {
fclose(serialization);
serialization = NULL;
} else {
+ DBusError error;
+
+ dbus_error_init(&error);
+
log_debug("Activating default unit: %s", arg_default_unit);
- if ((r = manager_load_unit(m, arg_default_unit, NULL, &target)) < 0) {
- log_error("Failed to load default target: %s", strerror(-r));
+ if ((r = manager_load_unit(m, arg_default_unit, NULL, &error, &target)) < 0) {
+ log_error("Failed to load default target: %s", bus_error(&error, r));
+ dbus_error_free(&error);
log_info("Trying to load rescue target...");
- if ((r = manager_load_unit(m, SPECIAL_RESCUE_TARGET, NULL, &target)) < 0) {
- log_error("Failed to load rescue target: %s", strerror(-r));
+ if ((r = manager_load_unit(m, SPECIAL_RESCUE_TARGET, NULL, &error, &target)) < 0) {
+ log_error("Failed to load rescue target: %s", bus_error(&error, r));
+ dbus_error_free(&error);
goto finish;
}
}
@@ -980,8 +987,9 @@ int main(int argc, char *argv[]) {
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));
+ if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &error, &job)) < 0) {
+ log_error("Failed to start default target: %s", bus_error(&error, r));
+ dbus_error_free(&error);
goto finish;
}
diff --git a/src/manager.c b/src/manager.c
index c1f70e8..9cbf9c8 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -53,6 +53,7 @@
#include "missing.h"
#include "path-lookup.h"
#include "special.h"
+#include "bus-errors.h"
/* As soon as 16 units are in our GC queue, make sure to run a gc sweep */
#define GC_QUEUE_ENTRIES_MAX 16
@@ -697,7 +698,7 @@ static int delete_one_unmergeable_job(Manager *m, Job *j) {
return -EINVAL;
}
-static int transaction_merge_jobs(Manager *m) {
+static int transaction_merge_jobs(Manager *m, DBusError *e) {
Job *j;
Iterator i;
int r;
@@ -726,6 +727,8 @@ static int transaction_merge_jobs(Manager *m) {
return -EAGAIN;
/* We couldn't merge anything. Failure */
+ dbus_set_error(e, BUS_ERROR_TRANSACTION_JOBS_CONFLICTING, "Transaction contains conflicting jobs '%s' and '%s' for %s. Probably contradicting requirement dependencies configured.",
+ job_type_to_string(t), job_type_to_string(k->type), k->unit->meta.id);
return r;
}
}
@@ -812,7 +815,7 @@ static bool unit_matters_to_anchor(Unit *u, Job *j) {
return false;
}
-static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned generation) {
+static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned generation, DBusError *e) {
Iterator i;
Unit *u;
int r;
@@ -863,6 +866,7 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned
log_error("Unable to break cycle");
+ dbus_set_error(e, BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC, "Transaction order is cyclic. See logs for details.");
return -ENOEXEC;
}
@@ -887,7 +891,7 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned
if (!(o = u->meta.job))
continue;
- if ((r = transaction_verify_order_one(m, o, j, generation)) < 0)
+ if ((r = transaction_verify_order_one(m, o, j, generation, e)) < 0)
return r;
}
@@ -898,7 +902,7 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned
return 0;
}
-static int transaction_verify_order(Manager *m, unsigned *generation) {
+static int transaction_verify_order(Manager *m, unsigned *generation, DBusError *e) {
Job *j;
int r;
Iterator i;
@@ -913,7 +917,7 @@ static int transaction_verify_order(Manager *m, unsigned *generation) {
g = (*generation)++;
HASHMAP_FOREACH(j, m->transaction_jobs, i)
- if ((r = transaction_verify_order_one(m, j, NULL, g)) < 0)
+ if ((r = transaction_verify_order_one(m, j, NULL, g, e)) < 0)
return r;
return 0;
@@ -945,7 +949,7 @@ static void transaction_collect_garbage(Manager *m) {
} while (again);
}
-static int transaction_is_destructive(Manager *m) {
+static int transaction_is_destructive(Manager *m, DBusError *e) {
Iterator i;
Job *j;
@@ -962,8 +966,11 @@ static int transaction_is_destructive(Manager *m) {
if (j->unit->meta.job &&
j->unit->meta.job != j &&
- !job_type_is_superset(j->type, j->unit->meta.job->type))
+ !job_type_is_superset(j->type, j->unit->meta.job->type)) {
+
+ dbus_set_error(e, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE, "Transaction is destructive.");
return -EEXIST;
+ }
}
return 0;
@@ -1080,7 +1087,7 @@ rollback:
return r;
}
-static int transaction_activate(Manager *m, JobMode mode) {
+static int transaction_activate(Manager *m, JobMode mode, DBusError *e) {
int r;
unsigned generation = 1;
@@ -1107,11 +1114,11 @@ static int transaction_activate(Manager *m, JobMode mode) {
/* Fifth step: verify order makes sense and correct
* cycles if necessary and possible */
- if ((r = transaction_verify_order(m, &generation)) >= 0)
+ if ((r = transaction_verify_order(m, &generation, e)) >= 0)
break;
if (r != -EAGAIN) {
- log_warning("Requested transaction contains an unfixable cyclic ordering dependency: %s", strerror(-r));
+ log_warning("Requested transaction contains an unfixable cyclic ordering dependency: %s", bus_error(e, r));
goto rollback;
}
@@ -1123,11 +1130,11 @@ static int transaction_activate(Manager *m, JobMode mode) {
/* Sixth step: let's drop unmergeable entries if
* necessary and possible, merge entries we can
* merge */
- if ((r = transaction_merge_jobs(m)) >= 0)
+ if ((r = transaction_merge_jobs(m, e)) >= 0)
break;
if (r != -EAGAIN) {
- log_warning("Requested transaction contains unmergable jobs: %s", strerror(-r));
+ log_warning("Requested transaction contains unmergable jobs: %s", bus_error(e, r));
goto rollback;
}
@@ -1144,8 +1151,8 @@ static int transaction_activate(Manager *m, JobMode mode) {
/* Ninth step: check whether we can actually apply this */
if (mode == JOB_FAIL)
- if ((r = transaction_is_destructive(m)) < 0) {
- log_notice("Requested transaction contradicts existing jobs: %s", strerror(-r));
+ if ((r = transaction_is_destructive(m, e)) < 0) {
+ log_notice("Requested transaction contradicts existing jobs: %s", bus_error(e, r));
goto rollback;
}
@@ -1253,6 +1260,7 @@ static int transaction_add_job_and_dependencies(
Job *by,
bool matters,
bool override,
+ DBusError *e,
Job **_ret) {
Job *ret;
Iterator i;
@@ -1264,11 +1272,15 @@ static int transaction_add_job_and_dependencies(
assert(type < _JOB_TYPE_MAX);
assert(unit);
- if (unit->meta.load_state != UNIT_LOADED)
+ if (unit->meta.load_state != UNIT_LOADED) {
+ dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s failed to load.", unit->meta.id);
return -EINVAL;
+ }
- if (!unit_job_is_applicable(unit, type))
+ if (!unit_job_is_applicable(unit, type)) {
+ dbus_set_error(e, BUS_ERROR_JOB_TYPE_NOT_APPLICABLE, "Job type %s is not applicable for unit %s.", job_type_to_string(type), unit->meta.id);
return -EBADR;
+ }
/* First add the job. */
if (!(ret = transaction_add_one_job(m, type, unit, override, &is_new)))
@@ -1282,33 +1294,33 @@ static int transaction_add_job_and_dependencies(
/* Finally, recursively add in all dependencies. */
if (type == JOB_START || type == JOB_RELOAD_OR_START) {
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRES], i)
- if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, override, NULL)) < 0 && r != -EBADR)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, override, e, NULL)) < 0 && r != -EBADR)
goto fail;
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
- if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !override, override, NULL)) < 0 && r != -EBADR)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !override, override, e, NULL)) < 0 && r != -EBADR)
log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r));
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_WANTS], i)
- if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, false, NULL)) < 0)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, false, e, NULL)) < 0)
log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r));
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUISITE], i)
- if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, true, override, NULL)) < 0 && r != -EBADR)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, true, override, e, NULL)) < 0 && r != -EBADR)
goto fail;
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUISITE_OVERRIDABLE], i)
- if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, !override, override, NULL)) < 0 && r != -EBADR)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, !override, override, e, NULL)) < 0 && r != -EBADR)
log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r));
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_CONFLICTS], i)
- if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, true, override, NULL)) < 0 && r != -EBADR)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, true, override, e, NULL)) < 0 && r != -EBADR)
goto fail;
} else if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRED_BY], i)
- if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, override, NULL)) < 0 && r != -EBADR)
+ if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, override, e, NULL)) < 0 && r != -EBADR)
goto fail;
}
@@ -1349,14 +1361,14 @@ static int transaction_add_isolate_jobs(Manager *m) {
if (hashmap_get(m->transaction_jobs, u))
continue;
- if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, u, NULL, true, false, NULL)) < 0)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, u, NULL, true, false, NULL, NULL)) < 0)
log_warning("Cannot add isolate job for unit %s, ignoring: %s", u->meta.id, strerror(-r));
}
return 0;
}
-int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool override, Job **_ret) {
+int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool override, DBusError *e, Job **_ret) {
int r;
Job *ret;
@@ -1365,12 +1377,14 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
assert(unit);
assert(mode < _JOB_MODE_MAX);
- if (mode == JOB_ISOLATE && type != JOB_START)
+ if (mode == JOB_ISOLATE && type != JOB_START) {
+ dbus_set_error(e, BUS_ERROR_INVALID_JOB_MODE, "Isolate is only valid for start.");
return -EINVAL;
+ }
log_debug("Trying to enqueue job %s/%s", unit->meta.id, job_type_to_string(type));
- if ((r = transaction_add_job_and_dependencies(m, type, unit, NULL, true, override, &ret)) < 0) {
+ if ((r = transaction_add_job_and_dependencies(m, type, unit, NULL, true, override, e, &ret)) < 0) {
transaction_abort(m);
return r;
}
@@ -1381,7 +1395,7 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
return r;
}
- if ((r = transaction_activate(m, mode)) < 0)
+ if ((r = transaction_activate(m, mode, e)) < 0)
return r;
log_debug("Enqueued job %s/%s as %u", unit->meta.id, job_type_to_string(type), (unsigned) ret->id);
@@ -1392,7 +1406,7 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
return 0;
}
-int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool override, Job **_ret) {
+int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool override, DBusError *e, Job **_ret) {
Unit *unit;
int r;
@@ -1401,10 +1415,10 @@ int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode
assert(name);
assert(mode < _JOB_MODE_MAX);
- if ((r = manager_load_unit(m, name, NULL, &unit)) < 0)
+ if ((r = manager_load_unit(m, name, NULL, NULL, &unit)) < 0)
return r;
- return manager_add_job(m, type, unit, mode, override, _ret);
+ return manager_add_job(m, type, unit, mode, override, e, _ret);
}
Job *manager_get_job(Manager *m, uint32_t id) {
@@ -1446,7 +1460,7 @@ unsigned manager_dispatch_load_queue(Manager *m) {
return n;
}
-int manager_load_unit_prepare(Manager *m, const char *name, const char *path, Unit **_ret) {
+int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
Unit *ret;
int r;
@@ -1456,14 +1470,18 @@ int manager_load_unit_prepare(Manager *m, const char *name, const char *path, Un
/* This will prepare the unit for loading, but not actually
* load anything from disk. */
- if (path && !is_path(path))
+ if (path && !is_path(path)) {
+ dbus_set_error(e, BUS_ERROR_INVALID_PATH, "Path %s is not absolute.", path);
return -EINVAL;
+ }
if (!name)
name = file_name_from_path(path);
- if (!unit_name_is_valid(name))
+ if (!unit_name_is_valid(name)) {
+ dbus_set_error(e, BUS_ERROR_INVALID_NAME, "Unit name %s is not valid.", name);
return -EINVAL;
+ }
if ((ret = manager_get_unit(m, name))) {
*_ret = ret;
@@ -1494,7 +1512,7 @@ int manager_load_unit_prepare(Manager *m, const char *name, const char *path, Un
return 0;
}
-int manager_load_unit(Manager *m, const char *name, const char *path, Unit **_ret) {
+int manager_load_unit(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
int r;
assert(m);
@@ -1502,7 +1520,7 @@ int manager_load_unit(Manager *m, const char *name, const char *path, Unit **_re
/* This will load the service information files, but not actually
* start any services or anything. */
- if ((r = manager_load_unit_prepare(m, name, path, _ret)) != 0)
+ if ((r = manager_load_unit_prepare(m, name, path, e, _ret)) != 0)
return r;
manager_dispatch_load_queue(m);
@@ -1746,9 +1764,14 @@ static int manager_dispatch_sigchld(Manager *m) {
static int manager_start_target(Manager *m, const char *name, JobMode mode) {
int r;
+ DBusError error;
+
+ dbus_error_init(&error);
+
+ if ((r = manager_add_job_by_name(m, JOB_START, name, mode, true, &error, NULL)) < 0)
+ log_error("Failed to enqueue %s job: %s", name, bus_error(&error, r));
- if ((r = manager_add_job_by_name(m, JOB_START, name, mode, true, NULL)) < 0)
- log_error("Failed to enqueue %s job: %s", name, strerror(-r));
+ dbus_error_free(&error);
return r;
}
@@ -2266,7 +2289,7 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
char_array_0(name);
- if ((r = manager_load_unit(m, strstrip(name), NULL, &u)) < 0)
+ if ((r = manager_load_unit(m, strstrip(name), NULL, NULL, &u)) < 0)
return r;
if ((r = unit_deserialize(u, f, fds)) < 0)
diff --git a/src/manager.h b/src/manager.h
index 5b3aaf3..e5cf3a1 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -210,11 +210,11 @@ Unit *manager_get_unit(Manager *m, const char *name);
int manager_get_unit_from_dbus_path(Manager *m, const char *s, Unit **_u);
int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j);
-int manager_load_unit_prepare(Manager *m, const char *name, const char *path, Unit **_ret);
-int manager_load_unit(Manager *m, const char *name, const char *path, Unit **_ret);
+int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret);
+int manager_load_unit(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret);
-int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, Job **_ret);
-int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool force, Job **_ret);
+int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, DBusError *e, Job **_ret);
+int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool force, DBusError *e, Job **_ret);
void manager_dump_units(Manager *s, FILE *f, const char *prefix);
void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
diff --git a/src/mount.c b/src/mount.c
index 49081d1..50fe85c 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -253,7 +253,7 @@ static int mount_add_target_links(Mount *m) {
else
target = SPECIAL_LOCAL_FS_TARGET;
- if ((r = manager_load_unit(m->meta.manager, target, NULL, &tu)) < 0)
+ if ((r = manager_load_unit(m->meta.manager, target, NULL, NULL, &tu)) < 0)
return r;
if (automount && m->meta.manager->running_as == MANAGER_SYSTEM) {
diff --git a/src/path.c b/src/path.c
index 30d946d..27c4544 100644
--- a/src/path.c
+++ b/src/path.c
@@ -30,6 +30,7 @@
#include "path.h"
#include "dbus-path.h"
#include "special.h"
+#include "bus-errors.h"
static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
[PATH_DEAD] = UNIT_INACTIVE,
@@ -298,17 +299,22 @@ static void path_enter_dead(Path *p, bool success) {
static void path_enter_running(Path *p) {
int r;
+ DBusError error;
+
assert(p);
+ dbus_error_init(&error);
- if ((r = manager_add_job(p->meta.manager, JOB_START, p->unit, JOB_REPLACE, true, NULL)) < 0)
+ if ((r = manager_add_job(p->meta.manager, JOB_START, p->unit, JOB_REPLACE, true, &error, NULL)) < 0)
goto fail;
path_set_state(p, PATH_RUNNING);
return;
fail:
- log_warning("%s failed to queue unit startup job: %s", p->meta.id, strerror(-r));
+ log_warning("%s failed to queue unit startup job: %s", p->meta.id, bus_error(&error, r));
path_enter_dead(p, false);
+
+ dbus_error_free(&error);
}
diff --git a/src/service.c b/src/service.c
index 35f2e9a..75439be 100644
--- a/src/service.c
+++ b/src/service.c
@@ -33,6 +33,7 @@
#include "unit-name.h"
#include "dbus-service.h"
#include "special.h"
+#include "bus-errors.h"
#define COMMENTS "#;\n"
#define NEWLINES "\n\r"
@@ -1763,20 +1764,24 @@ fail:
static void service_enter_restart(Service *s) {
int r;
+ DBusError error;
+
assert(s);
+ dbus_error_init(&error);
service_enter_dead(s, true, false);
- if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, NULL)) < 0)
+ if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, NULL, NULL)) < 0)
goto fail;
log_debug("%s scheduled restart job.", s->meta.id);
return;
fail:
-
- log_warning("%s failed to schedule restart job: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to schedule restart job: %s", s->meta.id, bus_error(&error, -r));
service_enter_dead(s, false, false);
+
+ dbus_error_free(&error);
}
static void service_enter_reload(Service *s) {
@@ -2538,7 +2543,7 @@ static int service_enumerate(Manager *m) {
goto finish;
}
- if ((r = manager_load_unit_prepare(m, name, NULL, &service)) < 0) {
+ if ((r = manager_load_unit_prepare(m, name, NULL, NULL, &service)) < 0) {
log_warning("Failed to prepare unit %s: %s", name, strerror(-r));
continue;
}
diff --git a/src/snapshot.c b/src/snapshot.c
index ba72edc..fe8a43d 100644
--- a/src/snapshot.c
+++ b/src/snapshot.c
@@ -25,6 +25,7 @@
#include "snapshot.h"
#include "unit-name.h"
#include "dbus-snapshot.h"
+#include "bus-errors.h"
static const UnitActiveState state_translation_table[_SNAPSHOT_STATE_MAX] = {
[SNAPSHOT_DEAD] = UNIT_INACTIVE,
@@ -174,7 +175,7 @@ static const char *snapshot_sub_state_to_string(Unit *u) {
return snapshot_state_to_string(SNAPSHOT(u)->state);
}
-int snapshot_create(Manager *m, const char *name, bool cleanup, Snapshot **_s) {
+int snapshot_create(Manager *m, const char *name, bool cleanup, DBusError *e, Snapshot **_s) {
Iterator i;
Unit *other, *u = NULL;
char *n = NULL;
@@ -185,14 +186,20 @@ int snapshot_create(Manager *m, const char *name, bool cleanup, Snapshot **_s) {
assert(_s);
if (name) {
- if (!unit_name_is_valid(name))
+ if (!unit_name_is_valid(name)) {
+ dbus_set_error(e, BUS_ERROR_INVALID_NAME, "Unit name %s is not valid.", name);
return -EINVAL;
+ }
- if (unit_name_to_type(name) != UNIT_SNAPSHOT)
+ if (unit_name_to_type(name) != UNIT_SNAPSHOT) {
+ dbus_set_error(e, BUS_ERROR_UNIT_TYPE_MISMATCH, "Unit name %s lacks snapshot suffix.", name);
return -EINVAL;
+ }
- if (manager_get_unit(m, name))
+ if (manager_get_unit(m, name)) {
+ dbus_set_error(e, BUS_ERROR_UNIT_EXISTS, "Snapshot %s exists already.", name);
return -EEXIST;
+ }
} else {
@@ -209,7 +216,7 @@ int snapshot_create(Manager *m, const char *name, bool cleanup, Snapshot **_s) {
name = n;
}
- r = manager_load_unit_prepare(m, name, NULL, &u);
+ r = manager_load_unit_prepare(m, name, NULL, e, &u);
free(n);
if (r < 0)
diff --git a/src/snapshot.h b/src/snapshot.h
index 2561790..2b5f3c3 100644
--- a/src/snapshot.h
+++ b/src/snapshot.h
@@ -44,7 +44,7 @@ struct Snapshot {
extern const UnitVTable snapshot_vtable;
-int snapshot_create(Manager *m, const char *name, bool cleanup, Snapshot **s);
+int snapshot_create(Manager *m, const char *name, bool cleanup, DBusError *e, Snapshot **s);
void snapshot_remove(Snapshot *s);
const char* snapshot_state_to_string(SnapshotState i);
diff --git a/src/socket.c b/src/socket.c
index 00e0685..b8643d9 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -38,6 +38,7 @@
#include "dbus-socket.h"
#include "missing.h"
#include "special.h"
+#include "bus-errors.h"
static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
[SOCKET_DEAD] = UNIT_INACTIVE,
@@ -1025,11 +1026,13 @@ fail:
static void socket_enter_running(Socket *s, int cfd) {
int r;
+ DBusError error;
assert(s);
+ dbus_error_init(&error);
if (cfd < 0) {
- if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s->service), JOB_REPLACE, true, NULL)) < 0)
+ if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s->service), JOB_REPLACE, true, &error, NULL)) < 0)
goto fail;
socket_set_state(s, SOCKET_RUNNING);
@@ -1061,7 +1064,7 @@ static void socket_enter_running(Socket *s, int cfd) {
goto fail;
}
- r = manager_load_unit(s->meta.manager, name, NULL, &u);
+ r = manager_load_unit(s->meta.manager, name, NULL, NULL, &u);
free(name);
if (r < 0)
@@ -1074,18 +1077,20 @@ static void socket_enter_running(Socket *s, int cfd) {
s->n_connections ++;
- if ((r = manager_add_job(u->meta.manager, JOB_START, u, JOB_REPLACE, true, NULL)) < 0)
+ if ((r = manager_add_job(u->meta.manager, JOB_START, u, JOB_REPLACE, true, &error, NULL)) < 0)
goto fail;
}
return;
fail:
- log_warning("%s failed to queue socket startup job: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to queue socket startup job: %s", s->meta.id, bus_error(&error, r));
socket_enter_stop_pre(s, false);
if (cfd >= 0)
close_nointr_nofail(cfd);
+
+ dbus_error_free(&error);
}
static void socket_run_next(Socket *s, bool success) {
diff --git a/src/swap.c b/src/swap.c
index f72ede6..9203514 100644
--- a/src/swap.c
+++ b/src/swap.c
@@ -110,7 +110,7 @@ static int swap_add_target_links(Swap *s) {
else
return 0;
- if ((r = manager_load_unit(s->meta.manager, SPECIAL_SWAP_TARGET, NULL, &tu)) < 0)
+ if ((r = manager_load_unit(s->meta.manager, SPECIAL_SWAP_TARGET, NULL, NULL, &tu)) < 0)
return r;
if (!p->noauto && p->handle && s->meta.manager->running_as == MANAGER_SYSTEM)
diff --git a/src/test-engine.c b/src/test-engine.c
index 89631c4..d10196b 100644
--- a/src/test-engine.c
+++ b/src/test-engine.c
@@ -36,61 +36,61 @@ int main(int argc, char *argv[]) {
assert_se(manager_new(MANAGER_SYSTEM, &m) >= 0);
printf("Load1:\n");
- assert_se(manager_load_unit(m, "a.service", NULL, &a) >= 0);
- assert_se(manager_load_unit(m, "b.service", NULL, &b) >= 0);
- assert_se(manager_load_unit(m, "c.service", NULL, &c) >= 0);
+ assert_se(manager_load_unit(m, "a.service", NULL, NULL, &a) >= 0);
+ assert_se(manager_load_unit(m, "b.service", NULL, NULL, &b) >= 0);
+ assert_se(manager_load_unit(m, "c.service", NULL, NULL, &c) >= 0);
manager_dump_units(m, stdout, "\t");
printf("Test1: (Trivial)\n");
- assert_se(manager_add_job(m, JOB_START, c, JOB_REPLACE, false, &j) == 0);
+ assert_se(manager_add_job(m, JOB_START, c, JOB_REPLACE, false, NULL, &j) == 0);
manager_dump_jobs(m, stdout, "\t");
printf("Load2:\n");
manager_clear_jobs(m);
- assert_se(manager_load_unit(m, "d.service", NULL, &d) >= 0);
- assert_se(manager_load_unit(m, "e.service", NULL, &e) >= 0);
+ assert_se(manager_load_unit(m, "d.service", NULL, NULL, &d) >= 0);
+ assert_se(manager_load_unit(m, "e.service", NULL, NULL, &e) >= 0);
manager_dump_units(m, stdout, "\t");
printf("Test2: (Cyclic Order, Unfixable)\n");
- assert_se(manager_add_job(m, JOB_START, d, JOB_REPLACE, false, &j) == -ENOEXEC);
+ assert_se(manager_add_job(m, JOB_START, d, JOB_REPLACE, false, NULL, &j) == -ENOEXEC);
manager_dump_jobs(m, stdout, "\t");
printf("Test3: (Cyclic Order, Fixable, Garbage Collector)\n");
- assert_se(manager_add_job(m, JOB_START, e, JOB_REPLACE, false, &j) == 0);
+ assert_se(manager_add_job(m, JOB_START, e, JOB_REPLACE, false, NULL, &j) == 0);
manager_dump_jobs(m, stdout, "\t");
printf("Test4: (Identical transaction)\n");
- assert_se(manager_add_job(m, JOB_START, e, JOB_FAIL, false, &j) == 0);
+ assert_se(manager_add_job(m, JOB_START, e, JOB_FAIL, false, NULL, &j) == 0);
manager_dump_jobs(m, stdout, "\t");
printf("Load3:\n");
- assert_se(manager_load_unit(m, "g.service", NULL, &g) >= 0);
+ assert_se(manager_load_unit(m, "g.service", NULL, NULL, &g) >= 0);
manager_dump_units(m, stdout, "\t");
printf("Test5: (Colliding transaction, fail)\n");
- assert_se(manager_add_job(m, JOB_START, g, JOB_FAIL, false, &j) == -EEXIST);
+ assert_se(manager_add_job(m, JOB_START, g, JOB_FAIL, false, NULL, &j) == -EEXIST);
printf("Test6: (Colliding transaction, replace)\n");
- assert_se(manager_add_job(m, JOB_START, g, JOB_REPLACE, false, &j) == 0);
+ assert_se(manager_add_job(m, JOB_START, g, JOB_REPLACE, false, NULL, &j) == 0);
manager_dump_jobs(m, stdout, "\t");
printf("Test7: (Unmeargable job type, fail)\n");
- assert_se(manager_add_job(m, JOB_STOP, g, JOB_FAIL, false, &j) == -EEXIST);
+ assert_se(manager_add_job(m, JOB_STOP, g, JOB_FAIL, false, NULL, &j) == -EEXIST);
printf("Test8: (Mergeable job type, fail)\n");
- assert_se(manager_add_job(m, JOB_RESTART, g, JOB_FAIL, false, &j) == 0);
+ assert_se(manager_add_job(m, JOB_RESTART, g, JOB_FAIL, false, NULL, &j) == 0);
manager_dump_jobs(m, stdout, "\t");
printf("Test9: (Unmeargable job type, replace)\n");
- assert_se(manager_add_job(m, JOB_STOP, g, JOB_REPLACE, false, &j) == 0);
+ assert_se(manager_add_job(m, JOB_STOP, g, JOB_REPLACE, false, NULL, &j) == 0);
manager_dump_jobs(m, stdout, "\t");
printf("Load4:\n");
- assert_se(manager_load_unit(m, "h.service", NULL, &h) >= 0);
+ assert_se(manager_load_unit(m, "h.service", NULL, NULL, &h) >= 0);
manager_dump_units(m, stdout, "\t");
printf("Test10: (Unmeargable job type of auxiliary job, fail)\n");
- assert_se(manager_add_job(m, JOB_START, h, JOB_FAIL, false, &j) == 0);
+ assert_se(manager_add_job(m, JOB_START, h, JOB_FAIL, false, NULL, &j) == 0);
manager_dump_jobs(m, stdout, "\t");
manager_free(m);
diff --git a/src/timer.c b/src/timer.c
index b4521e6..1c7010d 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -26,6 +26,7 @@
#include "timer.h"
#include "dbus-timer.h"
#include "special.h"
+#include "bus-errors.h"
static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = {
[TIMER_DEAD] = UNIT_INACTIVE,
@@ -261,18 +262,23 @@ fail:
}
static void timer_enter_running(Timer *t) {
+ DBusError error;
int r;
+
assert(t);
+ dbus_error_init(&error);
- if ((r = manager_add_job(t->meta.manager, JOB_START, t->unit, JOB_REPLACE, true, NULL)) < 0)
+ if ((r = manager_add_job(t->meta.manager, JOB_START, t->unit, JOB_REPLACE, true, &error, NULL)) < 0)
goto fail;
timer_set_state(t, TIMER_RUNNING);
return;
fail:
- log_warning("%s failed to queue unit startup job: %s", t->meta.id, strerror(-r));
+ log_warning("%s failed to queue unit startup job: %s", t->meta.id, bus_error(&error, r));
timer_enter_dead(t, false);
+
+ dbus_error_free(&error);
}
static int timer_start(Unit *u) {
diff --git a/src/unit.c b/src/unit.c
index 1874cdf..a5f8712 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -881,7 +881,7 @@ static void unit_check_uneeded(Unit *u) {
log_info("Service %s is not needed anymore. Stopping.", u->meta.id);
/* Ok, nobody needs us anymore. Sniff. Then let's commit suicide */
- manager_add_job(u->meta.manager, JOB_STOP, u, JOB_FAIL, true, NULL);
+ manager_add_job(u->meta.manager, JOB_STOP, u, JOB_FAIL, true, NULL, NULL);
}
static void retroactively_start_dependencies(Unit *u) {
@@ -893,23 +893,23 @@ static void retroactively_start_dependencies(Unit *u) {
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES], i)
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
- manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL);
+ manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL, NULL);
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
- manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL);
+ manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL, NULL);
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUISITE], i)
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
- manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL);
+ manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL, NULL);
SET_FOREACH(other, u->meta.dependencies[UNIT_WANTS], i)
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
- manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL);
+ manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL, NULL);
SET_FOREACH(other, u->meta.dependencies[UNIT_CONFLICTS], i)
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
- manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL);
+ manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL, NULL);
}
static void retroactively_stop_dependencies(Unit *u) {
@@ -923,7 +923,7 @@ static void retroactively_stop_dependencies(Unit *u) {
/* Pull down units need us recursively if enabled */
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
- manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL);
+ manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL, NULL);
}
/* Garbage collect services that might not be needed anymore, if enabled */
@@ -1391,7 +1391,7 @@ int unit_add_dependency_by_name(Unit *u, UnitDependency d, const char *name, con
if (!(name = resolve_template(u, name, path, &s)))
return -ENOMEM;
- if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
+ if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
goto finish;
r = unit_add_dependency(u, d, other, add_reference);
@@ -1412,7 +1412,7 @@ int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency
if (!(name = resolve_template(u, name, path, &s)))
return -ENOMEM;
- if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
+ if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
goto finish;
r = unit_add_two_dependencies(u, d, e, other, add_reference);
@@ -1433,7 +1433,7 @@ int unit_add_dependency_by_name_inverse(Unit *u, UnitDependency d, const char *n
if (!(name = resolve_template(u, name, path, &s)))
return -ENOMEM;
- if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
+ if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
goto finish;
r = unit_add_dependency(other, d, u, add_reference);
@@ -1454,7 +1454,7 @@ int unit_add_two_dependencies_by_name_inverse(Unit *u, UnitDependency d, UnitDep
if (!(name = resolve_template(u, name, path, &s)))
return -ENOMEM;
- if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
+ if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
goto finish;
if ((r = unit_add_two_dependencies(other, d, e, u, add_reference)) < 0)
@@ -1682,7 +1682,7 @@ int unit_load_related_unit(Unit *u, const char *type, Unit **_found) {
assert(!unit_has_name(u, t));
- r = manager_load_unit(u->meta.manager, t, NULL, _found);
+ r = manager_load_unit(u->meta.manager, t, NULL, NULL, _found);
free(t);
assert(r < 0 || *_found != u);
@@ -1967,7 +1967,7 @@ int unit_add_node_link(Unit *u, const char *what, bool wants) {
if (!(e = unit_name_build_escape(what+1, NULL, ".device")))
return -ENOMEM;
- r = manager_load_unit(u->meta.manager, e, NULL, &device);
+ r = manager_load_unit(u->meta.manager, e, NULL, NULL, &device);
free(e);
if (r < 0)
@@ -1993,7 +1993,7 @@ int unit_coldplug(Unit *u) {
return r;
if (u->meta.deserialized_job >= 0) {
- if ((r = manager_add_job(u->meta.manager, u->meta.deserialized_job, u, JOB_FAIL, false, NULL)) < 0)
+ if ((r = manager_add_job(u->meta.manager, u->meta.deserialized_job, u, JOB_FAIL, false, NULL, NULL)) < 0)
return r;
u->meta.deserialized_job = _JOB_TYPE_INVALID;
commit 2105e76a7725d6a29ebfe0af0bf23b3279e466a2
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 8 00:47:35 2010 +0200
service: set env var for stop/reload commands
diff --git a/src/service.c b/src/service.c
index fed8227..35f2e9a 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1328,8 +1328,8 @@ static int service_spawn(
pid_t pid;
int r;
int *fds = NULL, *fdsbuf = NULL;
- unsigned n_fds = 0;
- char **argv = NULL, **env = NULL;
+ unsigned n_fds = 0, n_env = 0;
+ char **argv = NULL, **final_env = NULL, **our_env = NULL;
assert(s);
assert(c);
@@ -1362,63 +1362,64 @@ static int service_spawn(
goto fail;
}
- if (set_notify_socket) {
- char *t;
+ if (!(our_env = new0(char*, 3))) {
+ r = -ENOMEM;
+ goto fail;
+ }
- if (asprintf(&t, "NOTIFY_SOCKET=@%s", s->meta.manager->notify_socket) < 0) {
+ if (set_notify_socket)
+ if (asprintf(our_env + n_env++, "NOTIFY_SOCKET=@%s", s->meta.manager->notify_socket) < 0) {
r = -ENOMEM;
goto fail;
}
- env = strv_env_set(s->meta.manager->environment, t);
- free(t);
-
- if (!env) {
+ if (s->main_pid > 0)
+ if (asprintf(our_env + n_env++, "MAINPID=%lu", (unsigned long) s->main_pid) < 0) {
r = -ENOMEM;
goto fail;
}
- } else
- env = s->meta.manager->environment;
+
+ if (!(final_env = strv_env_merge(2,
+ s->meta.manager->environment,
+ our_env,
+ NULL))) {
+ r = -ENOMEM;
+ goto fail;
+ }
r = exec_spawn(c,
argv,
&s->exec_context,
fds, n_fds,
- env,
+ final_env,
apply_permissions,
apply_chroot,
s->meta.manager->confirm_spawn,
s->meta.cgroup_bondings,
&pid);
- strv_free(argv);
- argv = NULL;
-
- if (set_notify_socket)
- strv_free(env);
- env = NULL;
-
if (r < 0)
goto fail;
- if (fdsbuf)
- free(fdsbuf);
if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
/* FIXME: we need to do something here */
goto fail;
+ free(fdsbuf);
+ strv_free(argv);
+ strv_free(our_env);
+ strv_free(final_env);
+
*_pid = pid;
return 0;
fail:
- free(fds);
-
+ free(fdsbuf);
strv_free(argv);
-
- if (set_notify_socket)
- strv_free(env);
+ strv_free(our_env);
+ strv_free(final_env);
if (timeout)
unit_unwatch_timer(UNIT(s), &s->timer_watch);
More information about the systemd-commits
mailing list