summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Adler <Michael.Adler@intel.com>2008-07-23 14:41:34 -0700
committerMichael Adler <Michael.Adler@intel.com>2008-07-23 14:41:34 -0700
commit5f42bfcd56c84f6fe938b88411265359fc702110 (patch)
treea075741ec0d18af15c7a4b1c4aef23091706b4f8 /src
parent2cd04fd6da67d874fd4e563ed05707a42ff0598f (diff)
downloadgem5-5f42bfcd56c84f6fe938b88411265359fc702110.tar.xz
process: separate stderr from stdout
- Add the option of redirecting stderr to a file. With the old behaviour, stderr would follow stdout if stdout was to a file, but stderr went to the host stderr if stdout went to the host stdout. The new default maintains stdout and stderr going to the host. Now the two can specify different files, but they will share a file descriptor if the name of the files is the same. - Add --output and --errout options to se.py to go with --input.
Diffstat (limited to 'src')
-rw-r--r--src/sim/Process.py3
-rw-r--r--src/sim/process.cc35
2 files changed, 31 insertions, 7 deletions
diff --git a/src/sim/Process.py b/src/sim/Process.py
index 37a27bf3b..81108dd70 100644
--- a/src/sim/Process.py
+++ b/src/sim/Process.py
@@ -34,7 +34,8 @@ class Process(SimObject):
type = 'Process'
abstract = True
input = Param.String('cin', "filename for stdin")
- output = Param.String('cout', 'filename for stdout/stderr')
+ output = Param.String('cout', 'filename for stdout')
+ errout = Param.String('cerr', 'filename for stderr')
system = Param.System(Parent.any, "system process will run on")
max_stack_size = Param.MemorySize('64MB', 'maximum size of the stack')
diff --git a/src/sim/process.cc b/src/sim/process.cc
index 046a6bf9b..23e890b06 100644
--- a/src/sim/process.cc
+++ b/src/sim/process.cc
@@ -92,6 +92,7 @@ Process::Process(ProcessParams * params)
{
string in = params->input;
string out = params->output;
+ string err = params->errout;
// initialize file descriptors to default: same as simulator
int stdin_fd, stdout_fd, stderr_fd;
@@ -112,7 +113,16 @@ Process::Process(ProcessParams * params)
else
stdout_fd = Process::openOutputFile(out);
- stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
+ if (err == "stdout" || err == "cout")
+ stderr_fd = STDOUT_FILENO;
+ else if (err == "stderr" || err == "cerr")
+ stderr_fd = STDERR_FILENO;
+ else if (err == "None")
+ stderr_fd = -1;
+ else if (err == out)
+ stderr_fd = stdout_fd;
+ else
+ stderr_fd = Process::openOutputFile(err);
M5_pid = system->allocatePID();
// initialize first 3 fds (stdin, stdout, stderr)
@@ -132,7 +142,7 @@ Process::Process(ProcessParams * params)
fdo = &fd_map[STDERR_FILENO];
fdo->fd = stderr_fd;
- fdo->filename = "STDERR";
+ fdo->filename = err;
fdo->flags = O_WRONLY;
fdo->mode = -1;
fdo->fileOffset = 0;
@@ -183,7 +193,7 @@ Process::openInputFile(const string &filename)
int
Process::openOutputFile(const string &filename)
{
- int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0774);
+ int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0664);
if (fd == -1) {
perror(NULL);
@@ -355,6 +365,7 @@ Process::fix_file_offsets() {
Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO];
string in = fdo_stdin->filename;
string out = fdo_stdout->filename;
+ string err = fdo_stderr->filename;
// initialize file descriptors to default: same as simulator
int stdin_fd, stdout_fd, stderr_fd;
@@ -378,11 +389,23 @@ Process::fix_file_offsets() {
stdout_fd = -1;
else{
stdout_fd = Process::openOutputFile(out);
- if (lseek(stdin_fd, fdo_stdout->fileOffset, SEEK_SET) < 0)
- panic("Unable to seek to correct in file: %s", out);
+ if (lseek(stdout_fd, fdo_stdout->fileOffset, SEEK_SET) < 0)
+ panic("Unable to seek to correct location in file: %s", out);
}
- stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
+ if (err == "stdout" || err == "cout")
+ stderr_fd = STDOUT_FILENO;
+ else if (err == "stderr" || err == "cerr")
+ stderr_fd = STDERR_FILENO;
+ else if (err == "None")
+ stderr_fd = -1;
+ else if (err == out)
+ stderr_fd = stdout_fd;
+ else {
+ stderr_fd = Process::openOutputFile(err);
+ if (lseek(stderr_fd, fdo_stderr->fileOffset, SEEK_SET) < 0)
+ panic("Unable to seek to correct location in file: %s", err);
+ }
fdo_stdin->fd = stdin_fd;
fdo_stdout->fd = stdout_fd;