Enlightenment CVS committal

Author  : onefang
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore


Modified Files:
        Ecore.h ecore_exe.c ecore_private.h ecore_signal.c 


Log Message:
* exe exit event delay method changed.
* Added method to close an exe's stdin in a (probably) vain attempt to convince 
exe to exit.
* Other debugging shit.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/Ecore.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -3 -r1.32 -r1.33
--- Ecore.h     27 Dec 2005 17:17:30 -0000      1.32
+++ Ecore.h     30 Dec 2005 19:17:21 -0000      1.33
@@ -210,6 +210,7 @@
    EAPI Ecore_Exe  *ecore_exe_run(const char *exe_cmd, const void *data);
    EAPI Ecore_Exe  *ecore_exe_pipe_run(const char *exe_cmd, Ecore_Exe_Flags 
flags, const void *data);
    EAPI int         ecore_exe_pipe_write(Ecore_Exe *exe, void *data, int size);
+   EAPI void        ecore_exe_pipe_write_close(Ecore_Exe *exe);
    EAPI void       *ecore_exe_free(Ecore_Exe *exe);
    EAPI pid_t       ecore_exe_pid_get(Ecore_Exe *exe);
    EAPI void        ecore_exe_tag_set(Ecore_Exe *exe, const char *tag);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/ecore_exe.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -3 -r1.26 -r1.27
--- ecore_exe.c 24 Dec 2005 12:13:12 -0000      1.26
+++ ecore_exe.c 30 Dec 2005 19:17:21 -0000      1.27
@@ -71,6 +71,10 @@
  *     EMFILE  Too many file descriptors used by process.
  *     ENOLCK  Problem getting a lock.
  *     EPERM   Not allowed to do that.
+ *   fsync
+ *     EBADF   This is not an fd that is open for writing.
+ *     EINVAL, EROFS  This is not an fd that can be fsynced.
+ *     EIO     I/O error.
  *
  * How to use it -
  *    int ok = 0;
@@ -88,7 +92,7 @@
  *        // Something failed, cleanup.
  *     }
  */
-         switch (result)
+         switch (saved_errno)
            {
               case EACCES :
               case EAGAIN :
@@ -118,6 +122,7 @@
               case EFAULT :
               case EBADF :
               case EINVAL :
+              case EROFS :
               case EISDIR :
               case EDEADLK :
               case EPERM :
@@ -137,9 +142,9 @@
                      fprintf(stderr, 
                        "*** NAUGHTY PROGRAMMER!!!\n"
                        "*** SPANK SPANK SPANK!!!\n"
-                       "*** Unsupported errno code, please add this one.\n"
-                       "*** Now go fix your code in %s @%u. Tut tut tut!\n"
-                       "\n", __FILE__, __LINE__);
+                       "*** Unsupported errno code %d, please add this one.\n"
+                       "*** Now go fix your code in %s @%u, from %s @%u. Tut 
tut tut!\n"
+                       "\n", saved_errno, __FILE__, __LINE__, file, line);
                     result = 0;
                     break;
                  }
@@ -193,6 +198,7 @@
        ECORE_MAGIC_SET(exe, ECORE_MAGIC_EXE);
        exe->pid = pid;
        exe->data = (void *)data;
+        exe->cmd = strdup(exe_cmd);
        exes = _ecore_list2_append(exes, exe);
        return exe;
      }
@@ -389,6 +395,8 @@
       {   /* Something went wrong, so pull down everything. */
          IF_FN_DEL(_ecore_exe_free, exe);
       }
+else
+printf("Running as %d for %s.\n", exe->pid, exe->cmd);
 
    errno = n;
    return exe;
@@ -426,6 +434,25 @@
 }
 
 /**
+ * The stdin pipe of the given child process will close when the write buffer 
is empty.
+ * 
+ * @param exe  The child process to write to
+ * @ingroup Ecore_Exe_Basic_Group
+ */
+void
+ecore_exe_pipe_write_close(Ecore_Exe *exe)
+{
+   if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
+     {
+       ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
+                        "ecore_exe_pipe_write_close");
+       return;
+     }
+   exe->close_write = 1;
+}
+
+
+/**
  * Sets the string tag for the given process handle
  *
  * @param   exe The given process handle.
@@ -782,6 +809,7 @@
          unsigned char *inbuf;
         int inbuf_num;
 
+//printf("Reading data for %s\n", exe->cmd);
          /* Get any left over data from last time. */
          inbuf = exe->read_data_buf;
          inbuf_num = exe->read_data_size;
@@ -890,14 +918,17 @@
                        }
                     if (lost_exe)
                        {
-                          if (exe->exit_event)
-                             {   /*  There is a pending exit event to send, so 
send it. */
-                                _ecore_event_add(ECORE_EVENT_EXE_EXIT, 
exe->exit_event, 
-                                                 _ecore_event_exe_exit_free, 
NULL);
-                                exe->exit_event = NULL;   /* Just being 
paranoid. */
-                             }
-                          else
-                              ecore_exe_terminate(exe);   /* FIXME: give this 
some deep thought later. */
+if (exe->read_data_size)
+   printf("Theer are %d bytes left unsent from the dead exe %s.\n", 
exe->read_data_size, exe->cmd);
+//                        if (exe->exit_event)
+//                           {   /*  There is a pending exit event to send, so 
send it. */
+//printf("Sending delayed exit event for %s.\n", exe->cmd);
+//                              _ecore_event_add(ECORE_EVENT_EXE_EXIT, 
exe->exit_event, 
+//                                               _ecore_event_exe_exit_free, 
NULL);
+//                              exe->exit_event = NULL;   /* Just being 
paranoid. */
+//                           }
+//                        else
+//                              ecore_exe_terminate(exe);   /* FIXME: give 
this some deep thought later. */
                         }
                     break;
                  }
