[GRASS-SVN] r47968 - grass/branches/releasebranch_6_4/lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 30 02:17:46 EDT 2011
Author: mmetz
Date: 2011-08-29 23:17:46 -0700 (Mon, 29 Aug 2011)
New Revision: 47968
Modified:
grass/branches/releasebranch_6_4/lib/gis/spawn.c
Log:
lib/gis: backport G_wait(), CloseHandle()
Modified: grass/branches/releasebranch_6_4/lib/gis/spawn.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/gis/spawn.c 2011-08-30 06:16:59 UTC (rev 47967)
+++ grass/branches/releasebranch_6_4/lib/gis/spawn.c 2011-08-30 06:17:46 UTC (rev 47968)
@@ -386,13 +386,18 @@
return -1;
}
+ CloseHandle(pi.hThread);
+
if (!background) {
WaitForSingleObject(pi.hProcess, INFINITE);
if (!GetExitCodeProcess(pi.hProcess, &exitcode))
return -1;
+ CloseHandle(pi.hProcess);
return (int) exitcode;
}
+ CloseHandle(pi.hProcess);
+
return pi.dwProcessId;
}
@@ -716,7 +721,7 @@
sp->directory = NULL;
}
-#define NEXT_ARG(var, type) ((type) (ssize_t) *(var)++)
+#define NEXT_ARG(var, type) ((type) *(var)++)
static void parse_argvec(struct spawn *sp, const char **va)
{
@@ -937,3 +942,42 @@
return status;
}
+int G_wait(int i_pid)
+{
+#ifdef __MINGW32__
+ DWORD rights = PROCESS_QUERY_INFORMATION | SYNCHRONIZE;
+ HANDLE hProcess = OpenProcess(rights, FALSE, (DWORD) i_pid);
+ DWORD exitcode;
+
+ if (!hProcess)
+ return -1;
+
+ WaitForSingleObject(hProcess, INFINITE);
+ if (!GetExitCodeProcess(hProcess, &exitcode))
+ exitcode = (DWORD) -1;
+
+ CloseHandle(hProcess);
+
+ return (int) exitcode;
+#else
+ pid_t pid = (pid_t) i_pid;
+ int status = -1;
+ pid_t n;
+
+ do
+ n = waitpid(pid, &status, 0);
+ while (n == (pid_t) - 1 && errno == EINTR);
+
+ if (n != pid)
+ return -1;
+ else {
+ if (WIFEXITED(status))
+ return WEXITSTATUS(status);
+ else if (WIFSIGNALED(status))
+ return WTERMSIG(status);
+ else
+ return -0x100;
+ }
+#endif
+}
+
More information about the grass-commit
mailing list