[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[E-devel] [ENTRANCE] [PATCH] Entranced_Display patch



Hiya all,

A patch here for your review.

This patch extracts out the Entranced_Display subsystem out out spawner.c, with this done, its easier to see what's happening in spawner.c, my end target is to eventually rename spawner.c as main.c so its clear that its the starting point for the code.

No major changes, just shifting code around.

I'll pretend to be a UNIX shell utility and If no one *exits noisily* on the patch, I'll assume they're ok, and check them in :P



Cheers,
Essien




diff -Naur entrance/src/daemon/Entranced.h entrance.edit/src/daemon/Entranced.h
--- entrance/src/daemon/Entranced.h	2006-06-03 07:36:16.000000000 +0100
+++ entrance.edit/src/daemon/Entranced.h	2006-07-30 19:43:48.000000000 +0100
@@ -41,36 +41,11 @@
    unsigned char connected;
 } Entranced_Client;
 
-typedef struct _Entranced_Display
-{
-   Display     *display;
-   int         dispnum;         /* FIXME */
-   char        *name;           /* the name of the x display */
-   char        *xprog;          /* the X execution string */
-   int         attempts;
-   int         status;
-   int         auth_en;         /* Enable XAuth access control */
-   pid_t       pid;
-   Ecore_List  *auths;
-   char        *authfile;
-   char        *hostname;
-   
-   char        *config;         /* Config file for greeter */
-   Ecore_Exe   *e_exe;          /* Exe handle for Entrance session */
-   Ecore_Exe   *x_exe;          /* Exe handle for X server */
-
-   Entranced_Client client;
-} Entranced_Display;
 
 /* Functions */
 int Entranced_Write_Pidfile (pid_t pid);
 void Entranced_Fork_And_Exit(void);
-Entranced_Display *Entranced_Display_New(void);
-void Entranced_Spawn_X(Entranced_Display *d);
-pid_t Entranced_Start_Server_Once(Entranced_Display *d);
-int Entranced_X_Restart(Entranced_Display *d);
 void Entranced_X_Killall();
-void Entranced_Spawn_Entrance(Entranced_Display *d);
 int Entranced_Respawn_Reset(void *data);
 int Entranced_Exe_Exited(void *data, int type, void *event);
 int Entranced_Signal_Exit(void *data, int type, void *event);
diff -Naur entrance/src/daemon/Entranced_Display.h entrance.edit/src/daemon/Entranced_Display.h
--- entrance/src/daemon/Entranced_Display.h	1970-01-01 01:00:00.000000000 +0100
+++ entrance.edit/src/daemon/Entranced_Display.h	2006-07-30 20:06:37.000000000 +0100
@@ -0,0 +1,34 @@
+#ifndef __ENTRANCED_DISPLAY_H
+#define __ENTRANCED_DISPLAY_H
+/*TODO: also make Entrance_Edit.h be __ENTRANCE_EDIT_H*/
+
+typedef struct _Entranced_Display
+{
+   Display     *display;
+   int         dispnum;         /* FIXME */
+   char        *name;           /* the name of the x display */
+   char        *xprog;          /* the X execution string */
+   int         attempts;
+   int         status;
+   int         auth_en;         /* Enable XAuth access control */
+   pid_t       pid;
+   Ecore_List  *auths;
+   char        *authfile;
+   char        *hostname;
+   
+   char        *config;         /* Config file for greeter */
+   Ecore_Exe   *e_exe;          /* Exe handle for Entrance session */
+   Ecore_Exe   *x_exe;          /* Exe handle for X server */
+
+   Entranced_Client client;
+} Entranced_Display;
+
+
+Entranced_Display* Entranced_Display_New(void);
+void Entranced_Display_Spawn_X(Entranced_Display *);
+pid_t Entranced_Display_Start_Server_Once(Entranced_Display *);
+void Entranced_Display_Spawn_Entrance(Entranced_Display *);
+int Entranced_Display_X_Restart(Entranced_Display *);
+void Entranced_Display_XReady_Set(unsigned char i);
+
+#endif
diff -Naur entrance/src/daemon/Makefile.am entrance.edit/src/daemon/Makefile.am
--- entrance/src/daemon/Makefile.am	2006-07-22 10:25:44.000000000 +0100
+++ entrance.edit/src/daemon/Makefile.am	2006-07-30 19:45:35.000000000 +0100
@@ -11,7 +11,13 @@
 lib_LTLIBRARIES=libentrance_edit.la
 
 entranced_SOURCES = \
