diff options
author | Scott Anderson <ascent12@hotmail.com> | 2017-05-03 16:23:07 +1200 |
---|---|---|
committer | Scott Anderson <ascent12@hotmail.com> | 2017-05-03 16:23:07 +1200 |
commit | 81998fdc98231cb1b2e050da2fcec7c75d46320c (patch) | |
tree | 1ccf64d2df9a5942e8b497df9a5f766eaf92aac2 | |
parent | 762ac7f4c0168bf2ce536d94b3b44cb95939d769 (diff) |
Removed old session code from DRM backend.
-rw-r--r-- | backend/CMakeLists.txt | 1 | ||||
-rw-r--r-- | backend/drm/backend.c | 26 | ||||
-rw-r--r-- | backend/drm/session.c | 219 | ||||
-rw-r--r-- | backend/drm/udev.c | 11 | ||||
-rw-r--r-- | example/CMakeLists.txt | 1 | ||||
-rw-r--r-- | example/example-drm.c | 9 | ||||
-rw-r--r-- | include/backend/drm/backend.h | 9 | ||||
-rw-r--r-- | include/backend/drm/session.h | 24 | ||||
-rw-r--r-- | include/backend/drm/udev.h | 2 | ||||
-rw-r--r-- | include/wlr/backend/drm.h | 6 | ||||
-rw-r--r-- | session/logind.c | 3 | ||||
-rw-r--r-- | session/session.c | 3 |
12 files changed, 40 insertions, 274 deletions
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index 184854fe..ee8b04d6 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -11,7 +11,6 @@ add_library(wlr-backend wayland/wl_output.c drm/backend.c drm/drm.c - drm/session.c drm/udev.c ) diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 7db6e9a1..9f9a02c7 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -4,17 +4,16 @@ #include <string.h> #include <errno.h> +#include <wlr/session.h> #include <wlr/common/list.h> #include "backend/drm/backend.h" #include "backend/drm/drm.h" -#include "backend/drm/session.h" #include "backend/drm/udev.h" #include "common/log.h" -struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add, - struct wl_listener *rem, - struct wl_listener *render) +struct wlr_drm_backend *wlr_drm_backend_init(struct wlr_session *session, + struct wl_listener *add, struct wl_listener *rem, struct wl_listener *render) { struct wlr_drm_backend *backend = calloc(1, sizeof *backend); if (!backend) { @@ -22,6 +21,8 @@ struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add, return NULL; } + backend->session = session; + backend->displays = list_create(); if (!backend->displays) { wlr_log(L_ERROR, "Failed to allocate list"); @@ -34,17 +35,12 @@ struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add, goto error_list; } - if (!wlr_session_start(&backend->session)) { - wlr_log(L_ERROR, "Failed to start session"); - goto error_loop; - } - if (!wlr_udev_init(backend)) { wlr_log(L_ERROR, "Failed to start udev"); - goto error_session; + goto error_loop; } - backend->fd = wlr_udev_find_gpu(&backend->udev, &backend->session); + backend->fd = wlr_udev_find_gpu(&backend->udev, backend->session); if (backend->fd == -1) { wlr_log(L_ERROR, "Failed to open DRM device"); goto error_udev; @@ -71,11 +67,9 @@ struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add, return backend; error_fd: - wlr_session_release_device(&backend->session, backend->fd); + wlr_session_close_file(backend->session, backend->fd); error_udev: wlr_udev_free(&backend->udev); -error_session: - wlr_session_end(&backend->session); error_loop: wl_event_loop_destroy(backend->event_loop); error_list: @@ -101,8 +95,8 @@ void wlr_drm_backend_free(struct wlr_drm_backend *backend) wlr_drm_renderer_free(&backend->renderer); wlr_udev_free(&backend->udev); - wlr_session_release_device(&backend->session, backend->fd); - wlr_session_end(&backend->session); + wlr_session_close_file(backend->session, backend->fd); + wlr_session_finish(backend->session); wl_event_source_remove(backend->event_src.drm); wl_event_source_remove(backend->event_src.udev); diff --git a/backend/drm/session.c b/backend/drm/session.c deleted file mode 100644 index 073f822b..00000000 --- a/backend/drm/session.c +++ /dev/null @@ -1,219 +0,0 @@ -#define _POSIX_C_SOURCE 200809L - -#include <stdio.h> -#include <stdbool.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <systemd/sd-bus.h> -#include <systemd/sd-login.h> -#include <unistd.h> -#include <sys/sysmacros.h> -#include <sys/stat.h> -#include <fcntl.h> - -#include "backend/drm/backend.h" -#include "backend/drm/session.h" -#include "common/log.h" - -int wlr_session_take_device(struct wlr_session *restrict session, - const char *restrict path, - bool *restrict paused_out) -{ - int ret; - int fd = -1; - sd_bus_message *msg = NULL; - sd_bus_error error = SD_BUS_ERROR_NULL; - - struct stat st; - if (stat(path, &st) < 0) { - wlr_log(L_ERROR, "Failed to stat '%s'", path); - return -1; - } - - ret = sd_bus_call_method(session->bus, - "org.freedesktop.login1", - session->path, - "org.freedesktop.login1.Session", - "TakeDevice", - &error, &msg, - "uu", major(st.st_rdev), minor(st.st_rdev)); - if (ret < 0) { - wlr_log(L_ERROR, "Failed to take device '%s': %s", path, error.message); - goto error; - } - - int paused = 0; - ret = sd_bus_message_read(msg, "hb", &fd, &paused); - if (ret < 0) { - wlr_log(L_ERROR, "Failed to parse DBus response for '%s': %s", - path, strerror(-ret)); - goto error; - } - - // The original fd seem to be closed when the message is freed - // so we just clone it. - fd = fcntl(fd, F_DUPFD_CLOEXEC, 0); - if (fd == -1) { - wlr_log(L_ERROR, "Failed to clone file descriptor for '%s': %s", - path, strerror(errno)); - goto error; - } - - if (paused_out) - *paused_out = paused; - -error: - sd_bus_error_free(&error); - sd_bus_message_unref(msg); - return fd; -} - -void wlr_session_release_device(struct wlr_session *session, int fd) -{ - int ret; - sd_bus_message *msg = NULL; - sd_bus_error error = SD_BUS_ERROR_NULL; - - struct stat st; - if (fstat(fd, &st) < 0) { - wlr_log(L_ERROR, "Failed to stat device '%d'", fd); - return; - } - - ret = sd_bus_call_method(session->bus, - "org.freedesktop.login1", - session->path, - "org.freedesktop.login1.Session", - "ReleaseDevice", - &error, &msg, - "uu", major(st.st_rdev), minor(st.st_rdev)); - if (ret < 0) - wlr_log(L_ERROR, "Failed to release device '%d'", fd); - - sd_bus_error_free(&error); - sd_bus_message_unref(msg); -} - -static bool session_activate(struct wlr_session *session) -{ - int ret; - sd_bus_message *msg = NULL; - sd_bus_error error = SD_BUS_ERROR_NULL; - - ret = sd_bus_call_method(session->bus, - "org.freedesktop.login1", - session->path, - "org.freedesktop.login1.Session", - "Activate", - &error, &msg, - ""); - if (ret < 0) - wlr_log(L_ERROR, "Failed to activate session"); - - sd_bus_error_free(&error); - sd_bus_message_unref(msg); - return ret >= 0; -} - -static bool take_control(struct wlr_session *session) -{ - int ret; - sd_bus_message *msg = NULL; - sd_bus_error error = SD_BUS_ERROR_NULL; - - ret = sd_bus_call_method(session->bus, - "org.freedesktop.login1", - session->path, - "org.freedesktop.login1.Session", - "TakeControl", - &error, &msg, - "b", false); - if (ret < 0) - wlr_log(L_ERROR, "Failed to take control of session"); - - sd_bus_error_free(&error); - sd_bus_message_unref(msg); - return ret >= 0; -} - -static void release_control(struct wlr_session *session) -{ - int ret; - sd_bus_message *msg = NULL; - sd_bus_error error = SD_BUS_ERROR_NULL; - - ret = sd_bus_call_method(session->bus, - "org.freedesktop.login1", - session->path, - "org.freedesktop.login1.Session", - "ReleaseControl", - &error, &msg, - ""); - if (ret < 0) - wlr_log(L_ERROR, "Failed to release control of session"); - - sd_bus_error_free(&error); - sd_bus_message_unref(msg); -} - -void wlr_session_end(struct wlr_session *session) -{ - release_control(session); - - sd_bus_unref(session->bus); - free(session->id); - free(session->path); - free(session->seat); -} - -bool wlr_session_start(struct wlr_session *session) -{ - int ret; - - ret = sd_pid_get_session(getpid(), &session->id); - if (ret < 0) { - wlr_log(L_ERROR, "Failed to get session id: %s", strerror(-ret)); - goto error; - } - - ret = sd_session_get_seat(session->id, &session->seat); - if (ret < 0) { - wlr_log(L_ERROR, "Failed to get seat id: %s", strerror(-ret)); - goto error; - } - - // This could be done using asprintf, but I don't want to define _GNU_SOURCE - - const char *fmt = "/org/freedesktop/login1/session/%s"; - int len = snprintf(NULL, 0, fmt, session->id); - - session->path = malloc(len + 1); - if (!session->path) - goto error; - - sprintf(session->path, fmt, session->id); - - ret = sd_bus_default_system(&session->bus); - if (ret < 0) { - wlr_log(L_ERROR, "Failed to open DBus connection: %s", strerror(-ret)); - goto error; - } - - if (!session_activate(session)) - goto error_bus; - - if (!take_control(session)) - goto error_bus; - - return true; - -error_bus: - sd_bus_unref(session->bus); - -error: - free(session->path); - free(session->id); - free(session->seat); - return false; -} diff --git a/backend/drm/udev.c b/backend/drm/udev.c index ae99bcfc..6921a998 100644 --- a/backend/drm/udev.c +++ b/backend/drm/udev.c @@ -9,9 +9,10 @@ #include <xf86drmMode.h> #include <wayland-server.h> +#include <wlr/session.h> + #include "backend/drm/backend.h" #include "backend/drm/udev.h" -#include "backend/drm/session.h" #include "backend/drm/drm.h" #include "common/log.h" @@ -26,7 +27,7 @@ static bool device_is_kms(struct wlr_udev *udev, if (!path) return false; - fd = wlr_session_take_device(session, path, NULL); + fd = wlr_session_open_file(session, path); if (fd < 0) return false; @@ -39,7 +40,7 @@ static bool device_is_kms(struct wlr_udev *udev, goto out_res; if (*fd_out >= 0) { - wlr_session_release_device(session, *fd_out); + wlr_session_close_file(session, *fd_out); free(udev->drm_path); } @@ -52,7 +53,7 @@ static bool device_is_kms(struct wlr_udev *udev, out_res: drmModeFreeResources(res); out_fd: - wlr_session_release_device(session, fd); + wlr_session_close_file(session, fd); return false; } @@ -79,6 +80,7 @@ int wlr_udev_find_gpu(struct wlr_udev *udev, struct wlr_session *session) if (!dev) continue; + /* const char *seat = udev_device_get_property_value(dev, "ID_SEAT"); if (!seat) seat = "seat0"; @@ -86,6 +88,7 @@ int wlr_udev_find_gpu(struct wlr_udev *udev, struct wlr_session *session) udev_device_unref(dev); continue; } + */ struct udev_device *pci = udev_device_get_parent_with_subsystem_devtype(dev, "pci", NULL); diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index dfb069b4..fb2f3823 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -12,4 +12,5 @@ add_executable(example-drm target_link_libraries(example-drm wlr-backend + wlr-session ) diff --git a/example/example-drm.c b/example/example-drm.c index 4c944226..a3a2a8fd 100644 --- a/example/example-drm.c +++ b/example/example-drm.c @@ -6,6 +6,7 @@ #include <GLES3/gl3.h> #include <wlr/backend/drm.h> +#include <wlr/session.h> struct state { float color[3]; @@ -92,7 +93,13 @@ int main() wl_list_init(&state.render.link); clock_gettime(CLOCK_MONOTONIC, &state.last_frame); - struct wlr_drm_backend *wlr = wlr_drm_backend_init(&state.add, &state.rem, &state.render); + struct wlr_session *session = wlr_session_start(); + if (!session) { + return 1; + } + + struct wlr_drm_backend *wlr = wlr_drm_backend_init(session, + &state.add, &state.rem, &state.render); bool done = false; struct wl_event_loop *event_loop = wlr_drm_backend_get_event_loop(wlr); diff --git a/include/backend/drm/backend.h b/include/backend/drm/backend.h index 1ad8e479..32182d0c 100644 --- a/include/backend/drm/backend.h +++ b/include/backend/drm/backend.h @@ -8,10 +8,10 @@ #include <libudev.h> #include <wayland-server.h> +#include <wlr/session.h> #include <wlr/common/list.h> #include <wlr/backend/drm.h> -#include "session.h" #include "udev.h" #include "event.h" #include "drm.h" @@ -38,13 +38,12 @@ struct wlr_drm_backend { uint32_t taken_crtcs; struct wlr_drm_renderer renderer; - struct wlr_session session; + struct wlr_session *session; struct wlr_udev udev; }; -struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add, - struct wl_listener *rem, - struct wl_listener *render); +struct wlr_drm_backend *wlr_drm_backend_init(struct wlr_session *session, + struct wl_listener *add, struct wl_listener *rem, struct wl_listener *render); void wlr_drm_backend_free(struct wlr_drm_backend *backend); #endif diff --git a/include/backend/drm/session.h b/include/backend/drm/session.h deleted file mode 100644 index 6936b19a..00000000 --- a/include/backend/drm/session.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef SESSION_H -#define SESSION_H - -#include <systemd/sd-bus.h> -#include <stdbool.h> - -struct wlr_session { - sd_bus *bus; - - char *id; - char *path; - char *seat; -}; - -bool wlr_session_start(struct wlr_session *session); -void wlr_session_end(struct wlr_session *session); - -int wlr_session_take_device(struct wlr_session *restrict session, - const char *restrict path, - bool *restrict paused_out); - -void wlr_session_release_device(struct wlr_session *session, int fd); - -#endif diff --git a/include/backend/drm/udev.h b/include/backend/drm/udev.h index 576b5d6e..a09ee218 100644 --- a/include/backend/drm/udev.h +++ b/include/backend/drm/udev.h @@ -3,7 +3,7 @@ #include <libudev.h> -#include "backend/drm/session.h" +#include <wlr/session.h> struct wlr_udev { struct udev *udev; diff --git a/include/wlr/backend/drm.h b/include/wlr/backend/drm.h index 5179db4b..ede43fda 100644 --- a/include/wlr/backend/drm.h +++ b/include/wlr/backend/drm.h @@ -2,13 +2,13 @@ #define WLR_BACKEND_DRM_H #include <wayland-server.h> +#include <wlr/session.h> struct wlr_drm_backend; struct wlr_drm_display; -struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add, - struct wl_listener *rem, - struct wl_listener *render); +struct wlr_drm_backend *wlr_drm_backend_init(struct wlr_session *session, + struct wl_listener *add, struct wl_listener *rem, struct wl_listener *render); void wlr_drm_backend_free(struct wlr_drm_backend *backend); struct wl_event_loop *wlr_drm_backend_get_event_loop(struct wlr_drm_backend *backend); diff --git a/session/logind.c b/session/logind.c index c81a2020..0d8a52b5 100644 --- a/session/logind.c +++ b/session/logind.c @@ -200,6 +200,9 @@ static struct wlr_session *logind_session_start(void) { if (!take_control(session)) goto error_bus; + wl_log(L_INFO, "Successfully loaded logind session"); + + session->base.iface = session_logind_iface; return &session->base; error_bus: diff --git a/session/session.c b/session/session.c index 88391e6e..2f1b87be 100644 --- a/session/session.c +++ b/session/session.c @@ -1,6 +1,8 @@ #include <stddef.h> #include <wlr/session.h> +#include <stdarg.h> +#include "common/log.h" #include "session/interface.h" static const struct session_interface *ifaces[] = { @@ -20,6 +22,7 @@ struct wlr_session *wlr_session_start(void) { } } + wlr_log(L_ERROR, "Failed to load session backend"); return NULL; } |