[Ecls-list] Patch: return exit status from EXT:RUN-PROGRAM

Josh Elsasser josh at elsasser.org
Sat Oct 4 19:42:03 UTC 2008


The following patch tries to return the program exit status as a
second return value from EXT:RUN-PROGRAM for the :WAIT T case.  The
win32 portion of the code is completely untested as I don't have
access to a Windows development setup.

diff --git src/c/unixsys.d src/c/unixsys.d
index f57519d..da5bf35 100644
--- src/c/unixsys.d
+++ src/c/unixsys.d
@@ -29,6 +29,12 @@
 #ifdef _MSC_VER
 #include <windows.h>
 #endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
 
 cl_object
 si_system(cl_object cmd_string)
@@ -77,6 +83,7 @@ si_make_pipe()
 	int child_pid;
 	cl_object stream_write;
 	cl_object stream_read;
+	cl_object exit_status = Cnil;
 @{
 	command = si_copy_to_simple_base_string(command);
 	argv = cl_mapcar(2, @'si::copy-to-simple-base-string', argv);
@@ -235,11 +242,16 @@ si_make_pipe()
 	if (child_stdout) CloseHandle(child_stdout);
 	if (child_stderr) CloseHandle(child_stderr);
 	if (ok) {
+		DWORD exitcode;
 		CloseHandle(pr_info.hThread);
 		child_pid = pr_info.dwProcessId;
 		if (wait != Cnil) {
 			  WaitForSingleObject(pr_info.hProcess, INFINITE);
 		}
+		if (GetExitCodeProcess(pr_info.hProcess, &exitcode) &&
+		    STILL_ACTIVE != exitcode) {
+			exit_status = MAKE_FIXNUM(exitcode);
+		}
 		CloseHandle(pr_info.hProcess);
 	} else {
 		const char *message;
@@ -328,6 +340,7 @@ si_make_pipe()
 	if (child_pid > 0 && wait != Cnil) {
 	   	int status[0];
 		waitpid(child_pid, status, 0);
+		exit_status = MAKE_FIXNUM(WEXITSTATUS(status));
 	}
 }
 #endif /* mingw */
@@ -354,5 +367,6 @@ si_make_pipe()
 	}
 	@(return ((parent_read || parent_write)?
 		  cl_make_two_way_stream(stream_read, stream_write) :
-		  Cnil))
+		  Cnil)
+		 exit_status)
 @)
diff --git src/configure.in src/configure.in
index 157c7d0..6a5553a 100644
--- src/configure.in
+++ src/configure.in
@@ -441,7 +441,8 @@ AC_CHECK_HEADERS( [fcntl.h inttypes.h limits.h netdb.h netinet/in.h] \
 dnl !!! end autoscan
 
 AC_CHECK_HEADERS( [sys/resource.h sys/utsname.h float.h pwd.h dlfcn.h link.h] \
-                  [mach-o/dyld.h ulimit.h dirent.h sys/ioctl.h sys/select.h])
+                  [mach-o/dyld.h ulimit.h dirent.h sys/ioctl.h sys/select.h] \
+                  [sys/wait.h] )
 
 dnl =====================================================================
 dnl Checks for typedefs, structures, and compiler characteristics.
diff --git src/h/config.h.in src/h/config.h.in
index 286e8ee..5f6156f 100644
--- src/h/config.h.in
+++ src/h/config.h.in
@@ -297,6 +297,8 @@ typedef unsigned @CL_FIXNUM_TYPE@ cl_hashkey;
 #undef HAVE_SCHED_YIELD
 /* uname() for system identification					*/
 #undef HAVE_UNAME
+#undef HAVE_UNISTD_H
+#undef HAVE_SYS_WAIT_H
 
 /*
  * we do not manage to get proper signal handling of floating point




More information about the ecl-devel mailing list