Commit 260cf583 authored by 1's avatar 1 Committed by Martin Peterson

Fixes.



1999-12-31    <mkp@mkp.net>

	* daemon/server.c: Fixes.
parent 70627944
1999-12-31 <mkp@mkp.net>
* daemon/server.c: Fixes.
1999-12-29 <mkp@mkp.net>
* Checkin of my devel tree. Some of the new stuff is in. Mostly
......
......@@ -31,6 +31,7 @@
#include "gdm.h"
#include "misc.h"
#include "slave.h"
#include "server.h"
#include "xdmcp.h"
#include "verify.h"
#include "display.h"
......@@ -403,7 +404,7 @@ gdm_child_handler (gint sig)
if (d->type == TYPE_LOCAL && d->dispstat != DISPLAY_ABORT) {
d->dispstat = DISPLAY_DEAD;
gdm_server_start (d);
gdm_slave_start (d);
}
if (d->type == TYPE_XDMCP)
......
......@@ -32,33 +32,31 @@
#include <X11/Xlib.h>
#include "gdm.h"
#include "server.h"
#include "misc.h"
#include "xdmcp.h"
#include "display.h"
#include "auth.h"
static const gchar RCSid[]="$Id$";
extern gchar *argdelim;
extern gchar *GdmDisplayInit;
extern gchar *GdmServAuthDir;
extern gchar *GdmLogDir;
extern gint GdmXdmcp;
extern gboolean gdm_auth_secure_display (GdmDisplay *);
extern void gdm_debug (const gchar *, ...);
extern void gdm_error (const gchar *, ...);
extern gint gdm_display_manage (GdmDisplay *);
extern void gdm_xdmcp_close();
extern gint gdm_setenv (gchar *var, gchar *value);
gboolean gdm_server_start (GdmDisplay *d);
void gdm_server_stop (GdmDisplay *d);
/* Local prototypes */
void gdm_server_spawn (GdmDisplay *d);
void gdm_server_usr1_handler (gint);
void gdm_server_alarm_handler (gint);
void gdm_server_child_handler (gint);
GdmDisplay *gdm_server_alloc (gint id, gchar *command);
/* Configuration options */
extern gchar *argdelim;
extern gchar *GdmDisplayInit;
extern gchar *GdmServAuthDir;
extern gchar *GdmLogDir;
extern gint GdmXdmcp;
extern sigset_t sysmask;
/* Global vars */
GdmDisplay *d;
sigset_t mask, omask;
/**
......@@ -71,8 +69,8 @@ sigset_t mask, omask;
gboolean
gdm_server_start (GdmDisplay *disp)
{
struct sigaction usr1, chld, oldchld, alrm;
sigset_t mask, omask;
struct sigaction usr1, chld, alrm;
sigset_t mask;
if (!disp)
return FALSE;
......@@ -95,32 +93,37 @@ gdm_server_start (GdmDisplay *disp)
gdm_error (_("gdm_server_start: Error setting up USR1 signal handler"));
return FALSE;
}
/* Catch CHLD from X server */
chld.sa_handler = gdm_server_child_handler;
chld.sa_flags = SA_RESTART|SA_RESETHAND;
sigemptyset (&chld.sa_mask);
/* Set signal mask */
sigemptyset (&mask);
sigaddset (&mask, SIGUSR1);
sigprocmask (SIG_UNBLOCK, &mask, &omask);
if (sigaction (SIGCHLD, &chld, NULL) < 0) {
gdm_error (_("gdm_server_start: Error setting up CHLD signal handler"));
return FALSE;
}
/* Catch ALRM from X server */
alrm.sa_handler = gdm_server_alarm_handler;
alrm.sa_flags = SA_RESTART|SA_RESETHAND;
sigemptyset (&alrm.sa_mask);
/* Is the old server (if any) still alive */
if (d->servpid && kill (d->servpid, 0) == 0) {
/* Reset X and force auth file reread. XCloseDisplay works on most
* servers but just like young Zaphod, we play it safe */
gdm_debug ("gdm_server_start: HUP'ing servpid=%d", d->servpid);
kill (d->servpid, SIGHUP);
d->servstat = SERVER_STARTED;
if (sigaction (SIGALRM, &alrm, NULL) < 0) {
gdm_error (_("gdm_server_start: Error setting up ALRM signal handler"));
return FALSE;
}
else /* No server running */
gdm_server_spawn (d);
/* Set signal mask */
sigemptyset (&mask);
sigaddset (&mask, SIGUSR1);
sigaddset (&mask, SIGCHLD);
sigaddset (&mask, SIGALRM);
sigprocmask (SIG_UNBLOCK, &mask, &omask);
sigprocmask (SIG_UNBLOCK, &mask, NULL);
/* fork X server process */
gdm_server_spawn (d);
/* Wait for X server to send ready signal */
while (d->servtries < 5) {
pause();
......@@ -130,11 +133,9 @@ gdm_server_start (GdmDisplay *disp)
case SERVER_TIMEOUT:
/* Unset alarm and try again */
alarm (0);
sigprocmask (SIG_SETMASK, &omask, NULL);
waitpid (d->servpid, 0, WNOHANG);
gdm_debug ("gdm_server_alarm_handler: Temporary server failure");
gdm_debug ("gdm_server_start: Temporary server failure (%d)", d->name);
gdm_server_spawn (d);
break;
......@@ -142,12 +143,18 @@ gdm_server_start (GdmDisplay *disp)
case SERVER_RUNNING:
/* Unset alarm */
alarm (0);
sigprocmask (SIG_SETMASK, &omask, NULL);
gdm_debug ("gdm_server_run_session: Starting display %s!", d->name);
gdm_debug ("gdm_server_start: Completed %s!", d->name);
return TRUE;
case SERVER_ABORT:
alarm (0);
gdm_debug ("gdm_server_start: Server %s died during startup!", d->name);
sigprocmask (SIG_SETMASK, &sysmask, NULL);
return FALSE;
default:
break;
}
......@@ -157,10 +164,17 @@ gdm_server_start (GdmDisplay *disp)
}
/**
* gdm_server_spawn:
* @disp: Pointer to a GdmDisplay structure
*
* forks an actual X server process
*/
void
gdm_server_spawn (GdmDisplay *d)
{
struct sigaction usr1, sigalarm, chld, ochld;
struct sigaction usr1;
gchar *srvcmd = NULL;
gchar **argv = NULL;
int logfd;
......@@ -170,20 +184,6 @@ gdm_server_spawn (GdmDisplay *d)
d->servstat = SERVER_STARTED;
/* Catch CHLD from X server */
chld.sa_handler = gdm_server_child_handler;
chld.sa_flags = 0;
sigemptyset (&chld.sa_mask);
if (sigaction (SIGCHLD, &chld, &ochld) < 0) {
gdm_error (_("gdm_server_start: Error setting up CHLD signal handler"));
return;
}
/* If the old server is still alive, kill it */
if (d->servpid && kill (d->servpid, 0) == 0)
gdm_server_stop (d);
/* Log all output from spawned programs to a file */
logfd = open (g_strconcat (GdmLogDir, "/", d->name, ".log", NULL),
O_CREAT|O_TRUNC|O_APPEND|O_WRONLY, 0666);
......@@ -250,6 +250,13 @@ gdm_server_spawn (GdmDisplay *d)
}
/**
* gdm_server_stop:
* @disp: Pointer to a GdmDisplay structure
*
* Stops a local X server
*/
void
gdm_server_stop (GdmDisplay *d)
{
......@@ -265,6 +272,13 @@ gdm_server_stop (GdmDisplay *d)
}
/**
* gdm_server_usr1_handler:
* @sig: Signal value
*
* Received when the server is ready to accept connections
*/
void
gdm_server_usr1_handler (gint sig)
{
......@@ -272,6 +286,13 @@ gdm_server_usr1_handler (gint sig)
}
/**
* gdm_server_alarm_handler:
* @sig: Signal value
*
* Server start timeout handler
*/
void
gdm_server_alarm_handler (gint signal)
{
......@@ -279,6 +300,13 @@ gdm_server_alarm_handler (gint signal)
}
/**
* gdm_server_child_handler:
* @sig: Signal value
*
* Received when server died during startup
*/
void
gdm_server_child_handler (gint signal)
{
......@@ -286,6 +314,14 @@ gdm_server_child_handler (gint signal)
}
/**
* gdm_server_alloc:
* @id: Local display number
* @command: Command line for starting the X server
*
* Allocate display structure for a local X server
*/
GdmDisplay *
gdm_server_alloc (gint id, gchar *command)
{
......
/* GDM - The Gnome Display Manager
* Copyright (C) 1998, 1999, 2000 Martin K. Petersen <mkp@mkp.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef GDM_SERVER_H
#define GDM_SERVER_H
#include "gdm.h"
gboolean gdm_server_start (GdmDisplay *d);
void gdm_server_stop (GdmDisplay *d);
GdmDisplay *gdm_server_alloc (gint id, gchar *command);
#endif /* GDM_SERVER_H */
/* EOF */
......@@ -41,6 +41,7 @@
#include "verify.h"
#include "filecheck.h"
#include "auth.h"
#include "server.h"
static const gchar RCSid[]="$Id$";
......@@ -100,6 +101,9 @@ gdm_slave_start (GdmDisplay *display)
gdm_debug ("gdm_slave_start: Starting slave process for %s", display->name);
d = display;
if (d->type == TYPE_LOCAL)
gdm_server_start (d);
gdm_setenv ("XAUTHORITY", d->authfile);
gdm_setenv ("DISPLAY", d->name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment