Enlightenment CVS committal

Author  : xcomputerman
Project : e17
Module  : apps/entrance

Dir     : e17/apps/entrance/src/daemon


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


Log Message:
OK -- finally wrap this up:
- IPC functions added on both sides
- Xauth now fully functional
- Cleanup entranced shutdown (eliminate warnings)

Please report any bugs at http://xcomputerman.com/bugs/.


===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/entrance/src/daemon/Entranced.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- Entranced.h 22 Mar 2004 06:51:39 -0000      1.1
+++ Entranced.h 19 Apr 2004 05:15:50 -0000      1.2
@@ -1,3 +1,6 @@
+#ifndef __ENTRANCED_H
+#define __ENTRANCED_H
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -28,10 +31,15 @@
 #define EXITCODE 42
 
 /* structs */
-/* FIXME: Deprecate offending namespace foo */
-typedef struct _Entranced_Display Entranced_Display;
+typedef struct _Entranced_Client {
+   pid_t    pid;
+   uid_t    uid;
+   gid_t    gid;
+   char    *homedir;
+   char    *authfile;
+} Entranced_Client;
 
-struct _Entranced_Display
+typedef struct _Entranced_Display
 {
    Display     *display;
    int         dispnum;         /* FIXME */
@@ -39,18 +47,17 @@
    char        *xprog;          /* the X execution string */
    int         attempts;
    int         status;
-   struct {
-      pid_t x, client;
-   } pid;
+   pid_t       pid;
    Ecore_List  *auths;
    char        *authfile;
-   char        *user_authfile;
    char        *hostname;
    
    char        *config;         /* Config file for greeter */
-   Ecore_Exe   *e_exe;          /* Exe handle 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);
@@ -65,3 +72,5 @@
 int Entranced_Exe_Exited(void *data, int type, void *event);
 int Entranced_Signal_Exit(void *data, int type, void *event);
 
+#endif
+
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/entrance/src/daemon/Makefile.am,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- Makefile.am 31 Mar 2004 16:43:32 -0000      1.10
+++ Makefile.am 19 Apr 2004 05:15:50 -0000      1.11
@@ -7,7 +7,7 @@
 localstate_DATA = 
 
 entranced_SOURCES = \
-       auth.c auth.h Entranced.h md5.c md5.h spawner.c util.c
+       auth.c auth.h Entranced.h ipc.c ipc.h md5.c md5.h spawner.c util.c
 
 entranced_LDADD = @x_libs@ -lXau @ecore_libs@ @edb_libs@
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/entrance/src/daemon/auth.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- auth.c      23 Mar 2004 01:31:59 -0000      1.7
+++ auth.c      19 Apr 2004 05:15:50 -0000      1.8
@@ -68,7 +68,7 @@
    if (!d || !auth_file)
       return;
 
-   entranced_debug("entranced_auth_purge: %s", d->name);
+   entranced_debug("entranced_auth_purge: %s\n", d->name);
    fseek (auth_file, 0L, SEEK_SET);
    
    auth_keep = ecore_list_new();
@@ -95,7 +95,7 @@
    }
 
    /* Write remaining entries to auth file */
-   if (!(auth_file = freopen(d->user_authfile, "w", auth_file)))
+   if (!(auth_file = freopen(d->client.authfile, "w", auth_file)))
    {
       entranced_debug("entranced_auth_purge: Write failed!\n");
       return;
@@ -229,7 +229,7 @@
 int
 entranced_auth_display_secure (Entranced_Display *d)
 {
-   FILE              *auth_file;
+   FILE              *auth_file, *host_file;
    char              buf[PATH_MAX];
    char              hostname[1024];
 
@@ -278,10 +278,20 @@
    if (!_entranced_auth_entry_add(d, auth_file, d->hostname, 
                                  strlen(d->hostname)))
       return FALSE;
-   
+
    fclose(auth_file);
    setenv("XAUTHORITY", d->authfile, TRUE);
 
+   /* Write host access file */
+   snprintf(buf, PATH_MAX, "/etc/X%d.hosts", d->dispnum);
+   if (!(host_file = fopen(buf, "w")))
+   {
+      entranced_debug("entranced_auth_display_secure: Unable to open %s for 
writing\n", buf);
+      return FALSE;
+   }
+   fprintf(host_file, "%s\n", d->hostname);
+   fclose(host_file);
+   
    entranced_debug("entranced_auth_display_secure: Successfully set up access for %s 
(localhost)\n", d->name);
 
    return TRUE;
@@ -305,21 +315,21 @@
       umask (077);
 
       if (!homedir)
-         d->user_authfile = NULL;
+         d->client.authfile = NULL;
       else
       {
          snprintf(buf, PATH_MAX, "%s/.Xauthority", homedir);
-         d->user_authfile = strdup(buf);
+         d->client.authfile = strdup(buf);
       }
 
       /* Make sure the file can be written to */
-      if((auth_file = fopen(d->user_authfile, "a+")))
+      if((auth_file = fopen(d->client.authfile, "a+")))
          fclose(auth_file);
       else
       {
-         entranced_debug("entranced_auth_user_add: Unable to write auth file %s", 
d->user_authfile);
-         free(d->user_authfile);
-         d->user_authfile = NULL;
+         entranced_debug("entranced_auth_user_add: Unable to write auth file %s\n", 
d->client.authfile);
+         free(d->client.authfile);
+         d->client.authfile = NULL;
          return FALSE;
       }
       /* TODO: May need a permissions/paranoia check */
@@ -328,11 +338,11 @@
       /* FIXME: What if for some reason we never succeed in getting
        *        a lock ?
        */
-      if (XauLockAuth(d->user_authfile, 3, 3, 0) != LOCK_SUCCESS)
+      if (XauLockAuth(d->client.authfile, 3, 3, 0) != LOCK_SUCCESS)
       {
-         syslog(LOG_CRIT, "entranced_auth_user_add: Unable to lock auth file %s", 
d->user_authfile);
-         free(d->user_authfile);
-         d->user_authfile = NULL;
+         syslog(LOG_CRIT, "entranced_auth_user_add: Unable to lock auth file %s", 
d->client.authfile);
+         free(d->client.authfile);
+         d->client.authfile = NULL;
 
          umask (022);
       }
@@ -341,19 +351,19 @@
    }
 
    /* Open file and write auth entries */
-   if(!(auth_file = fopen(d->user_authfile, "a+")))
+   if(!(auth_file = fopen(d->client.authfile, "a+")))
    {
-      syslog(LOG_CRIT, "entranced_auth_user_add: Open auth file %s failed after 
lock", d->user_authfile);
-      XauUnlockAuth (d->user_authfile);
-      free(d->user_authfile);
-      d->user_authfile = NULL;
+      syslog(LOG_CRIT, "entranced_auth_user_add: Open auth file %s failed after 
lock", d->client.authfile);
+      XauUnlockAuth (d->client.authfile);
+      free(d->client.authfile);
+      d->client.authfile = NULL;
 
       umask (022);
 
       return FALSE;
    }
 
-   entranced_debug("entranced_auth_user_add: Opened %s for writing cookies\n", 
d->user_authfile);
+   entranced_debug("entranced_auth_user_add: Opened %s for writing cookies\n", 
d->client.authfile);
 
    /* Remove any existing old entries for this display */
    _entranced_auth_purge(d, auth_file);
@@ -369,8 +379,8 @@
    }
 
    fclose(auth_file);
-   XauUnlockAuth(d->user_authfile);
-   entranced_debug("entranced_auth_user_add: Finished writing auth entries to %s", 
d->user_authfile);
+   XauUnlockAuth(d->client.authfile);
+   entranced_debug("entranced_auth_user_add: Finished writing auth entries to %s\n", 
d->client.authfile);
 
    return ret;
       
@@ -381,26 +391,26 @@
 {
    FILE     *auth_file;
 
-   if (!d || !d->user_authfile)
+   if (!d || !d->client.authfile)
       return;
 
-   entranced_debug("entranced_auth_user_remove: Removing cookie from %s\n", 
d->user_authfile);
+   entranced_debug("entranced_auth_user_remove: Removing cookie from %s\n", 
d->client.authfile);
 
    /* TODO: Permissions check on auth file */
    /* Get a lock */
-   if (XauLockAuth(d->user_authfile, 3, 3, 0) != LOCK_SUCCESS)
+   if (XauLockAuth(d->client.authfile, 3, 3, 0) != LOCK_SUCCESS)
    {
-      free(d->user_authfile);
-      d->user_authfile = NULL;
+      free(d->client.authfile);
+      d->client.authfile = NULL;
       return;
    }
 
    /* Open the file */
-   if (!(auth_file = fopen(d->user_authfile, "a+")))
+   if (!(auth_file = fopen(d->client.authfile, "a+")))
    {
-      XauUnlockAuth(d->user_authfile);
-      free(d->user_authfile);
-      d->user_authfile = NULL;
+      XauUnlockAuth(d->client.authfile);
+      free(d->client.authfile);
+      d->client.authfile = NULL;
       return;
    }
 
@@ -409,10 +419,10 @@
    
    /* Close and unlock */
    fclose(auth_file);
-   XauUnlockAuth(d->user_authfile);
+   XauUnlockAuth(d->client.authfile);
 
-   free(d->user_authfile);
-   d->user_authfile = NULL;
+   free(d->client.authfile);
+   d->client.authfile = NULL;
 }
 
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/entrance/src/daemon/spawner.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -3 -r1.14 -r1.15
--- spawner.c   22 Mar 2004 06:51:39 -0000      1.14
+++ spawner.c   19 Apr 2004 05:15:50 -0000      1.15
@@ -1,8 +1,8 @@
 #include <Ecore.h>
-#include <Ecore_X.h>
-#include <Ecore_Ipc.h>
 #include "Entranced.h"
+#include "auth.h"
 #include "util.h"
+#include "ipc.h"
 
 /* Globals */
 /* Entranced_Display *d; */
@@ -73,16 +73,12 @@
 {
    Entranced_Display *d;
 
-   d = malloc(sizeof(Entranced_Display));
-   memset(d, 0, sizeof(Entranced_Display));
+   d = calloc(1, sizeof(Entranced_Display));
    /* TODO: Config-ize these parameters */
    d->xprog = strdup(X_SERVER);
    d->attempts = 5;
    d->status = NOT_RUNNING;
-   d->config = NULL;
-   d->e_exe = NULL;
-   d->x_exe = NULL;
-   d->display = NULL;
+   d->auths = ecore_list_new();
    return d;
 }
 
@@ -101,7 +97,7 @@
    d->status = NOT_RUNNING;
    while ((i < d->attempts) && (d->status != RUNNING))
    {
-      if ((d->pid.x = Entranced_Start_Server_Once(d)) > 0)
+      if ((d->pid = Entranced_Start_Server_Once(d)) > 0)
          break;
       ++i;
    }
@@ -130,11 +126,20 @@
 
    x_ready = 0;
 
-   if(d->name)
-      snprintf(x_cmd, PATH_MAX, "%s %s", X_SERVER, d->name);
-   else
-      snprintf(x_cmd, PATH_MAX, "%s", X_SERVER);
-
+   /* Set display name */
+   if (d->name)
+      free(d->name);
+   d->name = strdup(getenv("DISPLAY"));
+
+   /* Create server auth cookie */
+   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", X_SERVER, d->authfile, d->name);
+   
    /* x_exe = ecore_exe_run(d->xprog, d); */
    switch (xpid = fork())
    {
@@ -147,9 +152,6 @@
         syslog(LOG_WARNING, "Could not execute X server.");
         exit(1);
      default:
-        if (d->name)
-           free(d->name);
-        d->name = strdup(getenv("DISPLAY"));
         start_time = ecore_time_get();
 
         while (!x_ready)
@@ -176,17 +178,27 @@
  * @param d The spawner display context that this session will use
  */
 void
-Entranced_Spawn_Entrance(Entranced_Display * d)
+Entranced_Spawn_Entrance(Entranced_Display *d)
 {
    char entrance_cmd[PATH_MAX];
 
+   d->client.pid = 0;
+   d->client.uid = 0;
+   d->client.gid = 0;
+   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\"", 
-               ENTRANCE, d->name, 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", ENTRANCE, d->name);
+      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
@@ -201,7 +213,14 @@
 int
 Entranced_X_Restart(Entranced_Display * d)
 {
-
+   /* Reinitialize display handle */
+   if (d->e_exe)
+      ecore_exe_free(d->e_exe);
+   d->e_exe = NULL;
+   if (d->x_exe)
+      ecore_exe_free(d->x_exe);
+   d->x_exe = NULL;
+   
    /* Attempt to restart X server */
    d->status = NOT_RUNNING;
 
@@ -281,7 +300,7 @@
    }
 
    is_respawning = 1;
-   respawn_timer = ecore_timer_add(15.0, Entranced_Respawn_Reset, d);
+   respawn_timer = ecore_timer_add(5.0, Entranced_Respawn_Reset, d);
 
    if (e->exe == d->e_exe && e->pid == ecore_exe_pid_get(d->e_exe))
    {
@@ -300,9 +319,9 @@
          syslog(LOG_INFO, "The session was terminated with signal %d.",
                 e->exit_signal);
 
-      kill(d->pid.x, SIGHUP);
+      kill(d->pid, SIGHUP);
       sleep(3);
-      if (waitpid(d->pid.x, NULL, WNOHANG) > 0)
+      if (waitpid(d->pid, NULL, WNOHANG) > 0)
       {
          syslog(LOG_INFO, "The X Server apparently died as well.");
          if (!Entranced_X_Restart(d))
@@ -310,7 +329,7 @@
       }
 
    }
-   else if (e->pid == d->pid.x)
+   else if (e->pid == d->pid)
    {
       /* X terminated for some reason */
       if (e->exited)
@@ -320,7 +339,7 @@
                 e->exit_signal);
 
       sleep(2);
-      kill(d->pid.x, SIGKILL);
+      kill(d->pid, SIGKILL);
       if (!Entranced_X_Restart(d))
          exit(1);
 
@@ -360,6 +379,8 @@
    int c;
    int nodaemon = 0;            /* TODO: Config-ize this variable */
    Entranced_Display *d;
+   char *str = NULL;
+   char *disp = NULL;
    struct option d_opt[] = {
       {"config", 1, 0, 'c'},
       {"display", 1, 0, 'd'},
@@ -379,6 +400,7 @@
 
    /* Set up a spawner context */
    d = Entranced_Display_New();
+   entranced_ipc_display_set(d);
 
    /* Parse command-line options */
    while (1)
@@ -428,6 +450,16 @@
    /* TODO: Config-ize this */
    if (!getenv("DISPLAY"))
       setenv("DISPLAY", X_DISP, 1);
+   
+   disp = getenv("DISPLAY");
+   str = strstr(disp, ":");
+
+   if(!str || str >= (disp + strlen(disp) - 1))
+      d->dispnum = 0;
+   else
+      d->dispnum = atoi(str + 1);
+
+   entranced_debug("entranced: main: display number is %d\n", d->dispnum);
 
    if (nodaemon)
    {
@@ -457,6 +489,10 @@
       close(2);
    }
 
+   /* Init IPC */
+   if (!entranced_ipc_init(entranced_pid))
+      exit(1);
+
    /* Event filter */
    _e_filter =
       ecore_event_filter_add(Entranced_Filter_Start, Entranced_Filter_Loop,
@@ -499,14 +535,20 @@
 
    /* Shut down */
    entranced_debug("Exited main loop! Shutting down...\n");
-   ecore_exe_terminate(d->e_exe);
-   kill(d->pid.x, SIGTERM);
+   if (d->e_exe)
+      ecore_exe_terminate(d->e_exe);
+   kill(d->pid, SIGTERM);
    sleep(5);
    /* Die harder */
-   ecore_exe_kill(d->e_exe);
-   kill(d->pid.x, SIGKILL);
+   if (d->e_exe)
+      ecore_exe_kill(d->e_exe);
+   kill(d->pid, SIGKILL);
+
+   if (d->authfile)
+      unlink(d->authfile);
 
    closelog();
+   entranced_ipc_shutdown();
    ecore_shutdown();
    exit(0);
 }




-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to