Commit fd40e931 authored by Johannes Kanig's avatar Johannes Kanig

use open+dup instead of freopen for usestdin in server

parent c364ad1a
...@@ -296,12 +296,15 @@ pid_t create_process(char* cmd, ...@@ -296,12 +296,15 @@ pid_t create_process(char* cmd,
setrlimit(RLIMIT_CORE,&res); setrlimit(RLIMIT_CORE,&res);
} }
if (usestdin) {
int infile = open(argv[count], O_RDONLY);
if (infile == -1) { perror("Cannot open the input file"); exit(1); }
dup2(infile, 0);
}
//adapt stdout/stderr //adapt stdout/stderr
dup2(outfile, 1); dup2(outfile, 1);
dup2(outfile, 2); dup2(outfile, 2);
if (usestdin) {
freopen(argv[argc-1], "r", stdin);
}
/* execute the command */ /* execute the command */
execvp(cmd,unix_argv); execvp(cmd,unix_argv);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment