Enlightenment CVS committal

Author  : xcomputerman
Project : e17
Module  : apps/entrance

Dir     : e17/apps/entrance/src/daemon


Modified Files:
        spawner.c spawner.h 


Log Message:
Initial commit of revamped spawner code.

Respawning is currently broken, because ecore barfs when X is killed.
Possible solutions are to have the broken pipe properly handled in
ecore, or fork off a separate process for ecore_x functions.


===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/entrance/src/daemon/spawner.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- spawner.c   26 Jul 2003 15:19:26 -0000      1.5
+++ spawner.c   14 Oct 2003 17:05:14 -0000      1.6
@@ -1,587 +1,357 @@
+#include <Ecore.h>
+#include <Ecore_X.h>
+#include <Ecore_Ipc.h>
 #include "spawner.h"
 
-/* funcs */
-Spawner_Display *spawner_display_new(void);
-static void spawn_entrance(void);
-static void spawn_x(void);
-static int start_server_once(Spawner_Display * d);
-void session_exit(void);
-void daemon_exit(void);
-void x_server_dead(void);
-void handle_sigchild(void);
-void handle_sigterm(void);
-void handle_sigusr1(void);
-double get_time(void);
-
-/* globals */
-Spawner_Display *d;
-sigset_t d_sig;
-sigset_t empty_sig;
-int term_sig = 0, child_sig = 0, usr1_sig = 0;
+/* Globals */
+/* Entranced_Spawner_Display *d; */
+Ecore_Event_Handler *e_handler = NULL;
+Ecore_Event_Handler *d_handler = NULL;
+
+static unsigned char is_respawning = 0;
+Ecore_Timer *respawn_timer = NULL;
 
 /**
- * write_entranced_pidfile - write the entranced pid to the specified pidfile
- * @pid - the pid_t variable received from the first fork called
+ * Write the entranced pid to the defined pidfile.
+ * @param pid The spawner's process ID, which is the pid after the fork if there was 
one
+ * @return 0 if the operation was successful, 1 otherwise.
  */