@@ -916,6 +947,22 @@
    if ((exe->write_fd_handler) && 
(ecore_main_fd_handler_active_get(exe->write_fd_handler, ECORE_FD_WRITE)))
       _ecore_exe_flush(exe);
 
+   /* If we have sent all there is to send, and we need to close the pipe, 
then close it. */
+   if ((exe->close_write == 1) && /*(!exe->write_data_buf) &&*/ 
(exe->write_data_size == exe->write_data_offset))
+      {
+         int ok = 0;
+         int result;
+
+printf("Closing stdin for %s\n", exe->cmd);
+//         if (exe->child_fd_write)  E_NO_ERRNO(result, 
fsync(exe->child_fd_write), ok);
+         IF_FN_DEL(ecore_main_fd_handler_del, exe->write_fd_handler);
+         if (exe->child_fd_write)  E_NO_ERRNO(result, 
close(exe->child_fd_write), ok);
+        exe->child_fd_write = 0;
+         IF_FREE(exe->write_data_buf);
+         exe->flags &= ~ECORE_EXE_PIPE_WRITE;
+        exe->close_write = 0;
+      }
+
    return 1;
 }
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/ecore_private.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -3 -r1.28 -r1.29
--- ecore_private.h     27 Dec 2005 17:17:30 -0000      1.28
+++ ecore_private.h     30 Dec 2005 19:17:21 -0000      1.29
@@ -191,11 +191,7 @@
    int          read_data_size; /* data read from child in bytes */
    int          child_fd_write;        /* fd to write TO to send data to the 
child */
    int          child_fd_read; /* fd to read FROM when child has sent us (the 
parent) data */
-   /* I thought a bit about wether or not their could be multiple exit events, 
then realised that since we 
-    * delete the exe on the first exit event, the answer is no.  On the other 
hand, STOPing an exe may trigger
-    * this, even though it has not truly exited.  Probably should investigate 
this further.
-    */
-   struct _Ecore_Event_Exe_Exit  *exit_event; /* Process exit event */
+   int          close_write;
 };
 #endif
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/ecore_signal.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -3 -r1.19 -r1.20
--- ecore_signal.c      19 Dec 2005 05:07:58 -0000      1.19
+++ ecore_signal.c      30 Dec 2005 19:17:21 -0000      1.20
@@ -33,6 +33,8 @@
 static void _ecore_signal_callback_sigrt(int sig, siginfo_t *si, void *foo);
 #endif
 
+static int _ecore_signal_exe_exit_delay(void *data);
+
 static volatile sig_atomic_t sig_count = 0;
 static volatile sig_atomic_t sigchld_count = 0;
 static volatile sig_atomic_t sigusr1_count = 0;
@@ -184,10 +186,37 @@
                    e->data = sigchld_info; /* FIXME: I'm not sure, but maybe 
we should clone this.  I don't know if anybody uses it. */
                  
                   if ((e->exe) && (e->exe->flags & ECORE_EXE_PIPE_READ))
-                    e->exe->exit_event = e;   /* We want to report the Last 
Words of the exe, so delay this event. */
+                     {
+                       /* We want to report the Last Words of the exe, so 
delay this event.
+                        * There are three possibilities here -
+                        *  1 There are no Last Words.
+                        *  2 There are Last Words, they are not ready to be 
read.
+                        *  3 There are Last Words, they are ready to be read.
+                        *
+                        * For 1 we don't want to delay, for 3 we want to delay.
+                        * 2 is the problem.  If we check for data now and 
there 
+                        * is none, then there is no way to differentiate 1 and 
2.
+                        * If we don't delay, we may loose data, but if we do 
delay, 
+                        * there may not be data and the exit event never gets 
sent.
+                        * 
+                        * Any way you look at it, there has to be some time 
passed 
+                        * before the exit event gets sent.  So the startegy 
here is
+                        * to setup a timer event that will send the exit event 
after
+                        * an arbitrary, but brief, time.
+                        *
+                        * This is probably paranoid, for the less paraniod, we 
could 
+                        * check to see for Last Words, and only delay if there 
are any.
+                        * This has it's own set of problems.
+                        */
+printf("Delaying exit event for %s.\n", e->exe->cmd);
+                        ecore_timer_add(0.1, _ecore_signal_exe_exit_delay, e);
+                     }
                  else
+{
+printf("Sending exit event for %s.\n", e->exe->cmd);
                     _ecore_event_add(ECORE_EVENT_EXE_EXIT, e, 
                                   _ecore_event_exe_exit_free, NULL);
+}
               }
          }
        sigchld_count--;
@@ -458,4 +487,19 @@
    sig_count++;
 }
 #endif
+
+static int
+_ecore_signal_exe_exit_delay(void *data)
+{
+   Ecore_Event_Exe_Exit *e;
+
+   e = data;
+   if (e)
+      {
+printf("Sending delayed exit event for %s.\n", e->exe->cmd);
+      _ecore_event_add(ECORE_EVENT_EXE_EXIT, e, 
+          _ecore_event_exe_exit_free, NULL);
+      }
+   return 0;
+}
 #endif




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to