Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
KWSys
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rolf Eike Beer
KWSys
Commits
e47368de
Commit
e47368de
authored
21 years ago
by
Brad King
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Cleaned up implementation of stderr and win9x forwarding executable error pipe.
parent
9f9a81da
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ProcessWin32.c
+39
-74
39 additions, 74 deletions
ProcessWin32.c
with
39 additions
and
74 deletions
ProcessWin32.c
+
39
−
74
View file @
e47368de
...
...
@@ -66,8 +66,9 @@ typedef struct kwsysProcessCreateInformation_s
/* Windows child startup control data. */
STARTUPINFO
StartupInfo
;
/* Inherited pipe handles. */
HANDLE
InheritedWrite
[
KWSYSPE_PIPE_COUNT
];
/* Special error reporting pipe for Win9x forwarding executable. */
HANDLE
ErrorPipeRead
;
HANDLE
ErrorPipeWrite
;
}
kwsysProcessCreateInformation
;
/*--------------------------------------------------------------------------*/
...
...
@@ -822,42 +823,27 @@ void kwsysProcess_Execute(kwsysProcess* cp)
/* Connect the child's output pipes to the threads. */
si
.
StartupInfo
.
dwFlags
=
STARTF_USESTDHANDLES
;
/* Create pipes to be shared by all processes in the pipeline. */
for
(
i
=
KWSYSPE_PIPE_STDERR
;
i
<
KWSYSPE_PIPE_COUNT
;
++
i
)
/* Create stderr pipe to be shared by all processes in the pipeline.
Neither end is directly inherited. */
if
(
!
CreatePipe
(
&
cp
->
Pipe
[
KWSYSPE_PIPE_STDERR
].
Read
,
&
cp
->
Pipe
[
KWSYSPE_PIPE_STDERR
].
Write
,
0
,
0
))
{
/* Create a pipe. Neither end is directly inherited. */
if
(
!
CreatePipe
(
&
cp
->
Pipe
[
i
].
Read
,
&
cp
->
Pipe
[
i
].
Write
,
0
,
0
))
{
kwsysProcessCleanup
(
cp
,
1
);
for
(
i
=
0
;
i
<
KWSYSPE_PIPE_COUNT
;
++
i
)
{
kwsysProcessCleanupHandle
(
&
si
.
InheritedWrite
[
i
]);
}
return
;
}
kwsysProcessCleanup
(
cp
,
1
);
return
;
}
/* Create an inherited duplicate of the write end, but do not
close the non-inherited version. We need to keep it open
to use in waking up the pipe threads. */
if
(
!
DuplicateHandle
(
GetCurrentProcess
(),
cp
->
Pipe
[
i
].
Write
,
GetCurrentProcess
(),
&
si
.
InheritedWrite
[
i
],
0
,
TRUE
,
DUPLICATE_SAME_ACCESS
))
{
/* Write end is already closed. */
cp
->
Pipe
[
i
].
Write
=
0
;
kwsysProcessCleanup
(
cp
,
1
);
for
(
i
=
0
;
i
<
KWSYSPE_PIPE_COUNT
;
++
i
)
{
kwsysProcessCleanupHandle
(
&
si
.
InheritedWrite
[
i
]);
}
return
;
}
/* Create an inherited duplicate of the write end, but do not
close the non-inherited version. We need to keep it open
to use in waking up the pipe threads. */
if
(
!
DuplicateHandle
(
GetCurrentProcess
(),
cp
->
Pipe
[
KWSYSPE_PIPE_STDERR
].
Write
,
GetCurrentProcess
(),
&
si
.
StartupInfo
.
hStdError
,
0
,
TRUE
,
DUPLICATE_SAME_ACCESS
))
{
kwsysProcessCleanup
(
cp
,
1
);
kwsysProcessCleanupHandle
(
&
si
.
StartupInfo
.
hStdError
);
return
;
}
/* All children will share the stderr pipe. */
si
.
StartupInfo
.
hStdError
=
si
.
InheritedWrite
[
KWSYSPE_PIPE_STDERR
];
/* Create the pipeline of processes. */
{
HANDLE
readEnd
=
0
;
...
...
@@ -879,10 +865,9 @@ void kwsysProcess_Execute(kwsysProcess* cp)
kwsysProcessCleanupHandle
(
&
si
.
StartupInfo
.
hStdInput
);
}
kwsysProcessCleanupHandle
(
&
si
.
StartupInfo
.
hStdOutput
);
for
(
i
=
0
;
i
<
KWSYSPE_PIPE_COUNT
;
++
i
)
{
kwsysProcessCleanupHandle
(
&
si
.
InheritedWrite
[
i
]);
}
kwsysProcessCleanupHandle
(
&
si
.
StartupInfo
.
hStdError
);
kwsysProcessCleanupHandle
(
&
si
.
ErrorPipeRead
);
kwsysProcessCleanupHandle
(
&
si
.
ErrorPipeWrite
);
return
;
}
}
...
...
@@ -891,12 +876,9 @@ void kwsysProcess_Execute(kwsysProcess* cp)
cp
->
Pipe
[
KWSYSPE_PIPE_STDOUT
].
Read
=
readEnd
;
}
/* Close the inherited handles to the pipes shared by all processes
in the pipeline. */
for
(
i
=
0
;
i
<
KWSYSPE_PIPE_COUNT
;
++
i
)
{
kwsysProcessCleanupHandle
(
&
si
.
InheritedWrite
[
i
]);
}
/* Close the inherited handles to the stderr pipe shared by all
processes in the pipeline. */
kwsysProcessCleanupHandle
(
&
si
.
StartupInfo
.
hStdError
);
/* The timeout period starts now. */
cp
->
StartTime
=
kwsysProcessTimeGetCurrent
();
...
...
@@ -1360,9 +1342,6 @@ int kwsysProcessCreate(kwsysProcess* cp, int index,
kwsysProcessCreateInformation
*
si
,
PHANDLE
readEnd
)
{
HANDLE
errorWriteEnd
=
0
;
HANDLE
errorReadEnd
=
0
;
/* Setup the process's stdin. */
if
(
*
readEnd
)
{
...
...
@@ -1388,6 +1367,7 @@ int kwsysProcessCreate(kwsysProcess* cp, int index,
/* Setup the process's stdout. */
{
DWORD
maybeClose
=
DUPLICATE_CLOSE_SOURCE
;
HANDLE
writeEnd
;
/* Create the output pipe for this process. Neither end is directly
...
...
@@ -1403,25 +1383,14 @@ int kwsysProcessCreate(kwsysProcess* cp, int index,
if
(
index
==
cp
->
NumberOfCommands
-
1
)
{
cp
->
Pipe
[
KWSYSPE_PIPE_STDOUT
].
Write
=
writeEnd
;
if
(
!
DuplicateHandle
(
GetCurrentProcess
(),
writeEnd
,
GetCurrentProcess
(),
&
writeEnd
,
0
,
TRUE
,
DUPLICATE_SAME_ACCESS
))
{
return
0
;
}
maybeClose
=
0
;
}
else
if
(
!
DuplicateHandle
(
GetCurrentProcess
(),
writeEnd
,
GetCurrentProcess
(),
&
si
->
StartupInfo
.
hStdOutput
,
0
,
TRUE
,
(
maybeClose
|
DUPLICATE_SAME_ACCESS
)))
{
if
(
!
DuplicateHandle
(
GetCurrentProcess
(),
writeEnd
,
GetCurrentProcess
(),
&
writeEnd
,
0
,
TRUE
,
(
DUPLICATE_CLOSE_SOURCE
|
DUPLICATE_SAME_ACCESS
)))
{
return
0
;
}
return
0
;
}
si
->
StartupInfo
.
hStdOutput
=
writeEnd
;
}
/* Create the child process. */
...
...
@@ -1432,19 +1401,18 @@ int kwsysProcessCreate(kwsysProcess* cp, int index,
{
/* Create an error reporting pipe for the forwarding executable.
Neither end is directly inherited. */
if
(
!
CreatePipe
(
&
errorReadEnd
,
&
error
Write
End
,
0
,
0
))
if
(
!
CreatePipe
(
&
si
->
ErrorPipeRead
,
&
si
->
ErrorPipe
Write
,
0
,
0
))
{
return
0
;
}
/* Create an inherited duplicate of the write end. This also closes
the non-inherited version. */
if
(
!
DuplicateHandle
(
GetCurrentProcess
(),
error
Write
End
,
GetCurrentProcess
(),
&
error
Write
End
,
if
(
!
DuplicateHandle
(
GetCurrentProcess
(),
si
->
ErrorPipe
Write
,
GetCurrentProcess
(),
&
si
->
ErrorPipe
Write
,
0
,
TRUE
,
(
DUPLICATE_CLOSE_SOURCE
|
DUPLICATE_SAME_ACCESS
)))
{
CloseHandle
(
errorReadEnd
);
return
0
;
}
...
...
@@ -1453,12 +1421,10 @@ int kwsysProcessCreate(kwsysProcess* cp, int index,
realCommand
=
malloc
(
strlen
(
cp
->
Win9x
)
+
strlen
(
cp
->
Commands
[
index
])
+
100
);
if
(
!
realCommand
)
{
CloseHandle
(
errorWriteEnd
);
CloseHandle
(
errorReadEnd
);
return
0
;
}
sprintf
(
realCommand
,
"%s %p %p %p %d %s"
,
cp
->
Win9x
,
error
Write
End
,
cp
->
Win9xResumeEvent
,
cp
->
Win9xKillEvent
,
si
->
ErrorPipe
Write
,
cp
->
Win9xResumeEvent
,
cp
->
Win9xKillEvent
,
cp
->
HideWindow
,
cp
->
Commands
[
index
]);
}
else
...
...
@@ -1480,7 +1446,7 @@ int kwsysProcessCreate(kwsysProcess* cp, int index,
/* Close the error pipe write end so we can detect when the
forwarding executable closes it. */
CloseHandle
(
error
Write
End
);
kwsysProcessCleanupHandle
(
&
si
->
ErrorPipe
Write
);
if
(
r
)
{
/* Wait for the forwarding executable to report an error or
...
...
@@ -1489,7 +1455,7 @@ int kwsysProcessCreate(kwsysProcess* cp, int index,
DWORD
n
=
1
;
while
(
total
<
KWSYSPE_PIPE_BUFFER_SIZE
&&
n
>
0
)
{
if
(
ReadFile
(
errorReadEn
d
,
cp
->
ErrorMessage
+
total
,
if
(
ReadFile
(
si
->
ErrorPipeRea
d
,
cp
->
ErrorMessage
+
total
,
KWSYSPE_PIPE_BUFFER_SIZE
-
total
,
&
n
,
0
))
{
total
+=
n
;
...
...
@@ -1508,12 +1474,11 @@ int kwsysProcessCreate(kwsysProcess* cp, int index,
DWORD
error
=
GetLastError
();
kwsysProcessCleanupHandle
(
&
cp
->
ProcessInformation
[
index
].
hThread
);
kwsysProcessCleanupHandle
(
&
cp
->
ProcessInformation
[
index
].
hProcess
);
CloseHandle
(
errorReadEnd
);
SetLastError
(
error
);
return
0
;
}
}
CloseHandle
(
errorReadEn
d
);
kwsysProcessCleanupHandle
(
&
si
->
ErrorPipeRea
d
);
}
if
(
!
r
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment