-void
-Process::fixFileOffsets()
-{
- auto seek = [] (FDEntry *fde)
- {
- if (lseek(fde->fd, fde->fileOffset, SEEK_SET) < 0)
- fatal("Unable to see to location in %s", fde->filename);
- };
-
- std::map<string,int>::iterator it;
-
- // Search through the input options and set fd if match is found;
- // otherwise, open an input file and seek to location.
- FDEntry *fde_stdin = getFDEntry(STDIN_FILENO);
-
- // Check if user has specified a different input file, and if so, use it
- // instead of the file specified in the checkpoint. This also resets the
- // file offset from the checkpointed value
- string new_in = ((ProcessParams*)params())->input;
- if (new_in != fde_stdin->filename) {
- warn("Using new input file (%s) rather than checkpointed (%s)\n",
- new_in, fde_stdin->filename);
- fde_stdin->filename = new_in;
- fde_stdin->fileOffset = 0;
- }
-
- if ((it = imap.find(fde_stdin->filename)) != imap.end()) {
- fde_stdin->fd = it->second;
- } else {
- fde_stdin->fd = openInputFile(fde_stdin->filename);
- seek(fde_stdin);
- }
-
- // Search through the output/error options and set fd if match is found;
- // otherwise, open an output file and seek to location.
- FDEntry *fde_stdout = getFDEntry(STDOUT_FILENO);
-
- // Check if user has specified a different output file, and if so, use it
- // instead of the file specified in the checkpoint. This also resets the
- // file offset from the checkpointed value
- string new_out = ((ProcessParams*)params())->output;
- if (new_out != fde_stdout->filename) {
- warn("Using new output file (%s) rather than checkpointed (%s)\n",
- new_out, fde_stdout->filename);
- fde_stdout->filename = new_out;
- fde_stdout->fileOffset = 0;
- }
-
- if ((it = oemap.find(fde_stdout->filename)) != oemap.end()) {
- fde_stdout->fd = it->second;
- } else {
- fde_stdout->fd = openOutputFile(fde_stdout->filename);
- seek(fde_stdout);
- }
-
- FDEntry *fde_stderr = getFDEntry(STDERR_FILENO);
-
- // Check if user has specified a different error file, and if so, use it
- // instead of the file specified in the checkpoint. This also resets the
- // file offset from the checkpointed value
- string new_err = ((ProcessParams*)params())->errout;
- if (new_err != fde_stderr->filename) {
- warn("Using new error file (%s) rather than checkpointed (%s)\n",
- new_err, fde_stderr->filename);
- fde_stderr->filename = new_err;
- fde_stderr->fileOffset = 0;
- }
-
- if (fde_stdout->filename == fde_stderr->filename) {
- // Reuse the same file descriptor if these match.
- fde_stderr->fd = fde_stdout->fd;
- } else if ((it = oemap.find(fde_stderr->filename)) != oemap.end()) {
- fde_stderr->fd = it->second;
- } else {
- fde_stderr->fd = openOutputFile(fde_stderr->filename);
- seek(fde_stderr);
- }
-
- for (int tgt_fd = 3; tgt_fd < fd_array->size(); tgt_fd++) {
- FDEntry *fde = getFDEntry(tgt_fd);
- if (fde->fd == -1)
- continue;
-
- if (fde->isPipe) {
- if (fde->filename == "PIPE-WRITE")
- continue;
- assert(fde->filename == "PIPE-READ");
-
- int fds[2];
- if (pipe(fds) < 0)
- fatal("Unable to create new pipe");
-
- fde->fd = fds[0];
-
- FDEntry *fde_write = getFDEntry(fde->readPipeSource);
- assert(fde_write->filename == "PIPE-WRITE");
- fde_write->fd = fds[1];
- } else {
- fde->fd = openFile(fde->filename.c_str(), fde->flags, fde->mode);
- seek(fde);
- }
- }
-}
-
-void
-Process::findFileOffsets()
-{
- for (auto& fde : *fd_array) {
- if (fde.fd != -1)
- fde.fileOffset = lseek(fde.fd, 0, SEEK_CUR);
- }
-}
-
-void
-Process::setReadPipeSource(int read_pipe_fd, int source_fd)
-{
- FDEntry *fde = getFDEntry(read_pipe_fd);
- assert(source_fd >= -1);
- fde->readPipeSource = source_fd;
-}
-