Remove the displayType member of struct display.

xenodm only manages Local Permanent FromFile X servers.
No need to keep the checks for that.
For now the Xservers file keeps the location field, but ignores its
This commit is contained in:
matthieu 2016-11-06 09:17:47 +00:00
parent 1d7833af8c
commit 1a2fd595f2
5 changed files with 55 additions and 131 deletions

View File

@ -54,7 +54,6 @@ from The Open Group.
# include <time.h>
# define Time_t time_t
# include <X11/Xdmcp.h>
@ -80,33 +79,6 @@ typedef int waitType;
typedef enum displayStatus { running, notRunning, zombie, phoenix } DisplayStatus;
/*
* local - server runs on local host
* foreign - server runs on remote host -- unsupported in xenodm
* permanent - session restarted when it exits
* transient - session not restarted when it exits
* fromFile - started via entry in servers file
* fromXDMCP - started with XDMCP
*/
typedef struct displayType {
unsigned int location:1;
unsigned int lifetime:1;
unsigned int origin:1;
} DisplayType;
# define Local 1
# define Foreign 0
# define Permanent 1
# define Transient 0
# define FromFile 1
# define FromXDMCP 0 /* unsupported in xenodm */
extern DisplayType parseDisplayType (char *string, int *usedDefault);
typedef enum fileState { NewEntry, OldEntry, MissingEntry } FileState;
struct display {
@ -114,7 +86,6 @@ struct display {
/* Xservers file / XDMCP information */
char *name; /* DISPLAY name */
char *class; /* display class (may be NULL) */
DisplayType displayType; /* method to handle with */
char **argv; /* program name and arguments */
/* display state */
@ -274,7 +245,7 @@ extern void ForEachDisplay (void (*f)(struct display *));
extern void RemoveDisplay (struct display *old);
/* in file.c */
extern void ParseDisplay (char *source, DisplayType *acceptableTypes, int numAcceptable);
extern void ParseDisplay (char *source);
/* in netaddr.c */
extern char *NetaddrAddress(XdmcpNetaddr netaddrp, int *lenp);

View File

@ -867,8 +867,7 @@ SetUserAuthorization (struct display *d, struct verify_info *verify)
!strncmp (auths[i]->name, "MIT-MAGIC-COOKIE-1", 18))
{
magicCookie = i;
if (d->displayType.location == Local)
writeLocalAuth (new, auths[i], d->name);
writeLocalAuth (new, auths[i], d->name);
break;
}
}
@ -885,8 +884,7 @@ SetUserAuthorization (struct display *d, struct verify_info *verify)
if (auths[i]->name_length == 14 &&
!strncmp (auths[i]->name, "MIT-KERBEROS-5", 14))
auths[i]->data_length = 0;
if (d->displayType.location == Local)
writeLocalAuth (new, auths[i], d->name);
writeLocalAuth (new, auths[i], d->name);
auths[i]->data_length = data_len;
}
}
@ -966,10 +964,7 @@ RemoveUserAuthorization (struct display *d, struct verify_info *verify)
initAddrs ();
doWrite = 0;
for (i = 0; i < d->authNum; i++)
{
if (d->displayType.location == Local)
writeLocalAuth (new, auths[i], d->name);
}
writeLocalAuth (new, auths[i], d->name);
doWrite = 1;
if (old) {
if (fstat (fileno (old), &statb) != -1)

View File

@ -156,11 +156,6 @@ ScanServers (void)
int len;
FILE *serversFile;
struct stat statb;
static DisplayType acceptableTypes[] =
{ { Local, Permanent, FromFile },
};
#define NumTypes (sizeof (acceptableTypes) / sizeof (acceptableTypes[0]))
if (servers[0] == '/')
{
@ -180,13 +175,13 @@ ScanServers (void)
len = strlen (lineBuf);
if (lineBuf[len-1] == '\n')
lineBuf[len-1] = '\0';
ParseDisplay (lineBuf, acceptableTypes, NumTypes);
ParseDisplay (lineBuf);
}
fclose (serversFile);
}
else
{
ParseDisplay (servers, acceptableTypes, NumTypes);
ParseDisplay (servers);
}
}
@ -331,8 +326,7 @@ WaitForChild (void)
d->startTries = 0;
d->reservTries = 0;
Debug ("Display exited with OBEYSESS_DISPLAY\n");
if (d->displayType.lifetime != Permanent ||
d->status == zombie)
if (d->status == zombie)
StopDisplay (d);
else
RestartDisplay (d, FALSE);
@ -345,8 +339,7 @@ WaitForChild (void)
* no display connection was ever made, tell the
* terminal that the open attempt failed
*/
if (d->displayType.origin == FromXDMCP ||
d->status == zombie ||
if (d->status == zombie ||
++d->startTries >= d->startAttempts)
{
LogError ("Display %s is being disabled\n", d->name);
@ -360,7 +353,7 @@ WaitForChild (void)
case RESERVER_DISPLAY:
d->startTries = 0;
Debug ("Display exited with RESERVER_DISPLAY\n");
if (d->displayType.origin == FromXDMCP || d->status == zombie)
if (d->status == zombie)
StopDisplay(d);
else {
Time_t now;
@ -404,8 +397,7 @@ WaitForChild (void)
case waitCompose (SIGTERM,0,0):
Debug ("Display exited on SIGTERM, try %d of %d\n",
d->startTries, d->startAttempts);
if (d->displayType.origin == FromXDMCP ||
d->status == zombie ||
if (d->status == zombie ||
++d->startTries >= d->startAttempts)
{
/*
@ -428,7 +420,7 @@ WaitForChild (void)
* XDMCP will restart the session if the display
* requests it
*/
if (d->displayType.origin == FromXDMCP || d->status == zombie)
if (d->status == zombie)
StopDisplay(d);
else
RestartDisplay (d, FALSE);
@ -480,19 +472,16 @@ WaitForChild (void)
static void
CheckDisplayStatus (struct display *d)
{
if (d->displayType.origin == FromFile)
{
switch (d->state) {
case MissingEntry:
StopDisplay (d);
break;
case NewEntry:
d->state = OldEntry;
case OldEntry:
if (d->status == notRunning)
StartDisplay (d);
break;
}
switch (d->state) {
case MissingEntry:
StopDisplay (d);
break;
case NewEntry:
d->state = OldEntry;
case OldEntry:
if (d->status == notRunning)
StartDisplay (d);
break;
}
}
@ -576,28 +565,25 @@ StartDisplay (struct display *d)
Debug ("StartDisplay %s\n", d->name);
LogInfo ("Starting X server on %s\n", d->name);
LoadServerResources (d);
if (d->displayType.location == Local)
if (d->authorize)
{
if (d->authorize)
{
Debug ("SetLocalAuthorization %s, auth %s\n",
d->name, d->authNames[0]);
SetLocalAuthorization (d);
/*
* reset the server after writing the authorization information
* to make it read the file (for compatibility with old
* servers which read auth file only on reset instead of
* at first connection)
*/
if (d->serverPid != -1 && d->resetForAuth && d->resetSignal)
kill (d->serverPid, d->resetSignal);
}
if (d->serverPid == -1 && !StartServer (d))
{
LogError ("Server for display %s can't be started, session disabled\n", d->name);
RemoveDisplay (d);
return;
}
Debug ("SetLocalAuthorization %s, auth %s\n",
d->name, d->authNames[0]);
SetLocalAuthorization (d);
/*
* reset the server after writing the authorization information
* to make it read the file (for compatibility with old
* servers which read auth file only on reset instead of
* at first connection)
*/
if (d->serverPid != -1 && d->resetForAuth && d->resetSignal)
kill (d->serverPid, d->resetSignal);
}
if (d->serverPid == -1 && !StartServer (d))
{
LogError ("Server for display %s can't be started, session disabled\n", d->name);
RemoveDisplay (d);
return;
}
if (!nofork_session)
pid = fork ();

View File

@ -38,13 +38,6 @@ from The Open Group.
#include <ctype.h>
static int
DisplayTypeMatch (DisplayType d1, DisplayType d2)
{
return d1.location == d2.location &&
d1.lifetime == d2.lifetime &&
d1.origin == d2.origin;
}
static void
freeFileArgs (char **args)
@ -135,14 +128,24 @@ freeSomeArgs (char **args, int n)
free (args);
}
static int
parseDisplayType (char *string)
{
if (strcmp(string, "local") == 0)
return 0;
else
return 1;
}
void
ParseDisplay (char *source, DisplayType *acceptableTypes, int numAcceptable)
ParseDisplay (char *source)
{
char **args, **argv, **a;
char *name, *class, *type;
struct display *d;
int usedDefault;
DisplayType displayType;
Boolean local;
args = splitIntoWords (source);
if (!args)
@ -160,7 +163,7 @@ ParseDisplay (char *source, DisplayType *acceptableTypes, int numAcceptable)
freeFileArgs (args);
return;
}
displayType = parseDisplayType (args[1], &usedDefault);
usedDefault = parseDisplayType(args[1]);
class = NULL;
type = args[1];
argv = args + 2;
@ -172,7 +175,7 @@ ParseDisplay (char *source, DisplayType *acceptableTypes, int numAcceptable)
*/
if (usedDefault && args[2])
{
displayType = parseDisplayType (args[2], &usedDefault);
usedDefault = parseDisplayType (args[2]);
if (!usedDefault)
{
class = args[1];
@ -180,14 +183,7 @@ ParseDisplay (char *source, DisplayType *acceptableTypes, int numAcceptable)
argv = args + 3;
}
}
while (numAcceptable)
{
if (DisplayTypeMatch (*acceptableTypes, displayType))
break;
--numAcceptable;
++acceptableTypes;
}
if (!numAcceptable)
if (!local)
{
LogError ("Unacceptable display type %s for display %s\n",
type, name);
@ -216,33 +212,9 @@ ParseDisplay (char *source, DisplayType *acceptableTypes, int numAcceptable)
Debug ("Found new display: %s %s %s",
d->name, d->class ? d->class : "", type);
}
d->displayType = displayType;
d->argv = copyArgs (argv);
for (a = d->argv; a && *a; a++)
Debug (" %s", *a);
Debug ("\n");
freeSomeArgs (args, argv - args);
}
static struct displayMatch {
const char *name;
DisplayType type;
} displayTypes[] = {
{ "local", { Local, Permanent, FromFile } },
{ NULL, { Local, Permanent, FromFile } },
};
DisplayType
parseDisplayType (char *string, int *usedDefault)
{
struct displayMatch *d;
for (d = displayTypes; d->name; d++)
if (!strcmp (d->name, string))
{
*usedDefault = 0;
return d->type;
}
*usedDefault = 1;
return d->type;
}

View File

@ -233,7 +233,7 @@ WaitForServer (struct display *d)
void
ResetServer (struct display *d)
{
if (d->dpy && d->displayType.origin != FromXDMCP)
if (d->dpy)
pseudoReset (d->dpy);
}