summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1998-06-15 04:07:18 +0000
committerGurusamy Sarathy <gsar@cpan.org>1998-06-15 04:07:18 +0000
commitf55ee38a033ce570145fdd38bb9f09acf59d37cd (patch)
treed09466217844d04a8289a2d2d15377ce38987426 /win32
parente6d5c5302bca4863c13ae11aa5ed04b35c9d89f5 (diff)
downloadperl-f55ee38a033ce570145fdd38bb9f09acf59d37cd.tar.gz
various win32 odds and ends
- added support for waitpid(), open2/open3, and a bugfix for kill() from Ronald Schmidt <RonaldWS@aol.com> - tweak testsuite mods of above - regenerate win32/config_H.?c - change kill() to win32_kill() and export it - coalesce common code in win32.c - add PerlProc_waitpid() and export win32_waitpid() result builds and passes on the three win32 compilers p4raw-id: //depot/perl@1134
Diffstat (limited to 'win32')
-rw-r--r--win32/config.bc2
-rw-r--r--win32/config.gc2
-rw-r--r--win32/config.vc2
-rw-r--r--win32/config_H.bc8
-rw-r--r--win32/config_H.gc8
-rw-r--r--win32/config_H.vc8
-rw-r--r--win32/makedef.pl2
-rw-r--r--win32/runperl.c6
-rw-r--r--win32/win32.c62
-rw-r--r--win32/win32iop.h4
10 files changed, 63 insertions, 41 deletions
diff --git a/win32/config.bc b/win32/config.bc
index 453c6fdc25..2d25e46ef3 100644
--- a/win32/config.bc
+++ b/win32/config.bc
@@ -271,7 +271,7 @@ d_voidtty=''
d_volatile='define'
d_vprintf='define'
d_wait4='undef'
-d_waitpid='undef'
+d_waitpid='define'
d_wcstombs='define'
d_wctomb='define'
d_xenix='undef'
diff --git a/win32/config.gc b/win32/config.gc
index ac5fa5f7ca..b98a55ec2e 100644
--- a/win32/config.gc
+++ b/win32/config.gc
@@ -271,7 +271,7 @@ d_voidtty=''
d_volatile='define'
d_vprintf='define'
d_wait4='undef'
-d_waitpid='undef'
+d_waitpid='define'
d_wcstombs='define'
d_wctomb='define'
d_xenix='undef'
diff --git a/win32/config.vc b/win32/config.vc
index 8699e29e5d..806549c363 100644
--- a/win32/config.vc
+++ b/win32/config.vc
@@ -271,7 +271,7 @@ d_voidtty=''
d_volatile='define'
d_vprintf='define'
d_wait4='undef'
-d_waitpid='undef'
+d_waitpid='define'
d_wcstombs='define'
d_wctomb='define'
d_xenix='undef'
diff --git a/win32/config_H.bc b/win32/config_H.bc
index ce21ebff2f..ca5ab3a476 100644
--- a/win32/config_H.bc
+++ b/win32/config_H.bc
@@ -788,7 +788,7 @@
* This symbol, if defined, indicates that the waitpid routine is
* available to wait for child process.
*/
-/*#define HAS_WAITPID /**/
+#define HAS_WAITPID /**/
/* HAS_WCSTOMBS:
* This symbol, if defined, indicates that the wcstombs routine is
@@ -1616,12 +1616,6 @@
#define LONGLONGSIZE 8 /**/
#endif
-/* HAS_MKSTEMP:
- * This symbol, if defined, indicates that the mkstemp routine is
- * available to create and open a unique temporary file.
- */
-/*#define HAS_MKSTEMP /**/
-
/* HAS_SETGROUPS:
* This symbol, if defined, indicates that the setgroups() routine is
* available to set the list of process groups. If unavailable, multiple
diff --git a/win32/config_H.gc b/win32/config_H.gc
index 22f12586e7..7ec7c7f16b 100644
--- a/win32/config_H.gc
+++ b/win32/config_H.gc
@@ -788,7 +788,7 @@
* This symbol, if defined, indicates that the waitpid routine is
* available to wait for child process.
*/
-/*#define HAS_WAITPID /**/
+#define HAS_WAITPID /**/
/* HAS_WCSTOMBS:
* This symbol, if defined, indicates that the wcstombs routine is
@@ -1616,12 +1616,6 @@
#define LONGLONGSIZE 8 /**/
#endif
-/* HAS_MKSTEMP:
- * This symbol, if defined, indicates that the mkstemp routine is
- * available to create and open a unique temporary file.
- */
-/*#define HAS_MKSTEMP /**/
-
/* HAS_SETGROUPS:
* This symbol, if defined, indicates that the setgroups() routine is
* available to set the list of process groups. If unavailable, multiple
diff --git a/win32/config_H.vc b/win32/config_H.vc
index 0ff8941b83..40870c5c90 100644
--- a/win32/config_H.vc
+++ b/win32/config_H.vc
@@ -788,7 +788,7 @@
* This symbol, if defined, indicates that the waitpid routine is
* available to wait for child process.
*/
-/*#define HAS_WAITPID /**/
+#define HAS_WAITPID /**/
/* HAS_WCSTOMBS:
* This symbol, if defined, indicates that the wcstombs routine is
@@ -1616,12 +1616,6 @@
#define LONGLONGSIZE 8 /**/
#endif
-/* HAS_MKSTEMP:
- * This symbol, if defined, indicates that the mkstemp routine is
- * available to create and open a unique temporary file.
- */
-/*#define HAS_MKSTEMP /**/
-
/* HAS_SETGROUPS:
* This symbol, if defined, indicates that the setgroups() routine is
* available to set the list of process groups. If unavailable, multiple
diff --git a/win32/makedef.pl b/win32/makedef.pl
index 65e8023962..059fc4927d 100644
--- a/win32/makedef.pl
+++ b/win32/makedef.pl
@@ -575,6 +575,8 @@ win32_get_osfhandle
win32_ioctl
win32_utime
win32_wait
+win32_waitpid
+win32_kill
win32_str_os_error
Perl_win32_init
Perl_init_os_extras
diff --git a/win32/runperl.c b/win32/runperl.c
index 17d2ac2a57..7d49182168 100644
--- a/win32/runperl.c
+++ b/win32/runperl.c
@@ -582,7 +582,7 @@ public:
};
virtual int Kill(int pid, int sig)
{
- return kill(pid, sig);
+ return win32_kill(pid, sig);
};
virtual int Killpg(int pid, int sig)
{
@@ -627,6 +627,10 @@ public:
{
return win32_wait(status);
};
+ virtual int Waitpid(int pid, int *status, int flags)
+ {
+ return win32_waitpid(pid, status, flags);
+ };
virtual Sighandler_t Signal(int sig, Sighandler_t subcode)
{
return 0;
diff --git a/win32/win32.c b/win32/win32.c
index 3a0583c0fe..9afb0bd687 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -111,6 +111,7 @@ static BOOL has_redirection(char *ptr);
static long filetime_to_clock(PFILETIME ft);
static BOOL filetime_from_time(PFILETIME ft, time_t t);
static char * get_emd_part(char *leading, char *trailing, ...);
+static void remove_dead_process(HANDLE deceased);
HANDLE w32_perldll_handle = INVALID_HANDLE_VALUE;
static DWORD w32_platform = (DWORD)-1;
@@ -840,10 +841,30 @@ chown(const char *path, uid_t owner, gid_t group)
return 0;
}
-int
-kill(int pid, int sig)
+static void
+remove_dead_process(HANDLE deceased)
{
+#ifndef USE_RTL_WAIT
+ int child;
+ for (child = 0 ; child < w32_num_children ; ++child) {
+ if (w32_child_pids[child] == deceased) {
+ Copy(&w32_child_pids[child+1], &w32_child_pids[child],
+ (w32_num_children-child-1), HANDLE);
+ w32_num_children--;
+ break;
+ }
+ }
+#endif
+}
+
+DllExport int
+win32_kill(int pid, int sig)
+{
+#ifdef USE_RTL_WAIT
HANDLE hProcess= OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
+#else
+ HANDLE hProcess = (HANDLE) pid;
+#endif
if (hProcess == NULL) {
croak("kill process failed!\n");
@@ -852,6 +873,10 @@ kill(int pid, int sig)
if (!TerminateProcess(hProcess, sig))
croak("kill process failed!\n");
CloseHandle(hProcess);
+
+ /* WaitForMultipleObjects() on a pid that was killed returns error
+ * so if we know the pid is gone we remove it from process list */
+ remove_dead_process(hProcess);
}
return 0;
}
@@ -1050,6 +1075,24 @@ win32_utime(const char *filename, struct utimbuf *times)
}
DllExport int
+win32_waitpid(int pid, int *status, int flags)
+{
+ int rc;
+ if (pid == -1)
+ return win32_wait(status);
+ else {
+ rc = cwait(status, pid, WAIT_CHILD);
+ /* cwait() returns differently on Borland */
+#ifdef __BORLANDC__
+ if (status)
+ *status = (((*status >> 8) & 0xff) | ((*status << 8) & 0xff00));
+#endif
+ remove_dead_process((HANDLE)pid);
+ }
+ return rc >= 0 ? pid : rc;
+}
+
+DllExport int
win32_wait(int *status)
{
#ifdef USE_RTL_WAIT
@@ -1666,10 +1709,6 @@ win32_pclose(FILE *pf)
return _pclose(pf);
#else
-#ifndef USE_RTL_WAIT
- int child;
-#endif
-
int childpid, status;
SV *sv;
@@ -1687,16 +1726,7 @@ win32_pclose(FILE *pf)
win32_fclose(pf);
SvIVX(sv) = 0;
-#ifndef USE_RTL_WAIT
- for (child = 0 ; child < w32_num_children ; ++child) {
- if (w32_child_pids[child] == (HANDLE)childpid) {
- Copy(&w32_child_pids[child+1], &w32_child_pids[child],
- (w32_num_children-child-1), HANDLE);
- w32_num_children--;
- break;
- }
- }
-#endif
+ remove_dead_process((HANDLE)childpid);
/* wait for the child */
if (cwait(&status, childpid, WAIT_CHILD) == -1)
diff --git a/win32/win32iop.h b/win32/win32iop.h
index 339b7c5fb1..6f4444eb3b 100644
--- a/win32/win32iop.h
+++ b/win32/win32iop.h
@@ -123,6 +123,8 @@ DllExport int win32_stat(const char *path, struct stat *buf);
DllExport int win32_ioctl(int i, unsigned int u, char *data);
DllExport int win32_utime(const char *f, struct utimbuf *t);
DllExport int win32_wait(int *status);
+DllExport int win32_waitpid(int pid, int *status, int flags);
+DllExport int win32_kill(int pid, int sig);
#ifdef HAVE_DES_FCRYPT
DllExport char * win32_crypt(const char *txt, const char *salt);
@@ -257,6 +259,8 @@ END_EXTERN_C
#define ioctl win32_ioctl
#define utime win32_utime
#define wait win32_wait
+#define waitpid win32_waitpid
+#define kill win32_kill
#ifdef HAVE_DES_FCRYPT
#undef crypt