mirror of
https://github.com/systemd/systemd.git
synced 2024-11-06 16:59:03 +03:00
logind: implement more dbus functionality
This commit is contained in:
parent
a185c5aa2d
commit
bef422ae1e
@ -27,26 +27,26 @@
|
||||
|
||||
#define BUS_MANAGER_INTERFACE \
|
||||
" <interface name=\"org.freedesktop.login1.Manager\">\n" \
|
||||
" <method name=\"GetSeat\">\n" \
|
||||
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
|
||||
" <arg name=\"seat\" type=\"o\" direction=\"out\"/>\n" \
|
||||
" </method>\n" \
|
||||
" <method name=\"GetUser\">\n" \
|
||||
" <arg name=\"uid\" type=\"t\" direction=\"in\"/>\n" \
|
||||
" <arg name=\"user\" type=\"o\" direction=\"out\"/>\n" \
|
||||
" </method>\n" \
|
||||
" <method name=\"GetSession\">\n" \
|
||||
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
|
||||
" <arg name=\"session\" type=\"o\" direction=\"out\"/>\n" \
|
||||
" </method>\n" \
|
||||
" <method name=\"ListSeats\">\n" \
|
||||
" <arg name=\"seats\" type=\"a(so)\" direction=\"out\"/>\n" \
|
||||
" <method name=\"GetUser\">\n" \
|
||||
" <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
|
||||
" <arg name=\"user\" type=\"o\" direction=\"out\"/>\n" \
|
||||
" </method>\n" \
|
||||
" <method name=\"GetSeat\">\n" \
|
||||
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
|
||||
" <arg name=\"seat\" type=\"o\" direction=\"out\"/>\n" \
|
||||
" </method>\n" \
|
||||
" <method name=\"ListSessions\">\n" \
|
||||
" <arg name=\"users\" type=\"a(sussso)\" direction=\"out\"/>\n" \
|
||||
" </method>\n" \
|
||||
" <method name=\"ListUsers\">\n" \
|
||||
" <arg name=\"users\" type=\"a(uso)\" direction=\"out\"/>\n" \
|
||||
" </method>\n" \
|
||||
" <method name=\"ListSessions\">\n" \
|
||||
" <arg name=\"users\" type=\"a(sussso)\" direction=\"out\"/>\n" \
|
||||
" <method name=\"ListSeats\">\n" \
|
||||
" <arg name=\"seats\" type=\"a(so)\" direction=\"out\"/>\n" \
|
||||
" </method>\n" \
|
||||
" <method name=\"CreateSession\">\n" \
|
||||
" <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
|
||||
@ -72,7 +72,7 @@
|
||||
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
|
||||
" </method>\n" \
|
||||
" <method name=\"TerminateUser\">\n" \
|
||||
" <arg name=\"uid\" type=\"t\" direction=\"in\"/>\n" \
|
||||
" <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
|
||||
" </method>\n" \
|
||||
" <method name=\"TerminateSeat\">\n" \
|
||||
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
|
||||
@ -184,6 +184,7 @@ static DBusHandlerResult manager_message_handler(
|
||||
|
||||
DBusError error;
|
||||
DBusMessage *reply = NULL;
|
||||
int r;
|
||||
|
||||
assert(connection);
|
||||
assert(message);
|
||||
@ -191,7 +192,201 @@ static DBusHandlerResult manager_message_handler(
|
||||
|
||||
dbus_error_init(&error);
|
||||
|
||||
if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
|
||||
if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetSession")) {
|
||||
const char *name;
|
||||
char *p;
|
||||
Session *session;
|
||||
bool b;
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
message,
|
||||
&error,
|
||||
DBUS_TYPE_STRING, &name,
|
||||
DBUS_TYPE_INVALID))
|
||||
return bus_send_error_reply(connection, message, &error, -EINVAL);
|
||||
|
||||
session = hashmap_get(m->sessions, name);
|
||||
if (!session)
|
||||
return bus_send_error_reply(connection, message, &error, -ENOENT);
|
||||
|
||||
reply = dbus_message_new_method_return(message);
|
||||
if (!reply)
|
||||
goto oom;
|
||||
|
||||
p = session_bus_path(session);
|
||||
if (!p)
|
||||
goto oom;
|
||||
|
||||
b = dbus_message_append_args(
|
||||
reply,
|
||||
DBUS_TYPE_OBJECT_PATH, &p,
|
||||
DBUS_TYPE_INVALID);
|
||||
free(p);
|
||||
|
||||
if (!b)
|
||||
goto oom;
|
||||
|
||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetUser")) {
|
||||
uint32_t uid;
|
||||
char *p;
|
||||
User *user;
|
||||
bool b;
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
message,
|
||||
&error,
|
||||
DBUS_TYPE_UINT32, &uid,
|
||||
DBUS_TYPE_INVALID))
|
||||
return bus_send_error_reply(connection, message, &error, -EINVAL);
|
||||
|
||||
user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
|
||||
if (!user)
|
||||
return bus_send_error_reply(connection, message, &error, -ENOENT);
|
||||
|
||||
reply = dbus_message_new_method_return(message);
|
||||
if (!reply)
|
||||
goto oom;
|
||||
|
||||
p = user_bus_path(user);
|
||||
if (!p)
|
||||
goto oom;
|
||||
|
||||
b = dbus_message_append_args(
|
||||
reply,
|
||||
DBUS_TYPE_OBJECT_PATH, &p,
|
||||
DBUS_TYPE_INVALID);
|
||||
free(p);
|
||||
|
||||
if (!b)
|
||||
goto oom;
|
||||
|
||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetSeat")) {
|
||||
const char *name;
|
||||
char *p;
|
||||
Seat *seat;
|
||||
bool b;
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
message,
|
||||
&error,
|
||||
DBUS_TYPE_STRING, &name,
|
||||
DBUS_TYPE_INVALID))
|
||||
return bus_send_error_reply(connection, message, &error, -EINVAL);
|
||||
|
||||
seat = hashmap_get(m->seats, name);
|
||||
if (!seat)
|
||||
return bus_send_error_reply(connection, message, &error, -ENOENT);
|
||||
|
||||
reply = dbus_message_new_method_return(message);
|
||||
if (!reply)
|
||||
goto oom;
|
||||
|
||||
p = seat_bus_path(seat);
|
||||
if (!p)
|
||||
goto oom;
|
||||
|
||||
b = dbus_message_append_args(
|
||||
reply,
|
||||
DBUS_TYPE_OBJECT_PATH, &p,
|
||||
DBUS_TYPE_INVALID);
|
||||
free(p);
|
||||
|
||||
if (!b)
|
||||
goto oom;
|
||||
|
||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ActivateSession")) {
|
||||
const char *name;
|
||||
Session *session;
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
message,
|
||||
&error,
|
||||
DBUS_TYPE_STRING, &name,
|
||||
DBUS_TYPE_INVALID))
|
||||
return bus_send_error_reply(connection, message, &error, -EINVAL);
|
||||
|
||||
session = hashmap_get(m->sessions, name);
|
||||
if (!session)
|
||||
return bus_send_error_reply(connection, message, &error, -ENOENT);
|
||||
|
||||
r = session_activate(session);
|
||||
if (r < 0)
|
||||
return bus_send_error_reply(connection, message, NULL, r);
|
||||
|
||||
reply = dbus_message_new_method_return(message);
|
||||
if (!reply)
|
||||
goto oom;
|
||||
|
||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateSession")) {
|
||||
const char *name;
|
||||
Session *session;
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
message,
|
||||
&error,
|
||||
DBUS_TYPE_STRING, &name,
|
||||
DBUS_TYPE_INVALID))
|
||||
return bus_send_error_reply(connection, message, &error, -EINVAL);
|
||||
|
||||
session = hashmap_get(m->sessions, name);
|
||||
if (!session)
|
||||
return bus_send_error_reply(connection, message, &error, -ENOENT);
|
||||
|
||||
r = session_stop(session);
|
||||
if (r < 0)
|
||||
return bus_send_error_reply(connection, message, NULL, r);
|
||||
|
||||
reply = dbus_message_new_method_return(message);
|
||||
if (!reply)
|
||||
goto oom;
|
||||
|
||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateUser")) {
|
||||
uint32_t uid;
|
||||
User *user;
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
message,
|
||||
&error,
|
||||
DBUS_TYPE_UINT32, &uid,
|
||||
DBUS_TYPE_INVALID))
|
||||
return bus_send_error_reply(connection, message, &error, -EINVAL);
|
||||
|
||||
user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
|
||||
if (!user)
|
||||
return bus_send_error_reply(connection, message, &error, -ENOENT);
|
||||
|
||||
r = user_stop(user);
|
||||
if (r < 0)
|
||||
return bus_send_error_reply(connection, message, NULL, r);
|
||||
|
||||
reply = dbus_message_new_method_return(message);
|
||||
if (!reply)
|
||||
goto oom;
|
||||
|
||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateSeat")) {
|
||||
const char *name;
|
||||
Seat *seat;
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
message,
|
||||
&error,
|
||||
DBUS_TYPE_STRING, &name,
|
||||
DBUS_TYPE_INVALID))
|
||||
return bus_send_error_reply(connection, message, &error, -EINVAL);
|
||||
|
||||
seat = hashmap_get(m->seats, name);
|
||||
if (!seat)
|
||||
return bus_send_error_reply(connection, message, &error, -ENOENT);
|
||||
|
||||
r = seat_stop_sessions(seat);
|
||||
if (r < 0)
|
||||
return bus_send_error_reply(connection, message, NULL, r);
|
||||
|
||||
reply = dbus_message_new_method_return(message);
|
||||
if (!reply)
|
||||
goto oom;
|
||||
|
||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
|
||||
char *introspection = NULL;
|
||||
FILE *f;
|
||||
Iterator i;
|
||||
|
@ -249,11 +249,90 @@ static DBusHandlerResult session_message_dispatch(
|
||||
{ NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
DBusError error;
|
||||
DBusMessage *reply = NULL;
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
assert(connection);
|
||||
assert(message);
|
||||
|
||||
return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties);
|
||||
dbus_error_init(&error);
|
||||
|
||||
if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Terminate")) {
|
||||
|
||||
r = session_stop(s);
|
||||
if (r < 0)
|
||||
return bus_send_error_reply(connection, message, NULL, r);
|
||||
|
||||
reply = dbus_message_new_method_return(message);
|
||||
if (!reply)
|
||||
goto oom;
|
||||
|
||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Activate")) {
|
||||
|
||||
r = session_activate(s);
|
||||
if (r < 0)
|
||||
return bus_send_error_reply(connection, message, NULL, r);
|
||||
|
||||
reply = dbus_message_new_method_return(message);
|
||||
if (!reply)
|
||||
goto oom;
|
||||
|
||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Lock") ||
|
||||
dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Unlock")) {
|
||||
bool b;
|
||||
DBusMessage *sig;
|
||||
|
||||
sig = dbus_message_new_signal(dbus_message_get_path(message), "org.freedesktop.login1.Session", dbus_message_get_member(message));
|
||||
if (!sig)
|
||||
goto oom;
|
||||
|
||||
b = dbus_connection_send(connection, sig, NULL);
|
||||
dbus_message_unref(sig);
|
||||
|
||||
if (!b)
|
||||
goto oom;
|
||||
|
||||
reply = dbus_message_new_method_return(message);
|
||||
if (!reply)
|
||||
goto oom;
|
||||
|
||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "SetIdleHint")) {
|
||||
dbus_bool_t b;
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
message,
|
||||
&error,
|
||||
DBUS_TYPE_BOOLEAN, &b,
|
||||
DBUS_TYPE_INVALID))
|
||||
return bus_send_error_reply(connection, message, &error, -EINVAL);
|
||||
|
||||
session_set_idle_hint(s, b);
|
||||
|
||||
reply = dbus_message_new_method_return(message);
|
||||
if (!reply)
|
||||
goto oom;
|
||||
|
||||
} else
|
||||
return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties);
|
||||
|
||||
if (reply) {
|
||||
if (!dbus_connection_send(connection, reply, NULL))
|
||||
goto oom;
|
||||
|
||||
dbus_message_unref(reply);
|
||||
}
|
||||
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
|
||||
oom:
|
||||
if (reply)
|
||||
dbus_message_unref(reply);
|
||||
|
||||
dbus_error_free(&error);
|
||||
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
}
|
||||
|
||||
static DBusHandlerResult session_message_handler(
|
||||
|
@ -595,6 +595,16 @@ dont_know:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void session_set_idle_hint(Session *s, bool b) {
|
||||
assert(s);
|
||||
|
||||
if (s->idle_hint == b)
|
||||
return;
|
||||
|
||||
s->idle_hint = b;
|
||||
dual_timestamp_get(&s->idle_hint_timestamp);
|
||||
}
|
||||
|
||||
int session_check_gc(Session *s) {
|
||||
int r;
|
||||
|
||||
|
@ -86,6 +86,7 @@ void session_add_to_gc_queue(Session *s);
|
||||
int session_activate(Session *s);
|
||||
bool session_is_active(Session *s);
|
||||
int session_get_idle_hint(Session *s, dual_timestamp *t);
|
||||
void session_set_idle_hint(Session *s, bool b);
|
||||
int session_start(Session *s);
|
||||
int session_stop(Session *s);
|
||||
int session_save(Session *s);
|
||||
|
Loading…
Reference in New Issue
Block a user