_cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
_cleanup_free_ char *path = NULL;
_cleanup_close_ int fifo_fd = -1;
- bool exists;
+ dbus_bool_t exists;
/* Session already exists, client is probably
* something like "su" which changes uid but is still
session->create_message = dbus_message_ref(message);
+ /* Now, let's wait until the slice unit and stuff got
+ * created. We send the reply back from
+ * session_send_create_reply().*/
+
return 0;
fail:
dbus_set_error(&error, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
session_send_create_reply(s, &error);
}
- }
+ } else
+ session_save(s);
}
session_add_to_gc_queue(s);
u->slice_job = NULL;
}
+ user_save(u);
user_add_to_gc_queue(u);
}
}
if (u)
user_add_to_gc_queue(u);
}
+
+ } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "UnitRemoved")) {
+
+ const char *path, *unit;
+ Session *session;
+ User *user;
+
+ if (!dbus_message_get_args(message, &error,
+ DBUS_TYPE_STRING, &unit,
+ DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID)) {
+ log_error("Failed to parse UnitRemoved message: %s", bus_error_message(&error));
+ goto finish;
+ }
+
+ session = hashmap_get(m->session_units, unit);
+ if (session)
+ session_add_to_gc_queue(session);
+
+ user = hashmap_get(m->user_units, unit);
+ if (user)
+ user_add_to_gc_queue(user);
+
+ } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "Reloading")) {
+ dbus_bool_t b;
+
+ if (!dbus_message_get_args(message, &error,
+ DBUS_TYPE_BOOLEAN, &b,
+ DBUS_TYPE_INVALID)) {
+ log_error("Failed to parse Reloading message: %s", bus_error_message(&error));
+ goto finish;
+ }
+
+ /* systemd finished reloading, let's recheck all our sessions */
+ if (!b) {
+ Session *session;
+ Iterator i;
+
+ log_debug("System manager has been reloaded, rechecking sessions...");
+
+ HASHMAP_FOREACH(session, m->sessions, i)
+ session_add_to_gc_queue(session);
+ }
}
finish:
pid_t pid,
const char *slice,
const char *description,
+ const char *after,
DBusError *error,
char **job) {
return log_oom();
}
+ if (!isempty(after)) {
+ const char *after_property = "After";
+
+ if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
+ !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &after_property) ||
+ !dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, "as", &sub3) ||
+ !dbus_message_iter_open_container(&sub3, DBUS_TYPE_ARRAY, "s", &sub4) ||
+ !dbus_message_iter_append_basic(&sub4, DBUS_TYPE_STRING, &after) ||
+ !dbus_message_iter_close_container(&sub3, &sub4) ||
+ !dbus_message_iter_close_container(&sub2, &sub3) ||
+ !dbus_message_iter_close_container(&sub, &sub2))
+ return log_oom();
+ }
+
/* cgroup empty notification is not available in containers
* currently. To make this less problematic, let's shorten the
* stop timeout for sessions, so that we don't wait
DBUS_TYPE_STRING, &fail,
DBUS_TYPE_INVALID);
if (r < 0) {
+ if (dbus_error_has_name(error, BUS_ERROR_NO_SUCH_UNIT) ||
+ dbus_error_has_name(error, BUS_ERROR_LOAD_FAILED)) {
+
+ if (job)
+ *job = NULL;
+
+ dbus_error_free(error);
+ return 0;
+ }
+
log_error("Failed to stop unit %s: %s", unit, bus_error(error, r));
return r;
}
*job = copy;
}
- return 0;
+ return 1;
}
int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, DBusError *error) {
DBUS_TYPE_STRING, &interface,
DBUS_TYPE_STRING, &property,
DBUS_TYPE_INVALID);
-
if (r < 0) {
+ if (dbus_error_has_name(&error, DBUS_ERROR_NO_REPLY) ||
+ dbus_error_has_name(&error, DBUS_ERROR_DISCONNECTED)) {
+ /* systemd might have droppped off
+ * momentarily, let's not make this an
+ * error */
+
+ dbus_error_free(&error);
+ return true;
+ }
+
+ if (dbus_error_has_name(&error, BUS_ERROR_NO_SUCH_UNIT) ||
+ dbus_error_has_name(&error, BUS_ERROR_LOAD_FAILED)) {
+ /* If the unit is already unloaded then it's
+ * not active */
+
+ dbus_error_free(&error);
+ return false;
+ }
+
log_error("Failed to query ActiveState: %s", bus_error(&error, r));
dbus_error_free(&error);
return r;