-	auth.c auth.h Entranced.h ipc.c ipc.h md5.c md5.h spawner.c util.c util.h
+	Entranced.h \
+	auth.c auth.h \
+	ipc.c ipc.h \
+	md5.c md5.h \
+	util.c util.h \
+	spawner.c \
+	Entranced_Display.h entranced_display.c
 
 entranced_LDADD = @X_LIBS@ -lXau @ECORE_LIBS@
 
diff -Naur entrance/src/daemon/auth.h entrance.edit/src/daemon/auth.h
--- entrance/src/daemon/auth.h	2005-11-07 19:41:11.000000000 +0100
+++ entrance.edit/src/daemon/auth.h	2006-07-30 20:01:49.000000000 +0100
@@ -2,6 +2,7 @@
 #define __ENTRANCED_AUTH_H
 
 #include <Entranced.h>
+#include <Entranced_Display.h>
 #include <X11/Xauth.h>
 #include <X11/Xos.h>
 
diff -Naur entrance/src/daemon/entrance_edit.c entrance.edit/src/daemon/entrance_edit.c
--- entrance/src/daemon/entrance_edit.c	2006-07-27 23:04:34.000000000 +0100
+++ entrance.edit/src/daemon/entrance_edit.c	2006-07-30 20:11:58.000000000 +0100
@@ -88,6 +88,8 @@
 		   return 1;
 		}
 	}
+
+	return 0;
 }
 
 void 
