diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2019-03-27 11:50:56 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2019-03-27 11:50:56 +0100 |
commit | 135c11a9e5ff2244cb215ab14798769d859ec998 (patch) | |
tree | eed396116b447dda07413638a21021abc2cf5743 /vttest.c | |
parent | ab34bbe232a6e5d4cc129e851ddd0d6b9d5ef9ff (diff) | |
download | fbida-135c11a9e5ff2244cb215ab14798769d859ec998.tar.gz |
[wip] logind console switching
Diffstat (limited to 'vttest.c')
-rw-r--r-- | vttest.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/vttest.c b/vttest.c new file mode 100644 index 0000000..2de51c8 --- /dev/null +++ b/vttest.c @@ -0,0 +1,67 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <inttypes.h> +#include <time.h> +#include <fcntl.h> +#include <ctype.h> +#include <errno.h> +#include <termios.h> + +#include "logind.h" + +/* ---------------------------------------------------------------------- */ + +int main(int argc, char *argv[]) +{ + const char *xdg_seat, *xdg_session_id; + int dbus; + + xdg_seat = getenv("XDG_SEAT"); + xdg_session_id = getenv("XDG_SESSION_ID"); + if (!xdg_seat || !xdg_session_id) { + fprintf(stderr, "session id or seat not found\n"); + exit(1); + } + + fprintf(stderr, "session %s at %s\n", + xdg_session_id, xdg_seat); + if (logind_init(false) != 0) { + fprintf(stderr, "logind init failed\n"); + exit(1); + } + dbus = logind_dbus_fd(); + +#if 0 + logind_open("/dev/dri/card0", 0, NULL); + + const char *xdg_vtnr = getenv("XDG_VTNR"); + if (xdg_vtnr) { + int vt = atoi(xdg_vtnr); + vt++; + fprintf(stderr, "switch to vt %d\n", vt); + logind_switch_vt(vt); + } +#endif + + for (;;) { + fd_set set; + int rc, max; + + max = 0; + FD_ZERO(&set); + FD_SET(dbus, &set); + if (max < dbus) + max = dbus; + + rc = select(max+ 1, &set, NULL, NULL, NULL); + if (rc < 0) + break; + + if (FD_ISSET(dbus, &set)) { + logind_dbus_input(); + } + } + return 0; +} |