From f9fda8e6926928edf7b412acdf435a0307542201 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Sun, 10 Jan 2021 09:18:31 +0000 Subject: Get the path to the console device from the X server. --- include/dm.h | 1 + xenodm/dm.c | 40 ++++++++++++++++++++++++++++++++++++++++ xenodm/dpylist.c | 2 ++ 3 files changed, 43 insertions(+) diff --git a/include/dm.h b/include/dm.h index 76de42e..ab67e33 100644 --- a/include/dm.h +++ b/include/dm.h @@ -135,6 +135,7 @@ struct display { Display *dpy; /* Display */ char *windowPath; /* path to server "window" */ + char *consolePath; /* path to the console device */ /* autologin */ char *autoLogin; /* user to auto-login */ diff --git a/xenodm/dm.c b/xenodm/dm.c index 1b0353f..a524d65 100644 --- a/xenodm/dm.c +++ b/xenodm/dm.c @@ -37,6 +37,7 @@ from The Open Group. #include "dm_auth.h" #include "dm_error.h" +#include #include #include @@ -491,6 +492,44 @@ StartDisplays (void) ForEachDisplay (CheckDisplayStatus); } +static void +SetConsolePath(struct display *d) +{ + Atom prop; + Atom actualtype; + int actualformat; + unsigned long nitems; + unsigned long bytes_after; + unsigned char *buf; + + prop = XInternAtom(d->dpy, "Xorg_Console", False); + if (prop == None) { + LogError("no Xorg_Console atom\n"); + return; + } + if (XGetWindowProperty(d->dpy, DefaultRootWindow(d->dpy), prop, 0, + TTY_NAME_MAX << 2, + False, AnyPropertyType, &actualtype, &actualformat, + &nitems, &bytes_after, &buf)) { + LogError("no Xorg_Console property\n"); + return; + } + if (actualtype != XA_STRING) { + LogError("type %lx in Xorg_Console property!\n", actualtype); + XFree(buf); + return; + } + if (actualformat != 8) { + LogError("format %d in Xorg_Console property!\n", actualformat); + XFree(buf); + return; + } + d->consolePath = strdup(buf + strlen(_PATH_DEV)); + LogInfo("consolePath: %s\n", d->consolePath); + XFree(buf); +} + + static void SetWindowPath(struct display *d) { @@ -595,6 +634,7 @@ StartDisplay (struct display *d) SetAuthorization (d); if (!WaitForServer (d)) exit (OPENFAILED_DISPLAY); + SetConsolePath(d); SetWindowPath(d); if (pledge("stdio rpath cpath wpath fattr flock proc dns inet unix exec prot_exec getpw id", NULL) != 0) exit(OPENFAILED_DISPLAY); diff --git a/xenodm/dpylist.c b/xenodm/dpylist.c index 32adbfa..f70086b 100644 --- a/xenodm/dpylist.c +++ b/xenodm/dpylist.c @@ -134,6 +134,7 @@ RemoveDisplay (struct display *old) free (d->authNames); free (d->authNameLens); free (d->windowPath); + free (d->consolePath); free (d); break; } @@ -210,6 +211,7 @@ NewDisplay (char *name, char *class) d->grabTimeout = 0; d->dpy = NULL; d->windowPath = NULL; + d->consolePath = NULL; displays = d; return d; } -- cgit v1.2.3