diff -Naur entrance/src/daemon/entranced_display.c entrance.edit/src/daemon/entranced_display.c
--- entrance/src/daemon/entranced_display.c	1970-01-01 01:00:00.000000000 +0100
+++ entrance.edit/src/daemon/entranced_display.c	2006-07-30 20:10:59.000000000 +0100
@@ -0,0 +1,188 @@
+#include <Ecore_Config.h>
+#include "Entranced.h"
+#include "Entranced_Display.h"
+#include "auth.h"
+#include "util.h"
+
+
+static unsigned char x_ready = 0;
+static struct sigaction _entrance_x_sa;
+
+void 
+Entranced_Display_XReady_Set(unsigned char i)
+{
+	x_ready = i;
+}
+
+
+/**
+ * Create a new display context.
+ * @return A pointer to an Entranced_Display handle for the new context
+ */
+Entranced_Display *
+Entranced_Display_New(void)
+{
+   Entranced_Display *d;
+
+   d = calloc(1, sizeof(Entranced_Display));
+
+   ecore_config_string_default("/entranced/xserver", DEFAULT_X_SERVER);
+   ecore_config_int_default("/entranced/attempts", 5);
+
+   ecore_config_file_load(PACKAGE_CFG_DIR "/entrance_config.cfg");
+
+   d->xprog = ecore_config_string_get("/entranced/xserver");
+   d->attempts = ecore_config_int_get("/entranced/attempts");
+
+   d->status = NOT_RUNNING;
+   d->auth_en = 1;
+   d->auths = ecore_list_new();
+   d->client.uid = -1;
+   d->client.gid = -1;
+   return d;
+}
+
+/**
+ * Launch a new X server
+ * @param d The spawner display context that will handle this server
+ */
+void
+Entranced_Display_Spawn_X(Entranced_Display * d)
+{
+   int i = 0;
+
+   if (d == NULL)
+      return;
+
+   d->status = NOT_RUNNING;
+   while ((i < d->attempts) && (d->status != RUNNING))
+   {
+      if ((d->pid = Entranced_Display_Start_Server_Once(d)) > 0)
+         break;
+      ++i;
+   }
+}
+
+/**
+ * Single attempt to start the X Server.
+ * @param d The spawner display context that will handle this server
+ * @return The status of the display context after the launch attempt
+ */
+pid_t
+Entranced_Display_Start_Server_Once(Entranced_Display * d)
+{
+   double start_time;
+   char x_cmd[PATH_MAX];
+
+   /* Ecore_Exe *x_exe; */
+   pid_t xpid;
+
+   d->status = LAUNCHING;
+
+   x_ready = 0;
+
+   /* Create server auth cookie */
+
+   if(d->auth_en)
+   {
+      if (!entranced_auth_display_secure(d))
+      {
+         syslog(LOG_CRIT, "Failed to generate auth cookie for X Server.");
+         return -1;
+      }
+   
+      snprintf(x_cmd, PATH_MAX, "%s -auth %s %s", d->xprog, d->authfile, d->name);
+   }
+   else
+   {
+      snprintf(x_cmd, PATH_MAX, "%s %s", d->xprog, d->name);
+   }
+   entranced_debug("Entranced_Start_Server_Once: Executing %s\n", x_cmd);
+
+   /* x_exe = ecore_exe_run(d->xprog, d); */
+   switch (xpid = fork())
+   {
+     case -1:
+        syslog(LOG_WARNING, "fork() to start X server failed.");
+        return -1;
+     case 0:
+        _entrance_x_sa.sa_handler = SIG_IGN;
+        _entrance_x_sa.sa_flags = 0;
+        sigemptyset(&_entrance_x_sa.sa_mask);
+        sigaction(SIGUSR1, &_entrance_x_sa, NULL);
+      /* FIXME: need to parse command and NOT go thru /bin/sh!!!! */
+      /* why? some /bin/sh's wont pass on this SIGUSR1 thing... */
+        execl("/bin/sh", "/bin/sh", "-c", x_cmd, NULL);
+        syslog(LOG_WARNING, "Could not execute X server.");
+        exit(1);
+     default:
+        start_time = ecore_time_get();
+
+        while (!x_ready)
+        {
+           double current_time;
+
+           usleep(100000);
+           current_time = ecore_time_get();
+           if ((current_time - start_time) > 5.0)
+	     break;
+        }
+
+        if (!x_ready)
+        {
+           entranced_debug("Entranced_Start_Server_Once: Attempt to start X server failed.\n");
+           d->status = NOT_RUNNING;
+        }
+        else
+           d->status = RUNNING;
+
+        return xpid;
+   }
+}
+
+/**
+ * Start a new Entrance session
+ * @param d The spawner display context that this session will use
+ */
+void
+Entranced_Display_Spawn_Entrance(Entranced_Display *d)
+{
+   char entrance_cmd[PATH_MAX];
+
+   d->client.pid = 0;
+   d->client.uid = -1;
+   d->client.gid = -1;
+   if (d->client.homedir)
+      free(d->client.homedir);
+   d->client.homedir = NULL;
+
+   snprintf(entrance_cmd, PATH_MAX, "%s -d %s", ENTRANCE, d->name);
+   if (d->config)
+      snprintf(entrance_cmd, PATH_MAX, "%s -d %s -c \"%s\" -z %d", 
+               ENTRANCE, d->name, d->config, getpid());
+   else
+      snprintf(entrance_cmd, PATH_MAX, "%s -d %s -z %d", ENTRANCE, d->name,
+                                                         getpid());
+   printf("Starting command: %s\n", entrance_cmd);
+   d->e_exe = ecore_exe_run(entrance_cmd, d);
+   d->client.pid = ecore_exe_pid_get(d->e_exe);
+}
+
+int
+Entranced_Display_X_Restart(Entranced_Display * d)
+{
+   /* Attempt to restart X server */
+   d->status = NOT_RUNNING;
+
+   syslog(LOG_INFO, "Attempting to restart X server.");
+   Entranced_Display_Spawn_X(d);
+   if (d->status != RUNNING)
+   {
+      syslog(LOG_CRIT, "Failed to restart the X server. Aborting.");
+      return 0;
+   }
+   else
+      syslog(LOG_INFO, "Successfully restarted the X server.");
+   return 1;
+}
+
diff -Naur entrance/src/daemon/ipc.h entrance.edit/src/daemon/ipc.h
--- entrance/src/daemon/ipc.h	2004-04-19 06:15:50.000000000 +0100
+++ entrance.edit/src/daemon/ipc.h	2006-07-30 19:48:56.000000000 +0100
@@ -13,6 +13,7 @@
 
 #include "../ipc.h"
 #include "Entranced.h"
+#include "Entranced_Display.h"
 
 int  entranced_ipc_init(pid_t pid);
 void entranced_ipc_shutdown(void);
diff -Naur entrance/src/daemon/spawner.c entrance.edit/src/daemon/spawner.c
--- entrance/src/daemon/spawner.c	2006-07-30 19:23:23.000000000 +0100
+++ entrance.edit/src/daemon/spawner.c	2006-07-30 20:10:34.000000000 +0100
@@ -1,6 +1,7 @@
 #include <Ecore.h>
 #include <Ecore_Config.h>
 #include "Entranced.h"
+#include "Entranced_Display.h"
 #include "auth.h"
 #include "util.h"
 #include "ipc.h"
@@ -11,11 +12,10 @@
 static Ecore_Event_Handler *_d_handler = NULL;
 static Ecore_Event_Filter *_e_filter = NULL;
 
-static struct sigaction _entrance_x_sa, _entrance_d_sa;
+static struct sigaction _entrance_d_sa;
 
 static unsigned char is_respawning = 0;
 static unsigned char exev = 0;
-static unsigned char x_ready = 0;
 static Ecore_Timer *respawn_timer = NULL;
 
 /**
@@ -65,159 +65,7 @@
    }
 }
 
-/**
- * Create a new display context.
- * @return A pointer to an Entranced_Display handle for the new context
- */
-Entranced_Display *
-Entranced_Display_New(void)
-{
-   Entranced_Display *d;
-
-   d = calloc(1, sizeof(Entranced_Display));
-
-   /*TODO: make entrance itself use libentrance_edit*/
-   ecore_config_string_default("/entranced/xserver", DEFAULT_X_SERVER);
-   ecore_config_int_default("/entranced/attempts", 5);
-
-   ecore_config_file_load(PACKAGE_CFG_DIR "/entrance_config.cfg");
-
-   d->xprog = ecore_config_string_get("/entranced/xserver");
-   d->attempts = ecore_config_int_get("/entranced/attempts");
-
-   d->status = NOT_RUNNING;
-   d->auth_en = 1;
-   d->auths = ecore_list_new();
-   d->client.uid = -1;
-   d->client.gid = -1;
-   return d;
-}
-
-/**
- * Launch a new X server
- * @param d The spawner display context that will handle this server
- */
-void
-Entranced_Spawn_X(Entranced_Display * d)
-{
-   int i = 0;
-
-   if (d == NULL)
-      return;
-
-   d->status = NOT_RUNNING;
-   while ((i < d->attempts) && (d->status != RUNNING))
-   {
-      if ((d->pid = Entranced_Start_Server_Once(d)) > 0)
-         break;
-      ++i;
-   }
-}
-
-/**
- * Single attempt to start the X Server.
- * @param d The spawner display context that will handle this server
- * @return The status of the display context after the launch attempt
- */
-pid_t
-Entranced_Start_Server_Once(Entranced_Display * d)
-{
-   double start_time;
-   char x_cmd[PATH_MAX];
-
-   /* Ecore_Exe *x_exe; */
-   pid_t xpid;
-
-   d->status = LAUNCHING;
-
-   x_ready = 0;
-
-   /* Create server auth cookie */
-
-   if(d->auth_en)
-   {
-      if (!entranced_auth_display_secure(d))
-      {
-         syslog(LOG_CRIT, "Failed to generate auth cookie for X Server.");
-         return -1;
-      }
-   
-      snprintf(x_cmd, PATH_MAX, "%s -auth %s %s", d->xprog, d->authfile, d->name);
-   }
-   else
-   {
-      snprintf(x_cmd, PATH_MAX, "%s %s", d->xprog, d->name);
-   }
-   entranced_debug("Entranced_Start_Server_Once: Executing %s\n", x_cmd);
-
-   /* x_exe = ecore_exe_run(d->xprog, d); */
-   switch (xpid = fork())
-   {
-     case -1:
-        syslog(LOG_WARNING, "fork() to start X server failed.");
-        return -1;
-     case 0:
-        _entrance_x_sa.sa_handler = SIG_IGN;
-        _entrance_x_sa.sa_flags = 0;
-        sigemptyset(&_entrance_x_sa.sa_mask);
-        sigaction(SIGUSR1, &_entrance_x_sa, NULL);
-      /* FIXME: need to parse command and NOT go thru /bin/sh!!!! */
-      /* why? some /bin/sh's wont pass on this SIGUSR1 thing... */
-        execl("/bin/sh", "/bin/sh", "-c", x_cmd, NULL);
-        syslog(LOG_WARNING, "Could not execute X server.");
-        exit(1);
-     default:
-        start_time = ecore_time_get();
-
-        while (!x_ready)
-        {
-           double current_time;
-
-           usleep(100000);
-           current_time = ecore_time_get();
-           if ((current_time - start_time) > 5.0)
-	     break;
-        }
-
-        if (!x_ready)
-        {
-           entranced_debug("Entranced_Start_Server_Once: Attempt to start X server failed.\n");
-           d->status = NOT_RUNNING;
-        }
-        else
-           d->status = RUNNING;
-
-        return xpid;
-   }
-}
-
-/**
- * Start a new Entrance session
- * @param d The spawner display context that this session will use
- */
-void
-Entranced_Spawn_Entrance(Entranced_Display *d)
-{
-   char entrance_cmd[PATH_MAX];
 
-   d->client.pid = 0;
-   d->client.uid = -1;
-   d->client.gid = -1;
-   if (d->client.homedir)
-      free(d->client.homedir);
-   d->client.homedir = NULL;
-
-   snprintf(entrance_cmd, PATH_MAX, "%s -d %s", ENTRANCE, d->name);
-   if (d->config)
-      snprintf(entrance_cmd, PATH_MAX, "%s -d %s -c \"%s\" -z %d", 
-               ENTRANCE, d->name, d->config, getpid());
-   else
-      snprintf(entrance_cmd, PATH_MAX, "%s -d %s -z %d", ENTRANCE, d->name,
-                                                         getpid());
-   printf("Starting command: %s\n", entrance_cmd);
-   d->e_exe = ecore_exe_run(entrance_cmd, d);
-   d->client.pid = ecore_exe_pid_get(d->e_exe);
-}
 
 int
 Entranced_Respawn_Reset(void *data)
