process.cc (5512:755fcaf7a4cf) process.cc (5514:9a903bf83a33)
1/*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 78 unchanged lines hidden (view full) ---

87int num_processes = 0;
88
89Process::Process(ProcessParams * params)
90 : SimObject(params), system(params->system), checkpointRestored(false),
91 max_stack_size(params->max_stack_size)
92{
93 string in = params->input;
94 string out = params->output;
1/*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 78 unchanged lines hidden (view full) ---

87int num_processes = 0;
88
89Process::Process(ProcessParams * params)
90 : SimObject(params), system(params->system), checkpointRestored(false),
91 max_stack_size(params->max_stack_size)
92{
93 string in = params->input;
94 string out = params->output;
95 string err = params->errout;
95
96 // initialize file descriptors to default: same as simulator
97 int stdin_fd, stdout_fd, stderr_fd;
98
99 if (in == "stdin" || in == "cin")
100 stdin_fd = STDIN_FILENO;
101 else if (in == "None")
102 stdin_fd = -1;

--- 4 unchanged lines hidden (view full) ---

107 stdout_fd = STDOUT_FILENO;
108 else if (out == "stderr" || out == "cerr")
109 stdout_fd = STDERR_FILENO;
110 else if (out == "None")
111 stdout_fd = -1;
112 else
113 stdout_fd = Process::openOutputFile(out);
114
96
97 // initialize file descriptors to default: same as simulator
98 int stdin_fd, stdout_fd, stderr_fd;
99
100 if (in == "stdin" || in == "cin")
101 stdin_fd = STDIN_FILENO;
102 else if (in == "None")
103 stdin_fd = -1;

--- 4 unchanged lines hidden (view full) ---

108 stdout_fd = STDOUT_FILENO;
109 else if (out == "stderr" || out == "cerr")
110 stdout_fd = STDERR_FILENO;
111 else if (out == "None")
112 stdout_fd = -1;
113 else
114 stdout_fd = Process::openOutputFile(out);
115
115 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
116 if (err == "stdout" || err == "cout")
117 stderr_fd = STDOUT_FILENO;
118 else if (err == "stderr" || err == "cerr")
119 stderr_fd = STDERR_FILENO;
120 else if (err == "None")
121 stderr_fd = -1;
122 else if (err == out)
123 stderr_fd = stdout_fd;
124 else
125 stderr_fd = Process::openOutputFile(err);
116
117 M5_pid = system->allocatePID();
118 // initialize first 3 fds (stdin, stdout, stderr)
119 Process::FdMap *fdo = &fd_map[STDIN_FILENO];
120 fdo->fd = stdin_fd;
121 fdo->filename = in;
122 fdo->flags = O_RDONLY;
123 fdo->mode = -1;
124 fdo->fileOffset = 0;
125
126 fdo = &fd_map[STDOUT_FILENO];
127 fdo->fd = stdout_fd;
128 fdo->filename = out;
129 fdo->flags = O_WRONLY | O_CREAT | O_TRUNC;
130 fdo->mode = 0774;
131 fdo->fileOffset = 0;
132
133 fdo = &fd_map[STDERR_FILENO];
134 fdo->fd = stderr_fd;
126
127 M5_pid = system->allocatePID();
128 // initialize first 3 fds (stdin, stdout, stderr)
129 Process::FdMap *fdo = &fd_map[STDIN_FILENO];
130 fdo->fd = stdin_fd;
131 fdo->filename = in;
132 fdo->flags = O_RDONLY;
133 fdo->mode = -1;
134 fdo->fileOffset = 0;
135
136 fdo = &fd_map[STDOUT_FILENO];
137 fdo->fd = stdout_fd;
138 fdo->filename = out;
139 fdo->flags = O_WRONLY | O_CREAT | O_TRUNC;
140 fdo->mode = 0774;
141 fdo->fileOffset = 0;
142
143 fdo = &fd_map[STDERR_FILENO];
144 fdo->fd = stderr_fd;
135 fdo->filename = "STDERR";
145 fdo->filename = err;
136 fdo->flags = O_WRONLY;
137 fdo->mode = -1;
138 fdo->fileOffset = 0;
139
140
141 // mark remaining fds as free
142 for (int i = 3; i <= MAX_FD; ++i) {
143 Process::FdMap *fdo = &fd_map[i];

--- 34 unchanged lines hidden (view full) ---

178
179 return fd;
180}
181
182
183int
184Process::openOutputFile(const string &filename)
185{
146 fdo->flags = O_WRONLY;
147 fdo->mode = -1;
148 fdo->fileOffset = 0;
149
150
151 // mark remaining fds as free
152 for (int i = 3; i <= MAX_FD; ++i) {
153 Process::FdMap *fdo = &fd_map[i];

--- 34 unchanged lines hidden (view full) ---

188
189 return fd;
190}
191
192
193int
194Process::openOutputFile(const string &filename)
195{
186 int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0774);
196 int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0664);
187
188 if (fd == -1) {
189 perror(NULL);
190 cerr << "unable to open \"" << filename << "\" for writing\n";
191 fatal("can't open output file");
192 }
193
194 return fd;

--- 155 unchanged lines hidden (view full) ---

350 // find all offsets for currently open files and save them
351void
352Process::fix_file_offsets() {
353 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO];
354 Process::FdMap *fdo_stdout = &fd_map[STDOUT_FILENO];
355 Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO];
356 string in = fdo_stdin->filename;
357 string out = fdo_stdout->filename;
197
198 if (fd == -1) {
199 perror(NULL);
200 cerr << "unable to open \"" << filename << "\" for writing\n";
201 fatal("can't open output file");
202 }
203
204 return fd;

--- 155 unchanged lines hidden (view full) ---

360 // find all offsets for currently open files and save them
361void
362Process::fix_file_offsets() {
363 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO];
364 Process::FdMap *fdo_stdout = &fd_map[STDOUT_FILENO];
365 Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO];
366 string in = fdo_stdin->filename;
367 string out = fdo_stdout->filename;
368 string err = fdo_stderr->filename;
358
359 // initialize file descriptors to default: same as simulator
360 int stdin_fd, stdout_fd, stderr_fd;
361
362 if (in == "stdin" || in == "cin")
363 stdin_fd = STDIN_FILENO;
364 else if (in == "None")
365 stdin_fd = -1;

--- 7 unchanged lines hidden (view full) ---

373 if (out == "stdout" || out == "cout")
374 stdout_fd = STDOUT_FILENO;
375 else if (out == "stderr" || out == "cerr")
376 stdout_fd = STDERR_FILENO;
377 else if (out == "None")
378 stdout_fd = -1;
379 else{
380 stdout_fd = Process::openOutputFile(out);
369
370 // initialize file descriptors to default: same as simulator
371 int stdin_fd, stdout_fd, stderr_fd;
372
373 if (in == "stdin" || in == "cin")
374 stdin_fd = STDIN_FILENO;
375 else if (in == "None")
376 stdin_fd = -1;

--- 7 unchanged lines hidden (view full) ---

384 if (out == "stdout" || out == "cout")
385 stdout_fd = STDOUT_FILENO;
386 else if (out == "stderr" || out == "cerr")
387 stdout_fd = STDERR_FILENO;
388 else if (out == "None")
389 stdout_fd = -1;
390 else{
391 stdout_fd = Process::openOutputFile(out);
381 if (lseek(stdin_fd, fdo_stdout->fileOffset, SEEK_SET) < 0)
382 panic("Unable to seek to correct in file: %s", out);
392 if (lseek(stdout_fd, fdo_stdout->fileOffset, SEEK_SET) < 0)
393 panic("Unable to seek to correct location in file: %s", out);
383 }
384
394 }
395
385 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
396 if (err == "stdout" || err == "cout")
397 stderr_fd = STDOUT_FILENO;
398 else if (err == "stderr" || err == "cerr")
399 stderr_fd = STDERR_FILENO;
400 else if (err == "None")
401 stderr_fd = -1;
402 else if (err == out)
403 stderr_fd = stdout_fd;
404 else {
405 stderr_fd = Process::openOutputFile(err);
406 if (lseek(stderr_fd, fdo_stderr->fileOffset, SEEK_SET) < 0)
407 panic("Unable to seek to correct location in file: %s", err);
408 }
386
387 fdo_stdin->fd = stdin_fd;
388 fdo_stdout->fd = stdout_fd;
389 fdo_stderr->fd = stderr_fd;
390
391
392 for (int free_fd = 3; free_fd <= MAX_FD; ++free_fd) {
393 Process::FdMap *fdo = &fd_map[free_fd];

--- 340 unchanged lines hidden ---
409
410 fdo_stdin->fd = stdin_fd;
411 fdo_stdout->fd = stdout_fd;
412 fdo_stderr->fd = stderr_fd;
413
414
415 for (int free_fd = 3; free_fd <= MAX_FD; ++free_fd) {
416 Process::FdMap *fdo = &fd_map[free_fd];

--- 340 unchanged lines hidden ---