|
Lines 51-56
Link Here
|
| 51 |
# include <sys/vt.h> |
51 |
# include <sys/vt.h> |
| 52 |
#endif |
52 |
#endif |
| 53 |
|
53 |
|
|
|
54 |
#ifdef WITH_SYSTEMD |
| 55 |
# include <systemd/sd-login.h> |
| 56 |
# include <systemd/sd-daemon.h> |
| 57 |
|
| 58 |
#define SYSTEMD_FAILURE_LIMIT 25 |
| 59 |
|
| 60 |
static int systemdMonitorInit(void); |
| 61 |
static void systemdMonitorDeinit(); |
| 62 |
static int systemdStartDisplay(char *); |
| 63 |
static void systemdCheckAdded(char **); |
| 64 |
static void systemdCheckRemoved(char **); |
| 65 |
static void systemdHandleChange(); |
| 66 |
|
| 67 |
sd_login_monitor *systemdMonitor = NULL; |
| 68 |
int systemdMonitorFd = -1; |
| 69 |
#endif |
| 70 |
|
| 54 |
static void SigHandler( int n ); |
71 |
static void SigHandler( int n ); |
| 55 |
static int ScanConfigs( int force ); |
72 |
static int ScanConfigs( int force ); |
| 56 |
static void StartDisplays( void ); |
73 |
static void StartDisplays( void ); |
|
Lines 277-284
Link Here
|
| 277 |
#ifdef XDMCP |
294 |
#ifdef XDMCP |
| 278 |
UpdateListenSockets(); |
295 |
UpdateListenSockets(); |
| 279 |
#endif |
296 |
#endif |
|
|
297 |
|
| 298 |
#ifdef WITH_SYSTEMD |
| 299 |
if (systemdMonitorInit()) |
| 300 |
systemdHandleChange(); |
| 301 |
#endif |
| 302 |
|
| 280 |
openCtrl( 0 ); |
303 |
openCtrl( 0 ); |
| 281 |
MainLoop(); |
304 |
MainLoop(); |
|
|
305 |
#ifdef WITH_SYSTEMD |
| 306 |
systemdMonitorDeinit(); |
| 307 |
#endif |
| 282 |
closeCtrl( 0 ); |
308 |
closeCtrl( 0 ); |
| 283 |
if (sdRec.how) { |
309 |
if (sdRec.how) { |
| 284 |
commitBootOption(); |
310 |
commitBootOption(); |
|
Lines 1189-1194
Link Here
|
| 1189 |
} |
1215 |
} |
| 1190 |
continue; |
1216 |
continue; |
| 1191 |
} |
1217 |
} |
|
|
1218 |
#ifdef WITH_SYSTEMD |
| 1219 |
if (systemdMonitorFd >= 0 && FD_ISSET(systemdMonitorFd, &reads)) { |
| 1220 |
systemdHandleChange(); |
| 1221 |
sd_login_monitor_flush(systemdMonitor); |
| 1222 |
continue; |
| 1223 |
} |
| 1224 |
#endif |
| 1192 |
#ifdef XDMCP |
1225 |
#ifdef XDMCP |
| 1193 |
if (ProcessListenSockets( &reads )) |
1226 |
if (ProcessListenSockets( &reads )) |
| 1194 |
continue; |
1227 |
continue; |
|
Lines 1213-1218
Link Here
|
| 1213 |
} |
1246 |
} |
| 1214 |
} |
1247 |
} |
| 1215 |
|
1248 |
|
|
|
1249 |
#ifdef WITH_SYSTEMD |
| 1250 |
static int |
| 1251 |
systemdMonitorInit(void) |
| 1252 |
{ |
| 1253 |
if (sd_booted() <= 0) { |
| 1254 |
logError("Didn't boot with systemd, automatic multiseat won't be enabled\n"); |
| 1255 |
return False; |
| 1256 |
} |
| 1257 |
|
| 1258 |
int check = sd_login_monitor_new("seat", &systemdMonitor); |
| 1259 |
if (check < 0) { |
| 1260 |
logError("Can't get systemd monitor: %d, automatic multiseat won't be enabled\n", check); |
| 1261 |
return False; |
| 1262 |
} |
| 1263 |
|
| 1264 |
systemdMonitorFd = sd_login_monitor_get_fd(systemdMonitor); |
| 1265 |
if (systemdMonitorFd < 0) { |
| 1266 |
logError("Can't retrieve file descriptor from the systemd monitor: %d, automatic multiseat won't be enabled\n", systemdMonitorFd); |
| 1267 |
sd_login_monitor_unref(systemdMonitor); |
| 1268 |
systemdMonitorFd = -1; |
| 1269 |
return False; |
| 1270 |
} |
| 1271 |
|
| 1272 |
registerInput(systemdMonitorFd); |
| 1273 |
return True; |
| 1274 |
} |
| 1275 |
|
| 1276 |
static void |
| 1277 |
systemdMonitorDeinit(void) |
| 1278 |
{ |
| 1279 |
if (systemdMonitor) { |
| 1280 |
sd_login_monitor_unref(systemdMonitor); |
| 1281 |
} |
| 1282 |
systemdMonitorFd = -1; |
| 1283 |
} |
| 1284 |
|
| 1285 |
static int |
| 1286 |
systemdStartDisplay(char *seat) |
| 1287 |
{ |
| 1288 |
struct display *link = NULL; |
| 1289 |
for (link = displays; link; link = link-> next) { |
| 1290 |
if (link->status == reserve) |
| 1291 |
break; |
| 1292 |
} |
| 1293 |
if (!link) { |
| 1294 |
logError("There's not enough reserve displays for all your seats/sessions"); |
| 1295 |
return False; |
| 1296 |
} |
| 1297 |
if (!strDup((&link->systemdSeat), seat)) { |
| 1298 |
return False; |
| 1299 |
} |
| 1300 |
#ifdef HAVE_VTS |
| 1301 |
link->serverVT = 0; |
| 1302 |
#endif |
| 1303 |
link->status = notRunning; |
| 1304 |
link->stillThere = True; |
| 1305 |
link->authorize = True; |
| 1306 |
link->displayType = dLocal | dPermanent; |
| 1307 |
link->reqSrvVT = -1; |
| 1308 |
link->serverPid = -1; |
| 1309 |
return True; |
| 1310 |
} |
| 1311 |
|
| 1312 |
static void |
| 1313 |
systemdCheckAdded(char **seat_names) |
| 1314 |
{ |
| 1315 |
char **iter_name; |
| 1316 |
struct display *link; |
| 1317 |
for (iter_name = seat_names; *iter_name; iter_name++) { |
| 1318 |
if (strcmp(*iter_name, "seat0") == 0) |
| 1319 |
continue; /* ignore the main seat */ |
| 1320 |
int can_graphical = sd_seat_can_graphical(*iter_name); |
| 1321 |
for (link = displays; link; link = link->next) { |
| 1322 |
if (!link->systemdSeat) |
| 1323 |
continue; |
| 1324 |
/* see if the can_graphical property didn't change */ |
| 1325 |
if (0 == strcmp(*iter_name, link->systemdSeat)) { |
| 1326 |
if (!can_graphical) { |
| 1327 |
free(link->systemdSeat); |
| 1328 |
link->systemdSeat = NULL; |
| 1329 |
rStopDisplay(link, DS_RESERVE); |
| 1330 |
} |
| 1331 |
break; |
| 1332 |
} |
| 1333 |
} |
| 1334 |
/* the display wasn't found */ |
| 1335 |
if (!link) { |
| 1336 |
if (can_graphical) { |
| 1337 |
/* if starting the display failed, skip this round until the next change */ |
| 1338 |
if (!systemdStartDisplay(*iter_name)) |
| 1339 |
break; |
| 1340 |
} |
| 1341 |
} |
| 1342 |
} |
| 1343 |
} |
| 1344 |
|
| 1345 |
static void |
| 1346 |
systemdCheckRemoved(char **seat_names) |
| 1347 |
{ |
| 1348 |
char **iter_name; |
| 1349 |
struct display *link; |
| 1350 |
for (link = displays; link; link = link->next) { |
| 1351 |
for (iter_name = seat_names; *iter_name; iter_name++) { |
| 1352 |
if (strcmp(*iter_name, "seat0") == 0) |
| 1353 |
continue; /* ignore the main seat */ |
| 1354 |
if (link->systemdSeat && strcmp(*iter_name, link->systemdSeat) == 0) |
| 1355 |
break; |
| 1356 |
} |
| 1357 |
if (!(*iter_name) && link->systemdSeat) { /* was not found, stop this one */ |
| 1358 |
free(link->systemdSeat); |
| 1359 |
link->systemdSeat = NULL; |
| 1360 |
rStopDisplay(link, DS_RESERVE); |
| 1361 |
} |
| 1362 |
} |
| 1363 |
} |
| 1364 |
|
| 1365 |
static void |
| 1366 |
systemdHandleChange(void) |
| 1367 |
{ |
| 1368 |
static int failures = 0; |
| 1369 |
char **seat_names; |
| 1370 |
char **iter_name; |
| 1371 |
int check; |
| 1372 |
if ((check = sd_get_seats(&seat_names)) < 0) { |
| 1373 |
logError("Can't obtain systemd seats, error %d\n", -check); |
| 1374 |
failures++; |
| 1375 |
if (failures >= SYSTEMD_FAILURE_LIMIT) { |
| 1376 |
logError("%u failed calls to sd_get_seats, disabling systemd multi-seat support\n", SYSTEMD_FAILURE_LIMIT); |
| 1377 |
systemdMonitorDeinit(); |
| 1378 |
} |
| 1379 |
return; |
| 1380 |
} |
| 1381 |
|
| 1382 |
if (!check) |
| 1383 |
return; |
| 1384 |
|
| 1385 |
systemdCheckAdded(seat_names); |
| 1386 |
systemdCheckRemoved(seat_names); |
| 1387 |
|
| 1388 |
for (iter_name = seat_names; *iter_name; iter_name++) |
| 1389 |
free(*iter_name); |
| 1390 |
free(seat_names); |
| 1391 |
} |
| 1392 |
#endif WITH_SYSTEMD |
| 1393 |
|
| 1216 |
static void |
1394 |
static void |
| 1217 |
CheckDisplayStatus( struct display *d ) |
1395 |
CheckDisplayStatus( struct display *d ) |
| 1218 |
{ |
1396 |
{ |