-int
-write_entranced_pidfile(pid_t pid)
-{
-   FILE *fp;
-   int size, result = 1;
-   char buf[PATH_MAX];
-
-   size = snprintf(buf, PATH_MAX, "%d", pid);
-   if ((fp = fopen(PIDFILE, "w+")))
-   {
-      fwrite(buf, sizeof(char), size, fp);
-      fclose(fp);
-      result = 0;
-   }
-   return (result);
+int Entranced_Write_Pidfile (pid_t pid) {
+    FILE *fp;
+    int size, result = 1;
+    char buf[PATH_MAX];
+
+    size = snprintf(buf, PATH_MAX, "%d", pid);
+    if ((fp = fopen(PIDFILE, "w+"))) {
+        fwrite(buf, sizeof(char), size, fp);
+        fclose(fp);
+        result = 0;
+    }
+
+    return result;
 }
 
 /**
- * fork_and_exit - initial call in entranced, fork and exit for ease of use
- * To make this useable from startup scripts it's currently setup like this.
- * If this is incorrect or whatever please feel free to let me know.
+ * Make entranced a daemon by fork-and-exit. This is the default behavior.
  */
-void
-fork_and_exit(void)
-{
-   pid_t entranced_pid;
-
-   switch (entranced_pid = fork())
-   {
-     case 0:
-        break;
-     default:
-        if (write_entranced_pidfile(entranced_pid))
-        {
-           syslog(LOG_CRIT, "%d is the pid, but I couldn't write to %s.",
-                   entranced_pid, PIDFILE);
-           kill(entranced_pid, SIGKILL);
-           exit(1);
-        }
+void Entranced_Fork_And_Exit(void) {
+    pid_t entranced_pid;
 
-        exit(0);
-   }
+    switch (entranced_pid = fork()) {
+        case 0:
+            break;
+        default:
+            if (Entranced_Write_Pidfile(entranced_pid)) {
+                syslog(LOG_CRIT, "%d is the pid, but I couldn't write to %s.",
+                        entranced_pid, PIDFILE);
+                kill(entranced_pid, SIGKILL);
+                exit(1);
+            }
+            exit(0);
+    }
 }
 
-static int
-x_error_handler_ignore(Display * d, XErrorEvent * e)
-{
-   /* do nothing */
-   return 0;
+/**
+ * Create a new display context.
+ * @return A pointer to an Entranced_Spawner_Display handle for the new context
+ */
+Entranced_Spawner_Display *Entranced_Spawner_Display_New(void) {
+    Entranced_Spawner_Display *d;
+
+    d = malloc(sizeof(Entranced_Spawner_Display));
+    memset(d, 0, sizeof(Entranced_Spawner_Display));
+    /* TODO: Config-ize these parameters */
+    d->xprog = strdup(X_SERVER);
+    d->attempts = 5;
+    d->status = NOT_RUNNING;
+    d->e_exe = NULL;
+    d->x_exe = NULL;
+    d->display = NULL;
+    return d;
 }
 
 /**
- * x_server_killall - Kill all X clients
- *
- * This function will attempt to reset the X server by killing
- * all client windows, prior to respawning the entrance client.
+ * Launch a new X server
+ * @param d The spawner display context that will handle this server
  */
-static void
-x_server_killall(void)
-{
-   int screens, i, j;
-   pid_t pid;
-
-   if (!d || !(d->display))
-      return;
-
-   /* Fork off to avoid bringing down the daemon if X server dies in
-       * the middle of this function */
-   if((pid = fork())) {
-          waitpid(pid, NULL, 0);
-          kill(pid, SIGKILL);
-          return;
-   }
-
-   /* Don't want entranced barfing over a BadWindow error or sth */
-   XSetErrorHandler(x_error_handler_ignore);
-
-   XGrabServer(d->display);
-   screens = ScreenCount(d->display);
-
-   /* Traverse window tree starting from root, drag them * all before the
-      firing squad */
-   for (i = 0; i < screens; ++i)
-   {
-      Window root_r;
-      Window parent_r;
-      Window *children_r = NULL;
-      int num_children = 0;
-      Window root = RootWindow(d->display, i);
-
-      while (XQueryTree
-             (d->display, root, &root_r, &parent_r, &children_r,
-              &num_children) && num_children > 0)
-      {
-
-         for (j = 0; j < num_children; ++j)
-         {
-            XKillClient(d->display, children_r[j]);
-         }
-
-         XFree(children_r);
-      }
-   }
+static void Entranced_Spawn_X(Entranced_Spawner_Display *d) {
+    int i = 0;
 
-   XUngrabServer(d->display);
-   XSync(d->display, False);
+    if (d == NULL)
+        return;
+
+    d->status = NOT_RUNNING;
+    while ((i < d->attempts) && (d->status != RUNNING)) {
+        if ((d->x_exe = Entranced_Start_Server_Once(d)))
+            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
+ */
+Ecore_Exe * Entranced_Start_Server_Once(Entranced_Spawner_Display *d) {
+    double start_time;
+    Ecore_Exe *x_exe;
+/*    pid_t x_pid; */
+
+    d->status = LAUNCHING;
+    /* switch (x_pid = fork()) {
+        case 0:
+            execl("/bin/sh", "/bin/sh", "-c", d->xprog, d->xprog, NULL);
+            start_time = ecore_time_get();
+            break;
+        case -1:
+            syslog(LOG_CRIT, "Could not fork() to spawn X process.");
+            perror("Entranced");
+            exit(0);
+            break;
+        default:
+            d->pid.x = x_pid;
+            break;
+    } */
+
+    x_exe = ecore_exe_run(d->xprog, d);
+
+    d->name = strdup(getenv("DISPLAY"));
+       start_time = ecore_time_get();
+       
+    while (!(ecore_x_init(d->name))) {
+        double current_time;
+        usleep(100000);
+        current_time = ecore_time_get();
+        if ((start_time - current_time) > 5.0)
+            break;
+    }
+
+    d->display = ecore_x_display_get();
+
+    if (d->display == NULL) {
+        d->status = NOT_RUNNING;
+        if(x_exe != NULL) {
+            ecore_exe_free(x_exe);
+            x_exe = NULL;
+        }
+    } else
+        d->status = RUNNING;
+
+    return x_exe;
+}
 
 /**
- * main - startup the entranced process
- * @argc - not used
- * @argv - not used
- * Entranced starts off by forking off a child process, writing the child's
- * pid to a pidfile, and returning.  The forked child begins a new X session
- * and then starts the entrance process.
+ * Kill all X client windows. This is useful after the death of the session.
  */
-int
-main(int argc, char **argv)
-{
-   int c;
-   int nodaemon = 0;
-   struct sigaction act;
-   struct option d_opt[] = {
-      {"nodaemon", 0, 0, 1},
-      {"help", 0, 0, 2},
-      {0, 0, 0, 0}
-   };
-   pid_t entranced_pid = getpid();
-
-   putenv("DISPLAY");
-   openlog("entranced", LOG_NOWAIT, LOG_DAEMON);
-
-   /* get command line arguments */
-   while (1)
-   {
-      c = getopt_long_only(argc, argv, "d:", d_opt, NULL);
-      if (c == -1)
-         break;
-      switch (c)
-      {
-        case 'd':              /* display */
-           setenv("DISPLAY", optarg, 1);
-           break;
-        case 1:                /* nodaemon */
-           nodaemon = 1;
-           break;
-        case 2:
-           printf("Entranced - Launcher for the Entrance Display Manager\n");
-           printf("Usage: %s [OPTION] ...\n\n", argv[0]);
-           printf
-              
("--------------------------------------------------------------------------\n");
-           printf("  -d DISPLAY         Connect to an existing X server\n");
-           printf("  -help              Display this help message\n");
-           printf
-              ("  -nodaemon          Don't fork to background (useful for init 
scripts)\n");
-           printf
-              
("==========================================================================\n\n");
-           printf
-              ("Note: if you're launching Entrance from within an existing X session, 
don't\n");
-           printf
-              ("try to use entranced or you may get unexpected results. Instead, 
launch\n");
-           printf("entrance directly by typing \"entrance\".\n\n");
-           exit(0);
+void Entranced_X_Killall() {
+    int i, n;
+    Ecore_X_Window *roots;
 
-        default:
-           fprintf(stderr, "Warning: Unknown command line option\n");
-      }
-   }
-
-   if (!getenv("DISPLAY"))
-      setenv("DISPLAY", X_DISP, 1);
-
-   if (nodaemon)
-   {
-      if (write_entranced_pidfile(entranced_pid))
-      {
-         syslog(LOG_CRIT, "%d is the pid, but I couldn't write to %s.",
-                 entranced_pid, PIDFILE);
-         exit(1);
-      }
-   }
-   else
-      fork_and_exit();
-
-   /* Set up signals */
-   sigemptyset(&empty_sig);
-   sigemptyset(&d_sig);
-   sigaddset(&d_sig, SIGTERM);
-   sigaddset(&d_sig, SIGCHLD);
-   sigaddset(&d_sig, SIGHUP);
-   sigaddset(&d_sig, SIGUSR1);
-
-   /* Check to make sure entrance binary is executable */
-   if (access(ENTRANCE, X_OK))
-   {
-      syslog(LOG_CRIT, "Fatal Error: Unable to launch entrance binary. Aborting.");
-      exit(1);
-   }
-
-   if (!nodaemon)
-   {
-      close(0);
-      close(1);
-      close(2);
-   }
-
-   /* register child signal handler */
-   act.sa_handler = handle_sigchild;
-   act.sa_mask = d_sig;
-   sigaction(SIGCHLD, &act, NULL);
-
-   act.sa_handler = handle_sigusr1;
-   act.sa_mask = d_sig;
-   sigaction(SIGUSR1, &act, NULL);
-
-   act.sa_handler = handle_sigterm;
-   act.sa_mask = d_sig;
-   sigaction(SIGTERM, &act, NULL);
-
-   /* setup a spawner context */
-   d = spawner_display_new();
-
-   /* run X */
-   syslog(LOG_INFO, "Starting X server.");
-   spawn_x();
-
-   if (d->status == NOT_RUNNING)
-   {
-      free(d);
-      syslog(LOG_CRIT, "Could not start X server.");
-      exit(1);
-   }
-
-   /* run entrance */
-   syslog(LOG_INFO, "Starting Entrance.");
-   spawn_entrance();
-
-   for (;;)
-   {
-      if (term_sig)
-         daemon_exit();
-      if (child_sig)
-         x_server_dead();
-      if (usr1_sig)
-         session_exit();
-
-      term_sig = child_sig = usr1_sig = 0;
-      sigsuspend(&empty_sig);
-   }
-
-   closelog();
-   
-   return 0;
-}
-
-/* display_new */
-Spawner_Display *
-spawner_display_new(void)
-{
-   Spawner_Display *d;
-
-   d = malloc(sizeof(Spawner_Display));
-   memset(d, 0, sizeof(Spawner_Display));
-   d->xprog = strdup(X_SERVER);
-   d->attempts = 5;
-   d->status = NOT_RUNNING;
-   return (d);
-}
-
-/* spawn_entrance */
-static void
-spawn_entrance(void)
-{
-   pid_t pid, ppid;
-
-   sigprocmask(SIG_BLOCK, &d_sig, NULL);
-   ppid = getpid();
-
-   /* First fork */
-   switch (pid = fork())
-   {
-     case 0:
-        pid = fork();
-        if (pid)
-           exit(0);
-        else
-        {
-           /* Declare independence from the colonial masters */
-           if (setsid() == -1)
-           {
-              perror("setsid");
-              kill(ppid, SIGTERM);
-              exit(1);
-           }
-
-           /* Restore SIGCHLD default handling */
-           signal(SIGCHLD, SIG_DFL);
-           /* I will not die before my children */
-           signal(SIGHUP, SIG_IGN);
-           signal(SIGTERM, SIG_IGN);
-           signal(SIGUSR1, SIG_IGN);
-
-           sigprocmask(SIG_UNBLOCK, &d_sig, NULL);
-
-           /* Then fork again. woohoo */
-           if ((pid = fork()) == -1)
-           {
-              syslog(LOG_CRIT, "Fatal erro: Could not fork() entrance process.");
-              exit(1);
-           }
-                  
-          /* Process Monitor */
-           if (pid)
-           {
-              /* Wait for client session process to die, then destroy this
-                 process group */
-              pid_t chld;
-              int status;
-
-              while ((chld = waitpid(-1, &status, 0)) > 0)
-              {
-                 if (chld == pid
-                     && (WIFEXITED(status) || WIFSIGNALED(status)))
-                 {
-                    /* Tell daemon that this session is done. */
-                    kill(ppid, SIGUSR1);
-
-                    /* Die hard */
-                    kill(0, SIGKILL);
-                    exit(0);
-                 }
-              }
-           }
-           else
-           {
-              /* Launch entrance client */
-              if (execl
-                  ("/bin/sh", "/bin/sh", "-c", ENTRANCE, ENTRANCE, d->name,
-                   NULL) < 0)
-                 exit(1);
-           }
+    roots = ecore_x_window_root_list(&n);
+
+    for (i = 0; i < n; ++i)
+        ecore_x_killall(roots[i]);
+}
+
+/**
+ * Start a new Entrance session
+ * @param d The spawner display context that this session will use
+ */
+void Entranced_Spawn_Entrance(Entranced_Spawner_Display *d) {
+    char entrance_cmd[PATH_MAX];
+    
+    snprintf(entrance_cmd, PATH_MAX, "%s %s", ENTRANCE, d->name);
+    d->e_exe = ecore_exe_run(entrance_cmd, d);
+}
+
+int Entranced_Respawn_Reset(void *data) {
+    is_respawning = 0;
+    return 0;
+}
+
+/* Event handlers */
+int Entranced_Exe_Exited(void *data, int type, void *event) {
+    Ecore_Event_Exe_Exit *e = (Ecore_Event_Exe_Exit *) event;
+    Entranced_Spawner_Display *d = (Entranced_Spawner_Display *) data;
+    
+       printf("Ecore_Event_Exe_Exit triggered.\n");
+
+    if(is_respawning)
+        return;
+    
+    is_respawning = 1;
+    respawn_timer = ecore_timer_add(3.0, Entranced_Respawn_Reset, NULL);
+       
+    if (e->exe == d->e_exe) {
+        /* Session exited or crashed */
+        if (e->exited)
+            syslog(LOG_INFO, "The session has ended normally.");
+        else if (e->signalled)
+            syslog(LOG_INFO, "The session was terminated with signal %d.", 
e->exit_signal);
+    
+    } else {
+        /* X terminated for some reason */
+        if (e->exited)
+            syslog(LOG_INFO, "The X Server terminated for some reason.");
+        else if (e->signalled)
+            syslog(LOG_INFO, "The X server was terminated with signal %d.", 
e->exit_signal);
+
+    }
+
+    /* Die harder */
+    ecore_exe_terminate(d->e_exe);
+    ecore_exe_terminate(d->x_exe);
+    sleep(1);
+    ecore_exe_kill(d->x_exe);
+    sleep(1);
+
+    ecore_exe_free(d->e_exe);
+    ecore_exe_free(d->x_exe);
+    
+    d->status = NOT_RUNNING;
+       
+       /* Wait 4 seconds */
+       sleep(4);
+
+    /* Attempt to restart X server */
+    Entranced_Spawn_X(d);
+    if (d->status != RUNNING) {
+        syslog(LOG_CRIT, "Failed to restart the X server. Aborting.");
+        exit(1);
+    }
+
+    /* Launch Entrance */
+    Entranced_Spawn_Entrance(d);
+    
+    return 1;
+}
+
+int Entranced_Signal_Exit(void *data, int type, void *event) {
+       printf("Ecore_Signal_Exit_Triggered\n");
+    syslog(LOG_INFO, "Display and display manager are shutting down.");
+    ecore_main_loop_quit();
+    return 0;
+}
+
+/*
+ * Main function
+ */
+int main (int argc, char **argv) {
+    int c;
+    int nodaemon = 0;           /* TODO: Config-ize this variable */
+    Entranced_Spawner_Display *d;
+    struct option d_opt[] = {
+        {"nodaemon", 0, 0, 1},
+        {"help", 0, 0, 2},
+        {0, 0, 0, 0}
+    };
+    pid_t entranced_pid = getpid();
+
+    /* Initialize Ecore */
+    ecore_init();
+    ecore_app_args_set(argc, (const char **) argv);
+
+    putenv("DISPLAY");          /* Not sure why this is here :) */
+    openlog("entranced", LOG_NOWAIT, LOG_DAEMON);
+
+    /* Parse command-line options */
+    while (1) {
+        c = getopt_long_only(argc, argv, "d:", d_opt, NULL);
+        if (c == -1)
+            break;
+        switch (c) {
+            case 'd':
+                setenv("DISPLAY", optarg, 1);
+                break;
+            case 1:
+                nodaemon = 1;
+                break;
+            case 2:
+                /* This should probably in a separate usage function, but bleh */
+                printf("Entranced - Launcher for the Entrance Display Manager\n");
+                printf("Usage: %s [OPTION] ...\n\n", argv[0]);
+                printf
+                    
("--------------------------------------------------------------------------\n");
+                printf("  -d DISPLAY         Connect to an existing X server\n");
+                printf("  -help              Display this help message\n");
+                printf
+                    ("  -nodaemon          Don't fork to background (useful for init 
scripts)\n");
+                printf
+                    
("==========================================================================\n\n");
+                printf
+                    ("Note: if you're launching Entrance from within an existing X 
session, don't\n");
+                printf
+                    ("try to use entranced or you may get unexpected results. 
Instead, launch\n");
+                printf("entrance directly by typing \"entrance\".\n\n");
+                exit(0);
+
+        }
+    }
+
+    /* TODO: Config-ize this */
+    if (!getenv("DISPLAY"))
+        setenv("DISPLAY", X_DISP, 1);
+
+    if (nodaemon) {
+        if (Entranced_Write_Pidfile(entranced_pid)) {
+            syslog(LOG_CRIT, "%d is the pid, but I couldn't write to %s.",
+                    entranced_pid, PIDFILE);
+            exit(1);
         }
-        break;
-     case -1:
-        syslog(LOG_CRIT, "Fatal: Could not fork() entrance process.");
+    } else
+        Entranced_Fork_And_Exit();
+
+    /* Check to make sure entrance binary is executable */
+    if (access(ENTRANCE, X_OK)) {
+        syslog(LOG_CRIT, "Fatal Error: Unable to launch entrance binary. Aborting.");
+        exit(1);
+    }
+
+    /* Daemonize */
+    if (!nodaemon) {
+        close(0);
+        close(1);
+        close(2);
+    }
+
+    /* Set up a spawner context */
+    d = Entranced_Spawner_Display_New();
+
+    /* Launch X Server */
+    syslog(LOG_INFO, "Starting X server.");
+    Entranced_Spawn_X(d);
+
+    if (d->status == NOT_RUNNING) {
+        free(d);
+        syslog(LOG_CRIT, "Could not start X server.");
         exit(1);
-        break;
-     default:
-        d->pid.client = pid;
-        break;
-   }
-
-   /* This ought to be taken care of by sigsuspend(), 
-       * ensure complete atomicity */
-   /* sigprocmask(SIG_UNBLOCK, &d_sig, NULL); */
-
-}
-
-int
-x_pid_check(void)
-{
-   pid_t pid;
-   int status;
-
-   /* A pause, in case X died as well...allow things * to settle down */
-   usleep(500000);
-
-   /* Try to determine if X has died */
-   do
-   {
-      pid = waitpid(-1, &status, WNOHANG);
-      if (pid == d->pid.x)
-         return 1;
-   }
-   while (pid > 0);
-
-   return 0;
-}
-
-void
-x_server_dead(void)
-{
-   int status;
-
-   /* SIGCHLD received. This most likely means that X died. */
-   if (x_pid_check())
-   {
-      syslog(LOG_CRIT, "X server died.");
-
-      /* Die Harder! */
-      kill(d->pid.x, SIGTERM);
-         sleep(3);
-         kill(d->pid.x, SIGKILL);
-      d->display = NULL;
-
-      /* Attend to any waiting zombies before proceeding */
-      while (waitpid(-1, &status, WNOHANG) > 0);
-
-      /* Check if X died while trying to launch. */
-      if (d->status == LAUNCHING)
-      {
-         d->status = NOT_RUNNING;
-         syslog(LOG_WARNING, "X died mysteriously whilst launching. Waiting 10 
seconds before trying again.");
-         sleep(10);
-      }
-      d->status = NOT_RUNNING;
-
-      spawn_x();
-      if (d->status == NOT_RUNNING)
-      {
-         free(d);
-         syslog(LOG_CRIT, "Could not start X server.");
-         exit(1);
-      }
-
-      syslog(LOG_INFO, "Started new X server, spawning entrance...");
-      spawn_entrance();
-   }
-}
-
-void
-session_exit(void)
-{
-   pid_t pid;
-   int status;
-
-   pid = x_pid_check();
-
-   /* The session process has died */
-   if (!x_pid_check())
-   {
-      syslog(LOG_INFO, "Session has apparently ended.");
-      /* Clean up windows */
-         x_server_killall();
-
-         /* Terminate X server */
-      kill(d->pid.x, SIGTERM);
-         sleep(3);
-         kill(d->pid.x, SIGKILL);
-      d->display = NULL;
-
-
-      /* Attend to any waiting zombies */
-      while (waitpid(-1, &status, WNOHANG) > 0);
-
-      /* Restart X server */
-         spawn_x();
-      if (d->status == NOT_RUNNING)
-      {
-         free(d);
-         syslog(LOG_CRIT, "Could not start X server.");
-         exit(1);
-      }
-
-      spawn_entrance();
-      return;
-   }
-}
-
-void
-daemon_exit(void)
-{
-   syslog(LOG_CRIT, "Received SIGTERM, closing session.");
-   kill(d->pid.x, SIGTERM);
-   sleep(1);
-   kill(d->pid.x, SIGKILL);
-   closelog();
-   exit(0);
-}
-
-/* indicate that a sigchild has occurred */
-void
-handle_sigchild(void)
-{
-   child_sig = 1;
-}
-
-/* indicate that a sigterm has occurred */
-void
-handle_sigterm(void)
-{
-   term_sig = 1;
-}
-
-/* indicate that a sigusr1 has occurred */
-void
-handle_sigusr1(void)
-{
-   usr1_sig = 1;
-}
-
-/* spawn_x */
-static void
-spawn_x(void)
-{
-   int i = 0;
-
-   d->status = NOT_RUNNING;
-   while ((i < d->attempts) && (d->status != RUNNING))
-   {
-      if (start_server_once(d) == RUNNING)
-      {
-         d->status = RUNNING;
-         break;
-      }
-      i++;
-   }
-}
-
-
-/* start_server_once */
-static int
-start_server_once(Spawner_Display * d)
-{
-   double start_time = 0;
-   int pid;
-   int dspnum = 0;
-
-   d->status = LAUNCHING;
-   switch (pid = fork())
-   {
-     case 0:
-        execl("/bin/sh", "/bin/sh", "-c", d->xprog, d->xprog, NULL);
-        start_time = get_time();
-        break;
-     case -1:
-        syslog(LOG_CRIT, "Could not fork() to spawn X process.");
-        perror("Entranced");
-        exit(0);
-        break;
-     default:
-        d->pid.x = pid;
-        break;
-   }
-
-   d->name = strdup(getenv("DISPLAY"));
-   while (!(d->display = XOpenDisplay(d->name)))
-   {
-      double current_time;
-
-      current_time = get_time();
-      usleep(100000);
-      if (((start_time - current_time) > 5.0) || (dspnum > 2))
-         break;
-   }
-
-   if (!d->display)
-      return NOT_RUNNING;
-
-   return RUNNING;
-}
-
-/* get_time */
-double
-get_time(void)
-{
-   struct timeval timev;
+    }
 
-   gettimeofday(&timev, NULL);
-   return (double) timev.tv_sec + (((double) timev.tv_usec) / 1000000);
+    /* Run Entrance */
+    syslog(LOG_INFO, "Starting Entrance.");
+    Entranced_Spawn_Entrance(d);
+
+    /* Set up event handlers */
+    e_handler = ecore_event_handler_add(ECORE_EVENT_EXE_EXIT, Entranced_Exe_Exited, 
d);
+    d_handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, 
Entranced_Signal_Exit, NULL);
+
+    /* Main program loop */
+       printf("Entering main loop.\n");
+    ecore_main_loop_begin();
+
+    
+    /* Shut down */
+       printf("Exited main loop! Shutting down...\n");
+    ecore_exe_terminate(d->e_exe);
+    ecore_exe_terminate(d->x_exe);
+    sleep(5);
+    /* Die harder */
+    ecore_exe_kill(d->e_exe);
+    ecore_exe_kill(d->x_exe);
+        
+    closelog();
+    ecore_shutdown();
+    exit(0);
 }
+
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/entrance/src/daemon/spawner.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- spawner.h   24 May 2003 00:06:33 -0000      1.2
+++ spawner.h   14 Oct 2003 17:05:14 -0000      1.3
@@ -1,18 +1,21 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <signal.h>
 #include <unistd.h>
-#include <sys/time.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <X11/Xlib.h>
 #include <limits.h>
 #include <getopt.h>
 #include <syslog.h>
+
+#include <Ecore.h>
+#include <Ecore_X.h>
+#include <Ecore_Ipc.h>
+
 #include "../config.h"
 
-#define X_SERVER "/usr/X11R6/bin/X -terminate -ac -quiet"
+#define X_SERVER "/usr/X11R6/bin/X -quiet"
 /*#define X_SERVER "/usr/X11R6/bin/Xnest -terminate -geometry 640x480 -ac -full :1"*/
 #define X_DISP ":0"             /* only used if DISPLAY variable is NOT set */
 #define ENTRANCE PREFIX "/bin/entrance_wrapper"
@@ -23,19 +26,21 @@
 #define LAUNCHING 1
 #define RUNNING 2
 
-/* structs */
-typedef struct _Spawner_Display Spawner_Display;
-
-struct _Spawner_Display
+struct _Entranced_Spawner_Display
 {
    Display *display;
    char *name;                  /* the name of the x display */
    char *xprog;                 /* the X execution string */
    int attempts;
    int status;
+   Ecore_Exe *e_exe, *x_exe;
    struct
    {
       pid_t x, client;
    }
    pid;
 };
+
+/* structs */
+typedef struct _Entranced_Spawner_Display Entranced_Spawner_Display;
+




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to