[svn-commits] mnicholson: branch mnicholson/asttest r247332 - /team/mnicholson/asttest/astt...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Feb 17 14:44:45 CST 2010


Author: mnicholson
Date: Wed Feb 17 14:44:42 2010
New Revision: 247332

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=247332
Log:
Make pid_gc send SIGKILL after about 1.5 seconds if the process has not exited.

Modified:
    team/mnicholson/asttest/asttest/lua/proclib.c

Modified: team/mnicholson/asttest/asttest/lua/proclib.c
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/lua/proclib.c?view=diff&rev=247332&r1=247331&r2=247332
==============================================================================
--- team/mnicholson/asttest/asttest/lua/proclib.c (original)
+++ team/mnicholson/asttest/asttest/lua/proclib.c Wed Feb 17 14:44:42 2010
@@ -111,18 +111,25 @@
  * \param L the lua state to use
  *
  * This is the gc function for the pid userdata.  This function will send a
- * TERM signal to the process and then run waitpid.
+ * TERM signal to the process and then run waitpid.  If the process has not
+ * exited after about 1.5 seconds, SIGKILL will be sent.
  */
 static int pid_gc(lua_State *L) {
+	int i = 0;
 	pid_t *p = luaL_checkudata(L, 1, "proclib_pid");
 	if (kill(*p, SIGTERM)) {
 		return 0;
 	}
-#if 0	/* XXX maybe we should also do SIGKILL here? */
-	sleep(1);
-	kill(*p, SIGKILL);
-#endif
-	waitpid(*p, NULL, 0);
+
+	/* wait for the process to exit, after about 1.5 seconds, send SIGKILL */
+	while (waitpid(*p, NULL, WNOHANG) == 0) {
+		if (++i == 3) {
+			kill(*p, SIGKILL);
+			continue;
+		}
+		usleep(500);
+	}
+
 	return 0;
 }
 




More information about the svn-commits mailing list