X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flogind-user-dbus.c;h=3673a28bd4ceb6c7eeb64427b731536d8f32422b;hp=3be2c05d263f2b2d7c6c562d7489290d2fa51b4f;hb=edb4977837cbf82b0edc29cf8cbefa00c380fa16;hpb=a185c5aa2d8bef98716f8cf160da263c17e588b2 diff --git a/src/logind-user-dbus.c b/src/logind-user-dbus.c index 3be2c05d2..3673a28bd 100644 --- a/src/logind-user-dbus.c +++ b/src/logind-user-dbus.c @@ -29,6 +29,9 @@ #define BUS_USER_INTERFACE \ " \n" \ " \n" \ + " \n" \ + " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ @@ -121,7 +124,7 @@ static int bus_user_append_sessions(DBusMessageIter *i, const char *property, vo assert(property); assert(u); - if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "so", &sub)) + if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "(so)", &sub)) return -ENOMEM; LIST_FOREACH(sessions_by_user, session, u->sessions) { @@ -154,13 +157,14 @@ static int bus_user_append_sessions(DBusMessageIter *i, const char *property, vo static int bus_user_append_idle_hint(DBusMessageIter *i, const char *property, void *data) { User *u = data; - bool b; + dbus_bool_t b; assert(i); assert(property); assert(u); - b = user_get_idle_hint(u, NULL); + b = user_get_idle_hint(u, NULL) > 0; + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b)) return -ENOMEM; @@ -249,6 +253,27 @@ static DBusHandlerResult user_message_dispatch( reply = dbus_message_new_method_return(message); if (!reply) goto oom; + } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.User", "Kill")) { + int32_t signo; + + if (!dbus_message_get_args( + message, + &error, + DBUS_TYPE_INT32, &signo, + DBUS_TYPE_INVALID)) + return bus_send_error_reply(connection, message, &error, -EINVAL); + + if (signo <= 0 || signo >= _NSIG) + return bus_send_error_reply(connection, message, &error, -EINVAL); + + r = user_kill(u, signo); + if (r < 0) + return bus_send_error_reply(connection, message, NULL, r); + + reply = dbus_message_new_method_return(message); + if (!reply) + goto oom; + } else return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties); @@ -313,3 +338,74 @@ char *user_bus_path(User *u) { return s; } + +int user_send_signal(User *u, bool new_user) { + DBusMessage *m; + int r = -ENOMEM; + char *p = NULL; + uint32_t uid; + + assert(u); + + m = dbus_message_new_signal("/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + new_user ? "UserNew" : "UserRemoved"); + + if (!m) + return -ENOMEM; + + p = user_bus_path(u); + if (!p) + goto finish; + + uid = u->uid; + + if (!dbus_message_append_args( + m, + DBUS_TYPE_UINT32, &uid, + DBUS_TYPE_OBJECT_PATH, &p, + DBUS_TYPE_INVALID)) + goto finish; + + if (!dbus_connection_send(u->manager->bus, m, NULL)) + goto finish; + + r = 0; + +finish: + dbus_message_unref(m); + free(p); + + return r; +} + +int user_send_changed(User *u, const char *properties) { + DBusMessage *m; + int r = -ENOMEM; + char *p = NULL; + + assert(u); + + if (!u->started) + return 0; + + p = user_bus_path(u); + if (!p) + return -ENOMEM; + + m = bus_properties_changed_new(p, "org.freedesktop.login1.User", properties); + if (!m) + goto finish; + + if (!dbus_connection_send(u->manager->bus, m, NULL)) + goto finish; + + r = 0; + +finish: + if (m) + dbus_message_unref(m); + free(p); + + return r; +}