Enlightenment CVS committal

Author  : essiene
Project : e17
Module  : apps/entrance

Dir     : e17/apps/entrance/src/daemon


Modified Files:
        Entranced.h Makefile.am auth.h entrance_edit.c ipc.h spawner.c 


Log Message:
Further refactorings. I've extracted out Entranced_Display subsystem from 
spawner.c, so its easier to see exactly what spawner.c is doing now. This is 
the first in this set of patches. The end result should finally see spawner.c 
renamed to main.c. Once that is done, we can begin to look at easily adding new 
code as it will be clearer what goes where.

Oh yeah, and since no one has commented on this patch, I'll just comfortably 
take that as a go ahead, remember we can always revert :)

===================================================================
RCS file: /cvs/e/e17/apps/entrance/src/daemon/Entranced.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -3 -r1.14 -r1.15
--- Entranced.h 3 Jun 2006 06:36:16 -0000       1.14
+++ Entranced.h 1 Aug 2006 04:32:01 -0000       1.15
@@ -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);
===================================================================
RCS file: /cvs/e/e17/apps/entrance/src/daemon/Makefile.am,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -3 -r1.19 -r1.20
--- Makefile.am 22 Jul 2006 09:25:44 -0000      1.19
+++ Makefile.am 1 Aug 2006 04:32:01 -0000       1.20
@@ -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@
 
===================================================================
RCS file: /cvs/e/e17/apps/entrance/src/daemon/auth.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- auth.h      7 Nov 2005 18:41:11 -0000       1.2
+++ auth.h      1 Aug 2006 04:32:01 -0000       1.3
@@ -2,6 +2,7 @@
 #define __ENTRANCED_AUTH_H
 
 #include <Entranced.h>
+#include <Entranced_Display.h>
 #include <X11/Xauth.h>
 #include <X11/Xos.h>
 
===================================================================
RCS file: /cvs/e/e17/apps/entrance/src/daemon/entrance_edit.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- entrance_edit.c     28 Jul 2006 03:20:10 -0000      1.3
+++ entrance_edit.c     1 Aug 2006 04:32:01 -0000       1.4
@@ -88,6 +88,8 @@
                   return 1;
                }
        }
+
+       return 0;
 }
 
 void 
===================================================================
RCS file: /cvs/e/e17/apps/entrance/src/daemon/ipc.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- ipc.h       19 Apr 2004 05:15:50 -0000      1.1
+++ ipc.h       1 Aug 2006 04:32:01 -0000       1.2
@@ -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);
===================================================================
RCS file: /cvs/e/e17/apps/entrance/src/daemon/spawner.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -3 -r1.31 -r1.32
--- spawner.c   22 Jul 2006 08:56:22 -0000      1.31
+++ spawner.c   1 Aug 2006 04:32:01 -0000       1.32
@@ -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,158 +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));
-
-   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)
@@ -228,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 *
@@ -287,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; */
 }
 
@@ -343,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);
       }
 
@@ -359,7 +192,7 @@
 
       sleep(2);
       kill(d->pid, SIGKILL);
-      if (!Entranced_X_Restart(d))
+      if (!Entranced_Display_X_Restart(d))
          exit(1);
 
    }
@@ -370,7 +203,7 @@
 
    d->client.connected = 0;
    entranced_auth_user_remove(d);
-   Entranced_Spawn_Entrance(d);
+   Entranced_Display_Spawn_Entrance(d);
 
    return 1;
 }
@@ -556,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)
    {
@@ -568,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");



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to