@@ -229,23 +77,6 @@
    return 0;
 }
 
-int
-Entranced_X_Restart(Entranced_Display * d)
-{
-   /* Attempt to restart X server */
-   d->status = NOT_RUNNING;
-
-   syslog(LOG_INFO, "Attempting to restart X server.");
-   Entranced_Spawn_X(d);
-   if (d->status != RUNNING)
-   {
-      syslog(LOG_CRIT, "Failed to restart the X server. Aborting.");
-      return 0;
-   }
-   else
-      syslog(LOG_INFO, "Successfully restarted the X server.");
-   return 1;
-}
 
 /* Event Filters */
 void *
@@ -288,7 +119,8 @@
 
    /* X sends SIGUSR1 to let us know it is ready */
 /*    if (e->number == 1)*/
-   x_ready = 1;
+/*   x_ready = 1; this becomes below */
+   Entranced_Display_XReady_Set(1);
 /*    return 1; */
 }
 
@@ -344,7 +176,7 @@
       if (waitpid(d->pid, NULL, WNOHANG) > 0)
       {
          syslog(LOG_INFO, "The X Server apparently died as well.");
-         if (!Entranced_X_Restart(d))
+         if (!Entranced_Display_X_Restart(d))
             exit(1);
       }
 
@@ -360,7 +192,7 @@
 
       sleep(2);
       kill(d->pid, SIGKILL);
-      if (!Entranced_X_Restart(d))
+      if (!Entranced_Display_X_Restart(d))
          exit(1);
 
    }
@@ -371,7 +203,7 @@
 
    d->client.connected = 0;
    entranced_auth_user_remove(d);
-   Entranced_Spawn_Entrance(d);
+   Entranced_Display_Spawn_Entrance(d);
 
    return 1;
 }
@@ -557,7 +389,7 @@
 
    /* Launch X Server */
    syslog(LOG_INFO, "Starting X server.");
-   Entranced_Spawn_X(d);
+   Entranced_Display_Spawn_X(d);
 
    if (d->status == NOT_RUNNING)
    {
@@ -569,7 +401,7 @@
 
    /* Run Entrance */
    syslog(LOG_INFO, "Starting Entrance.");
-   Entranced_Spawn_Entrance(d);
+   Entranced_Display_Spawn_Entrance(d);
 
    /* Main program loop */
    entranced_debug("Entering main loop.\n");