ratpoison-devel
[Top][All Lists]
Advanced

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

[RP] Patch to stop shells from being left around


From: Mike Meyer
Subject: [RP] Patch to stop shells from being left around
Date: Thu Oct 4 14:48:02 2001

I noticed that the exec and xterm commands tended to leave an "sh -c"
hanging around. This seems strange considering the "ugly dance" that
spawn goes through to prevent zombies, as zombies only take up a
process slot but the shells use memory that would otherwise be free.

The attached patch changes that behavior by adding a "&" to the
command if it doesn't end in one. Since the shell is now doing what
the first fork in spawn does, that double fork may no longer be
needed. While the change for that is obvious, the test isn't, so I've
left it as is.

        <mike
--
Mike Meyer <address@hidden>                     http://www.mired.org/home/mwm/
Q: How do you make the gods laugh?              A: Tell them your plans.

Index: actions.c
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/actions.c,v
retrieving revision 1.93
diff -u -r1.93 actions.c
--- actions.c   2001/09/23 07:43:40     1.93
+++ actions.c   2001/10/04 21:38:41
@@ -865,7 +865,30 @@
 void
 spawn(void *data)
 {
-  char *cmd = data;
+  char *cmd ;
+  /* ugly dance to avoid leaving shells laying around. */
+  cmd = strrchr((char *) data, '&');
+
+  /* If we have an &, see if it's the last non-white on the line */
+  if (cmd != NULL)
+    {
+      do {
+       cmd++;
+      } while (*cmd == ' ') ;
+      if (*cmd == '\0') cmd = NULL;
+    }
+
+  /* cmd doesn't end in an &, so we add one */
+  if (cmd == NULL)
+    {
+      cmd = xmalloc(strlen((char *) data) + 3);
+      sprintf(cmd, "%s &", (char *) data);
+    }
+  else
+    {
+      cmd = xstrdup((char *) data);
+    }
+
   /*
    * ugly dance to avoid leaving zombies.  Could use SIGCHLD,
    * but it's not very portable.
@@ -891,6 +914,7 @@
       _exit(EXIT_SUCCESS);
     }
   wait((int *) 0);
+  free(cmd);
   PRINT_DEBUG ("spawned %s\n", cmd);
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]