summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Beulshausen <dbeu@php.net>2001-07-09 16:44:40 +0000
committerDaniel Beulshausen <dbeu@php.net>2001-07-09 16:44:40 +0000
commit112b9062ff18d13c08fc3f36d103fc78c825ea63 (patch)
tree50d58783f7d03644af454953cd260e97ca4ef269
parent61822fcd477edc5976700ff40fbebf189bd431d6 (diff)
downloadphp-git-112b9062ff18d13c08fc3f36d103fc78c825ea63.tar.gz
adopt shane's popen patch
-rw-r--r--TSRM/tsrm_win32.c23
-rw-r--r--TSRM/tsrm_win32.h2
2 files changed, 14 insertions, 11 deletions
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c
index daa861bf03..40217a0870 100644
--- a/TSRM/tsrm_win32.c
+++ b/TSRM/tsrm_win32.c
@@ -74,9 +74,7 @@ static ProcessPair* process_get(FILE *stream)
TWLS_FETCH();
for (ptr = TWG(process); ptr < (TWG(process) + TWG(process_size)); ptr++) {
- if (stream != NULL && ptr->stream == stream) {
- break;
- } else if (stream == NULL && !ptr->inuse) {
+ if (ptr->stream == stream) {
break;
}
}
@@ -96,6 +94,14 @@ static ProcessPair* process_get(FILE *stream)
return ptr;
}
+static HANDLE dupHandle(HANDLE fh, BOOL inherit) {
+ HANDLE copy, self = GetCurrentProcess();
+ if (!DuplicateHandle(self, fh, self, &copy, 0, inherit, DUPLICATE_SAME_ACCESS|DUPLICATE_CLOSE_SOURCE)) {
+ return NULL;
+ }
+ return copy;
+}
+
TSRM_API FILE* popen(const char *command, const char *type)
{
FILE *stream = NULL;
@@ -146,9 +152,11 @@ TSRM_API FILE* popen(const char *command, const char *type)
proc = process_get(NULL);
if (read) {
+ in = dupHandle(in, FALSE);
fno = _open_osfhandle((long)in, _O_RDONLY | mode);
CloseHandle(out);
} else {
+ out = dupHandle(out, FALSE);
fno = _open_osfhandle((long)out, _O_WRONLY | mode);
CloseHandle(in);
}
@@ -156,7 +164,6 @@ TSRM_API FILE* popen(const char *command, const char *type)
stream = _fdopen(fno, type);
proc->prochnd = process.hProcess;
proc->stream = stream;
- proc->inuse = 1;
return stream;
}
@@ -172,16 +179,12 @@ TSRM_API int pclose(FILE* stream)
fflush(process->stream);
fclose(process->stream);
+ WaitForSingleObject(process->prochnd, INFINITE);
GetExitCodeProcess(process->prochnd, &termstat);
- if (termstat == STILL_ACTIVE) {
- TerminateProcess(process->prochnd, termstat);
- }
-
process->stream = NULL;
- process->inuse = 0;
CloseHandle(process->prochnd);
return termstat;
}
-#endif
+#endif \ No newline at end of file
diff --git a/TSRM/tsrm_win32.h b/TSRM/tsrm_win32.h
index c26c8f9506..95cdd99a82 100644
--- a/TSRM/tsrm_win32.h
+++ b/TSRM/tsrm_win32.h
@@ -25,10 +25,10 @@
#ifdef TSRM_WIN32
#include <windows.h>
+
typedef struct {
FILE *stream;
HANDLE prochnd;
- int inuse;
} ProcessPair;
typedef struct {