Skip to content

Commit 6482cd9

Browse files
cepelinas9000markhindleyRalph Ronnquist
authored andcommitted
Patch 5/6 xfree86: libseat support, wire-up seatd-libseat.h into Xserver
Add necessary code into Xserver to support libseat (this time enabling functionality). Code used from Devuan repository + local changes to make functional in Xlibre Co-Authored-By: Mark Hindley <[email protected]> Co-Authored-By: Ralph Ronnquist <[email protected]> Signed-off-By: Tautvis <[email protected]>
1 parent 5456698 commit 6482cd9

File tree

7 files changed

+91
-29
lines changed

7 files changed

+91
-29
lines changed

hw/xfree86/common/xf86Events.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
#endif
9292

9393
#include "../os-support/linux/systemd-logind.h"
94+
#include "seatd-libseat.h"
95+
9496

9597
extern void (*xf86OSPMClose) (void);
9698

@@ -182,7 +184,9 @@ xf86ProcessActionEvent(ActionEvent action, void *arg)
182184
int vtno = *((int *) arg);
183185

184186
if (vtno != xf86Info.vtno) {
185-
if (!xf86VTActivate(vtno)) {
187+
if (seatd_libseat_controls_session()) {
188+
seatd_libseat_switch_session(vtno);
189+
} else if (!xf86VTActivate(vtno)) {
186190
ErrorF("Failed to switch from vt%02d to vt%02d: %s\n",
187191
xf86Info.vtno, vtno, strerror(errno));
188192
}
@@ -191,7 +195,9 @@ xf86ProcessActionEvent(ActionEvent action, void *arg)
191195
break;
192196
case ACTION_SWITCHSCREEN_NEXT:
193197
if (!xf86Info.dontVTSwitch) {
194-
if (!xf86VTActivate(xf86Info.vtno + 1)) {
198+
if (seatd_libseat_controls_session()) {
199+
seatd_libseat_switch_session(xf86Info.vtno + 1);
200+
} else if (!xf86VTActivate(xf86Info.vtno + 1)) {
195201
/* If first try failed, assume this is the last VT and
196202
* try wrapping around to the first vt.
197203
*/
@@ -204,7 +210,9 @@ xf86ProcessActionEvent(ActionEvent action, void *arg)
204210
break;
205211
case ACTION_SWITCHSCREEN_PREV:
206212
if (!xf86Info.dontVTSwitch && xf86Info.vtno > 0) {
207-
if (!xf86VTActivate(xf86Info.vtno - 1)) {
213+
if (seatd_libseat_controls_session()) {
214+
seatd_libseat_switch_session(xf86Info.vtno - 1);
215+
} else if (!xf86VTActivate(xf86Info.vtno - 1)) {
208216
/* Don't know what the maximum VT is, so can't wrap around */
209217
ErrorF("Failed to switch from vt%02d to previous vt: %s\n",
210218
xf86Info.vtno, strerror(errno));
@@ -225,8 +233,10 @@ xf86ProcessActionEvent(ActionEvent action, void *arg)
225233
void
226234
xf86Wakeup(void *blockData, int err)
227235
{
228-
if (xf86VTSwitchPending())
229-
xf86VTSwitch();
236+
if (xf86VTSwitchPending() ||
237+
(dispatchException & DE_TERMINATE)){
238+
xf86VTSwitch();
239+
}
230240
}
231241

232242
/*
@@ -304,6 +314,7 @@ static void xf86DisableInputDeviceForVTSwitch(InputInfoPtr pInfo)
304314

305315
xf86ReleaseKeys(pInfo->dev);
306316
ProcessInputEvents();
317+
seatd_libseat_close_device(pInfo);
307318
DisableDevice(pInfo->dev, TRUE);
308319
}
309320

@@ -489,7 +500,7 @@ xf86VTEnter(void)
489500
dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
490501

491502
for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) {
492-
/* Devices with server managed fds get enabled on logind resume */
503+
/* Devices with server managed fds get enabled on logind/libseat resume */
493504
if (!(pInfo->flags & XI86_SERVER_FD))
494505
xf86EnableInputDeviceForVTSwitch(pInfo);
495506
}
@@ -519,6 +530,9 @@ xf86VTSwitch(void)
519530
{
520531
DebugF("xf86VTSwitch()\n");
521532

533+
if(!(dispatchException & DE_TERMINATE))
534+
assert(!seatd_libseat_controls_session());
535+
522536
#ifdef XFreeXDGA
523537
if (!DGAVTSwitch())
524538
return;

hw/xfree86/common/xf86Init.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
#include "windowstr.h"
6767
#include "scrnintstr.h"
6868
#include "../os-support/linux/systemd-logind.h"
69+
#include "seatd-libseat.h"
70+
6971
#include "xf86VGAarbiter_priv.h"
7072
#include "loaderProcs.h"
7173

@@ -339,6 +341,7 @@ InitOutput(int argc, char **argv)
339341
DoShowOptions();
340342

341343
dbus_core_init();
344+
seatd_libseat_init(xf86VTKeepTtyIsSet());
342345
systemd_logind_init();
343346

344347
/* Do a general bus probe. This will be a PCI probe for x86 platforms */
@@ -432,9 +435,11 @@ InitOutput(int argc, char **argv)
432435
xorgHWOpenConsole = TRUE;
433436
}
434437

435-
if (xorgHWOpenConsole)
436-
xf86OpenConsole();
437-
else
438+
if (xorgHWOpenConsole) {
439+
if (!seatd_libseat_controls_session()) {
440+
xf86OpenConsole();
441+
}
442+
} else
438443
xf86Info.dontVTSwitch = TRUE;
439444

440445
/* Enable full I/O access */
@@ -566,8 +571,11 @@ InitOutput(int argc, char **argv)
566571
/*
567572
* serverGeneration != 1; some OSs have to do things here, too.
568573
*/
569-
if (xorgHWOpenConsole)
570-
xf86OpenConsole();
574+
if (xorgHWOpenConsole) {
575+
if (!seatd_libseat_controls_session()) {
576+
xf86OpenConsole();
577+
}
578+
}
571579

572580
/*
573581
should we reopen it here? We need to deal with an already opened
@@ -843,9 +851,13 @@ ddxGiveUp(enum ExitCode error)
843851
xf86Screens[i]->vtSema = FALSE;
844852
}
845853

846-
if (xorgHWOpenConsole)
847-
xf86CloseConsole();
854+
if (xorgHWOpenConsole) {
855+
if (!seatd_libseat_controls_session()) {
856+
xf86CloseConsole();
857+
}
858+
}
848859

860+
seatd_libseat_fini();
849861
systemd_logind_fini();
850862
dbus_core_fini();
851863

hw/xfree86/common/xf86Xinput.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
#include "mipointer.h"
7373
#include "loaderProcs.h"
7474
#include "../os-support/linux/systemd-logind.h"
75+
#include "seatd-libseat.h"
76+
7577
#include "exevents.h" /* AddInputDevice */
7678
#include "exglobals.h"
7779
#include "eventstr.h"
@@ -858,9 +860,10 @@ xf86DeleteInput(InputInfoPtr pInp, int flags)
858860

859861
FreeInputAttributes(pInp->attrs);
860862

861-
if (pInp->flags & XI86_SERVER_FD)
863+
if (pInp->flags & XI86_SERVER_FD){
864+
seatd_libseat_close_device(pInp);
862865
systemd_logind_release_fd(pInp->major, pInp->minor, pInp->fd);
863-
866+
}
864867
/* Remove the entry from the list. */
865868
if (pInp == xf86InputDevs)
866869
xf86InputDevs = pInp->next;
@@ -987,6 +990,7 @@ xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable)
987990
if (path && (drv->capabilities & XI86_DRV_CAP_SERVER_FD)){
988991
int fd = systemd_logind_take_fd(pInfo->major, pInfo->minor,
989992
path, &paused);
993+
seatd_libseat_open_device(pInfo,&fd,&paused);
990994
if (fd != -1) {
991995
if (paused) {
992996
/* Put on new_input_devices list for delayed probe */

hw/xfree86/os-support/bsd/bsd_init.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545

4646
#include "os/osdep.h"
4747

48+
#include "seatd-libseat.h"
49+
4850
static Bool KeepTty = FALSE;
4951

5052
#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
@@ -157,6 +159,12 @@ xf86OpenConsole(void)
157159
#endif
158160

159161
if (serverGeneration == 1) {
162+
163+
/* If libseat is in control, it handles VT switching. */
164+
if (seatd_libseat_controls_session()) {
165+
return;
166+
}
167+
160168
/* check if we are run with euid==0 */
161169
if (geteuid() != 0) {
162170
FatalError("xf86OpenConsole: Server must be suid root");

hw/xfree86/os-support/linux/lnx_init.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#include "xf86_os_support.h"
4242
#include "xf86_OSlib.h"
4343

44+
#include "seatd-libseat.h"
45+
46+
4447
#include <sys/stat.h>
4548
#ifdef HAVE_SYS_SYSMACROS_H
4649
#include <sys/sysmacros.h>
@@ -114,7 +117,7 @@ linux_parse_vt_settings(int may_fail)
114117
if (fd < 0) {
115118
if (may_fail)
116119
return 0;
117-
FatalError("parse_vt_settings: Cannot open /dev/tty0 (%s)\n",
120+
FatalError("parse_vt_settings: Cannot open /dev/tty0 (%s), maybe missing for ex. '-seat seat0 -keeptty' parameters? (in case trying to run uid !=0 mode)\n",
118121
strerror(errno));
119122
}
120123

@@ -213,6 +216,11 @@ xf86OpenConsole(void)
213216
i++;
214217
}
215218

219+
220+
/* If libseat is in control, it handles VT switching. */
221+
if (seatd_libseat_controls_session())
222+
return;
223+
216224
if (xf86Info.consoleFd < 0)
217225
FatalError("xf86OpenConsole: Cannot open virtual console"
218226
" %d (%s)\n", xf86Info.vtno, strerror(errno));
@@ -306,7 +314,7 @@ xf86CloseConsole(void)
306314
struct vt_stat vts;
307315
int ret;
308316

309-
if (xf86Info.ShareVTs) {
317+
if (xf86Info.ShareVTs || seatd_libseat_controls_session()) {
310318
close(xf86Info.consoleFd);
311319
return;
312320
}

hw/xfree86/os-support/shared/VTsw_usl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include "xf86_os_support.h"
3535
#include "xf86_OSlib.h"
3636

37+
#include "seatd-libseat.h"
38+
3739
/*
3840
* Handle the VT-switching interface for OSs that use USL-style ioctl()s
3941
* (this used to include the sysv, sco, and linux subdirs, but only linux
@@ -62,6 +64,8 @@ Bool
6264
xf86VTSwitchAway(void)
6365
{
6466
xf86Info.vtRequestsPending = FALSE;
67+
if (seatd_libseat_controls_session())
68+
return TRUE;
6569
if (ioctl(xf86Info.consoleFd, VT_RELDISP, 1) < 0)
6670
return FALSE;
6771
else
@@ -72,6 +76,8 @@ Bool
7276
xf86VTSwitchTo(void)
7377
{
7478
xf86Info.vtRequestsPending = FALSE;
79+
if (seatd_libseat_controls_session())
80+
return TRUE;
7581
if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0)
7682
return FALSE;
7783
else

hw/xfree86/os-support/shared/drm_platform.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,44 @@
2121
#include "xf86Bus.h"
2222

2323
#include "../linux/systemd-logind.h"
24+
#include "seatd-libseat.h"
2425

2526
static Bool
2627
get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
2728
{
2829
drmVersionPtr v;
29-
int fd;
30+
int fd = -1;
3031
int err = 0;
3132
Bool paused = FALSE, server_fd = FALSE;
3233

3334
LogMessage(X_INFO, "Platform probe for %s\n", attribs->syspath);
3435

35-
fd = systemd_logind_take_fd(attribs->major, attribs->minor, path, &paused);
36+
fd = seatd_libseat_open_graphics(path);
3637
if (fd != -1) {
37-
if (paused) {
38-
LogMessage(X_ERROR,
39-
"Error systemd-logind returned paused fd for drm node\n");
40-
systemd_logind_release_fd(attribs->major, attribs->minor, -1);
41-
return FALSE;
42-
}
4338
attribs->fd = fd;
4439
server_fd = TRUE;
40+
} else {
41+
fd = systemd_logind_take_fd(attribs->major, attribs->minor, path, &paused);
42+
if (fd != -1) {
43+
if (paused) {
44+
LogMessage(X_ERROR,
45+
"Error systemd-logind returned paused fd for drm node\n");
46+
systemd_logind_release_fd(attribs->major, attribs->minor, -1);
47+
return FALSE;
48+
}
49+
attribs->fd = fd;
50+
server_fd = TRUE;
51+
}
4552
}
4653

47-
if (fd == -1)
54+
if (fd == -1) {
55+
/* Try opening the path directly */
4856
fd = open(path, O_RDWR | O_CLOEXEC, 0);
49-
50-
if (fd == -1)
51-
return FALSE;
57+
if (fd == -1) {
58+
xf86Msg(X_ERROR, "cannot open %s\n", path);
59+
return FALSE;
60+
}
61+
}
5262

5363
/* for a delayed probe we've already added the device */
5464
if (delayed_index == -1) {

0 commit comments

Comments
 (0)