From 779aeb5c01df88ac4ddaecbc30a230c93f000590 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Sun, 18 Jul 2010 10:19:13 +0400 Subject: [PATCH] fixed io in runnerw(PY-1305) added runner for mac --- native/runner/runneru/runneru.cpp | 50 +++++++++++++------------------ native/runner/runnerw/runnerw.cpp | 24 +++++++-------- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/native/runner/runneru/runneru.cpp b/native/runner/runneru/runneru.cpp index bb3636095d90..2bc002639b14 100644 --- a/native/runner/runneru/runneru.cpp +++ b/native/runner/runneru/runneru.cpp @@ -1,35 +1,32 @@ #include #include #include +#include #include #include -#include #include -void PrintUsage() { - printf("Usage: runnerw.exe \n"); +void print_usage() { + printf("Usage: runneru \n"); printf("where is console application and it's arguments.\n"); printf("\n"); printf( - "Runner invokes console application as a process with inherited input and output streams.\n"); + "Runner executes an application as a process with inherited input and output streams.\n"); printf( - "Input stream is scanned for presence of 2 char 255(IAC) and 243(BRK) sequence and generates Ctrl-Break event in that case.\n"); - printf( - "Also in case of all type of event(Ctrl-C, Close, Shutdown etc) Ctrl-Break event is generated."); - + "Input stream is scanned for presence of 2 char 255(IAC) and 243(BRK) sequence and generates Ctrl-C(SIGING) event in that case.\n"); + exit(0); } -void SigintHandler(int sig) +void sigint_handler(int sig) { kill(0, SIGINT); signal(SIGINT, SIG_DFL); kill(getpid(), SIGINT); } -void Break(int pid) { +void generate_break(int pid) { kill(0, SIGINT); -// kill(pid, SIGTERM); exit(0); } @@ -38,12 +35,9 @@ char BRK = 243; int main(int argc, char **argv) { if (argc < 2) { - PrintUsage(); + print_usage(); } - std::string app(argv[1]); - std::string args(""); - char* argv2[argc]; for (int i = 1; i < argc; i++) { @@ -51,16 +45,16 @@ int main(int argc, char **argv) { } argv2[argc-1]=0; - if (app.length() == 0) { - PrintUsage(); + if (strlen(argv[0]) == 0) { + print_usage(); } - int par2child[2]; /* Pipe toward child */ + int write_pipe[2]; /* Pipe toward child */ - signal(SIGINT, &SigintHandler); + signal(SIGINT, &sigint_handler); /* Open pipes */ - if (pipe(par2child) == -1) { + if (pipe(write_pipe) == -1) { perror("pipe"); exit(1); } @@ -75,27 +69,25 @@ int main(int argc, char **argv) { case 0: /* Child section */ - - if (dup2(par2child[0], STDIN_FILENO) == -1 - ) { + if (dup2(write_pipe[0], STDIN_FILENO) == -1) { perror("dup2"); exit(1); } /* Close unused fildes. */ - close(par2child[0]); - close(par2child[1]); + close(write_pipe[0]); + close(write_pipe[1]); /* Exec! */ - execv(app.c_str(), argv2); + execv(argv[0], argv2); perror("execv"); exit(1); default: - close(par2child[0]); + close(write_pipe[0]); int is_iac = 0; char buf[1]; @@ -104,7 +96,7 @@ int main(int argc, char **argv) { if (is_iac) { if (c == BRK) { - Break(pid); + generate_break(pid); } else { is_iac = 0; } @@ -113,7 +105,7 @@ int main(int argc, char **argv) { is_iac = 1; } buf[0] = c; - write(par2child[1], buf, 1); + write(write_pipe[1], buf, 1); } } diff --git a/native/runner/runnerw/runnerw.cpp b/native/runner/runnerw/runnerw.cpp index d1d8031598e7..99e46b1a681c 100644 --- a/native/runner/runnerw/runnerw.cpp +++ b/native/runner/runnerw/runnerw.cpp @@ -10,7 +10,7 @@ void PrintUsage() { printf("\n"); printf("Runner invokes console application as a process with inherited input and output streams.\n"); printf("Input stream is scanned for presence of 2 char 255(IAC) and 243(BRK) sequence and generates Ctrl-Break event in that case.\n"); - printf("Also in case of all type of event(Ctrl-C, Close, Shutdown etc) Ctrl-Break event is generated."); + printf("Also in case of all type of event(Ctrl-C, Close, Shutdown etc) Ctrl-Break event is generated.\n"); exit(0); } @@ -35,8 +35,8 @@ void CtrlBreak() { BOOL is_iac = FALSE; -char IAC = 255; -char BRK = 243; +char IAC = 'a'; +char BRK = 'b'; BOOL Scan(char buf[], int count) { for (int i = 0; i> c; +// char c = fgetc(); + buf[0] = c; + Scan(buf, 1); + WriteFile(write_stdin, buf, 1, &b_write, NULL); } CloseHandle(pi.hThread);