Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
75af5340
Commit
75af5340
authored
Aug 04, 2008
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed handle inheritance and closing in win32 cli wrapper
parent
b4a2a1a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
22 deletions
+27
-22
src/cli/cli_main.cpp
src/cli/cli_main.cpp
+1
-1
src/cli/text_io_handler.cpp
src/cli/text_io_handler.cpp
+2
-2
src/cli/win32_cli_wrapper.cpp
src/cli/win32_cli_wrapper.cpp
+24
-19
No files found.
src/cli/cli_main.cpp
View file @
75af5340
...
...
@@ -69,7 +69,6 @@ void CLISetInterface::run() {
// loop
running
=
true
;
while
(
running
)
{
if
(
!
cli
.
canGetLine
())
break
;
// show prompt
if
(
!
quiet
)
{
cli
<<
GRAY
<<
_
(
"> "
)
<<
NORMAL
;
...
...
@@ -77,6 +76,7 @@ void CLISetInterface::run() {
}
// read line from stdin
String
command
=
cli
.
getLine
();
if
(
command
.
empty
()
&&
!
cli
.
canGetLine
())
break
;
handleCommand
(
command
);
cli
.
flush
();
cli
.
flushRaw
();
...
...
src/cli/text_io_handler.cpp
View file @
75af5340
...
...
@@ -141,9 +141,9 @@ void TextIOHandler::flushRaw() {
if
(
!
buffer
.
empty
())
{
#ifdef UNICODE
wxCharBuffer
buf
=
buffer
.
mb_str
(
wxConvUTF8
);
puts
(
buf
);
fputs
(
buf
,
stdout
);
#else
puts
(
buffer
.
c_str
()
);
fputs
(
buffer
.
c_str
(),
stdout
);
#endif
}
fflush
(
stdout
);
...
...
src/cli/win32_cli_wrapper.cpp
View file @
75af5340
...
...
@@ -35,7 +35,7 @@
/// How to transfer data from one handle to another
struct
Transfer
{
HANDLE
from
,
to
;
HANDLE
from
,
&
to
;
bool
escapes
;
};
...
...
@@ -103,16 +103,10 @@ int main(int argc, char** argv) {
// Ctrl+C handler
SetConsoleCtrlHandler
(
HandleCtrlEvent
,
TRUE
);
// inheritable handles
SECURITY_ATTRIBUTES
inherit
;
inherit
.
nLength
=
sizeof
(
inherit
);
inherit
.
bInheritHandle
=
true
;
inherit
.
lpSecurityDescriptor
=
NULL
;
// create pipes
CreatePipe
(
&
in_theirs
,
&
in_mine
,
&
inherit
,
0
);
CreatePipe
(
&
out_mine
,
&
out_theirs
,
&
inherit
,
0
);
CreatePipe
(
&
err_mine
,
&
err_theirs
,
&
inherit
,
0
);
CreatePipe
(
&
in_theirs
,
&
in_mine
,
NULL
,
0
);
CreatePipe
(
&
out_mine
,
&
out_theirs
,
NULL
,
0
);
CreatePipe
(
&
err_mine
,
&
err_theirs
,
NULL
,
0
);
// the actual handles
in_real
=
GetStdHandle
(
STD_INPUT_HANDLE
);
...
...
@@ -128,10 +122,11 @@ int main(int argc, char** argv) {
CreateThread
(
NULL
,
0
,(
LPTHREAD_START_ROUTINE
)
TransferThread
,
&
tranfer_out
,
0
,
NULL
);
CreateThread
(
NULL
,
0
,(
LPTHREAD_START_ROUTINE
)
TransferThread
,
&
tranfer_err
,
0
,
NULL
);
// give handles to child process
child_startup_info
.
hStdInput
=
in_theirs
;
child_startup_info
.
hStdOutput
=
out_theirs
;
child_startup_info
.
hStdError
=
err_theirs
;
// give (inheritable copies of) handles to child process
HANDLE
me
=
GetCurrentProcess
();
DuplicateHandle
(
me
,
in_theirs
,
me
,
&
child_startup_info
.
hStdInput
,
0
,
TRUE
,
DUPLICATE_CLOSE_SOURCE
|
DUPLICATE_SAME_ACCESS
);
DuplicateHandle
(
me
,
out_theirs
,
me
,
&
child_startup_info
.
hStdOutput
,
0
,
TRUE
,
DUPLICATE_CLOSE_SOURCE
|
DUPLICATE_SAME_ACCESS
);
DuplicateHandle
(
me
,
err_theirs
,
me
,
&
child_startup_info
.
hStdError
,
0
,
TRUE
,
DUPLICATE_CLOSE_SOURCE
|
DUPLICATE_SAME_ACCESS
);
child_startup_info
.
dwFlags
=
STARTF_USESTDHANDLES
;
}
...
...
@@ -159,9 +154,13 @@ BOOL WINAPI HandleCtrlEvent(DWORD type) {
DWORD
exit_code
=
1
;
// try to exit child process cleanly
// TODO: don't exit child on Ctrl+C
CopyFileBuffer
(
in_mine
,
":quit
\n
"
,
6
);
CopyFileBuffer
(
out_real
,
":quit
\n
"
,
6
);
if
(
WaitForSingleObject
(
child_process_info
.
hProcess
,
100
)
==
WAIT_OBJECT_0
)
{
bool
wait
=
false
;
if
(
in_mine
!=
INVALID_HANDLE_VALUE
)
{
CopyFileBuffer
(
in_mine
,
":quit
\n
"
,
6
);
CopyFileBuffer
(
out_real
,
":quit
\n
"
,
6
);
wait
=
true
;
}
if
(
wait
&&
WaitForSingleObject
(
child_process_info
.
hProcess
,
100
)
==
WAIT_OBJECT_0
)
{
GetExitCodeProcess
(
child_process_info
.
hProcess
,
&
exit_code
);
}
else
{
TerminateProcess
(
child_process_info
.
hProcess
,
1
);
...
...
@@ -177,7 +176,7 @@ BOOL WINAPI HandleCtrlEvent(DWORD type) {
void
CopyFileBuffer
(
HANDLE
output
,
char
*
buffer
,
DWORD
size
)
{
DWORD
pos
=
0
,
bytes_written
;
while
(
pos
<
size
)
{
WriteFile
(
output
,
buffer
+
pos
,
size
-
pos
,
&
bytes_written
,
NULL
);
WriteFile
(
output
,
buffer
+
pos
,
size
-
pos
,
&
bytes_written
,
NULL
);
pos
+=
bytes_written
;
}
}
...
...
@@ -223,7 +222,13 @@ DWORD WINAPI TransferThread(Transfer* transfer) {
// read
char
buffer
[
1024
];
DWORD
bytes_read
;
ReadFile
(
transfer
->
from
,
buffer
,
sizeof
(
buffer
),
&
bytes_read
,
NULL
);
BOOL
ok
=
ReadFile
(
transfer
->
from
,
buffer
,
sizeof
(
buffer
),
&
bytes_read
,
NULL
);
if
(
ok
&&
bytes_read
==
0
)
{
// end of file: close handle
CloseHandle
(
transfer
->
to
);
transfer
->
to
=
INVALID_HANDLE_VALUE
;
break
;
}
// write
CopyFileBufferWithEscape
(
transfer
->
to
,
buffer
,
bytes_read
,
transfer
->
escapes
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment