return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static int wait_for_jobs(DBusConnection *bus, Set *s) {
+static int enable_wait_for_jobs(DBusConnection *bus) {
DBusError error;
DBusMessage *m = NULL, *reply = NULL;
int r;
assert(bus);
- assert(s);
dbus_error_init(&error);
goto finish;
}
- if (!dbus_connection_add_filter(bus, wait_filter, s, NULL)) {
- log_error("Failed to add filter.");
- r = -ENOMEM;
- goto finish;
- }
-
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
goto finish;
}
- while (!set_isempty(s) &&
- dbus_connection_read_write_dispatch(bus, -1))
- ;
-
r = 0;
finish:
- /* This is slightly dirty, since we don't undo the filter or the matches. */
+ /* This is slightly dirty, since we don't undo the match registrations. */
if (m)
dbus_message_unref(m);
return r;
}
+static int wait_for_jobs(DBusConnection *bus, Set *s) {
+ int r;
+
+ assert(bus);
+ assert(s);
+
+ if (!dbus_connection_add_filter(bus, wait_filter, s, NULL)) {
+ log_error("Failed to add filter.");
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ while (!set_isempty(s) &&
+ dbus_connection_read_write_dispatch(bus, -1))
+ ;
+
+ r = 0;
+
+finish:
+ /* This is slightly dirty, since we don't undo the filter registration. */
+
+ return r;
+}
+
static int start_unit(DBusConnection *bus, char **args, unsigned n) {
DBusMessage *m = NULL, *reply = NULL;
DBusError error;
mode = arg_replace ? "replace" : "fail";
+ if (arg_block) {
+ if ((r = enable_wait_for_jobs(bus)) < 0) {
+ log_error("Could not watch jobs: %s", strerror(-r));
+ goto finish;
+ }
+ }
+
for (i = 1; i < n; i++) {
if (!(m = dbus_message_new_method_call(
dbus_error_init(&error);
+ if (arg_block) {
+ if ((r = enable_wait_for_jobs(bus)) < 0) {
+ log_error("Could not watch jobs: %s", strerror(-r));
+ goto finish;
+ }
+ }
+
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
" show-environment Dump environment\n"
" set-environment [NAME=VALUE...] Set one or more environment variables\n"
" unset-environment [NAME...] Unset one or more environment variables\n",
- __progname);
+ program_invocation_short_name);
return 0;
}
{ "replace", no_argument, NULL, ARG_REPLACE },
{ "session", no_argument, NULL, ARG_SESSION },
{ "system", no_argument, NULL, ARG_SYSTEM },
- { "block", no_argument, NULL, ARG_BLOCK }
+ { "block", no_argument, NULL, ARG_BLOCK },
+ { NULL, 0, NULL, 0 }
};
int c;
int main(int argc, char*argv[]) {
-
static const struct {
const char* verb;
const enum {
dbus_error_init(&error);
log_set_target(LOG_TARGET_CONSOLE);
+ log_set_max_level(LOG_INFO);
log_parse_environment();
if ((r = parse_argv(argc, argv)) < 0)