- Timestamp:
- 2010-05-26T23:52:09+12:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/runtime-src/src/recpt/os_process_unix.cpp
r22174 r22177 41 41 #include "os_process_unix.h" 42 42 43 #define READ_PIPE_INDEX 044 #define WRITE_PIPE_INDEX 145 46 #define FD_STDIN 047 #define FD_STDOUT 148 #define FD_STDERR 249 50 osprocessunix::osprocessunix(char* cmdline)51 : osprocess(cmdline)52 {}53 54 43 osprocessunix::osprocessunix(char* cmdline, OSProcessPipeMode mode) 55 44 : child_stdout_read_(-1), child_stdin_write_(-1), … … 81 70 82 71 83 pid_ t pid= fork();84 if (pid < 0) {72 pid_ = fork(); 73 if (pid_ < 0) { 85 74 cerr << "osprocessunix::osprocessunix(): Failed to create child process" << endl; 86 75 return; 87 76 } 88 77 89 if (pid == 0) {78 if (pid_ == 0) { 90 79 // Child process 91 80 92 81 // Sort out input pipe 93 82 // child has no buisness accessing write end of input pipe => close 94 ::close(child_stdin_write_); 83 ::close(child_stdin_write_); 84 child_stdin_write_=-1; 95 85 96 86 if ((mode == uniWrite) || (mode == biReadWrite)) { … … 99 89 } 100 90 else { 101 // noPipe or (parent is doing) uniRead (which means we're not interested102 // in the child reading any input from the parent )91 // Parent is doing uniRead, which means we're not interested 92 // in the child reading any input from the parent 103 93 // => child input remains coming from stdin 104 94 ::close(child_stdin_read); … … 108 98 // child has no buisness accessing read end of output pipe => close 109 99 ::close(child_stdout_read_); 100 child_stdout_read_=-1; 101 110 102 if ((mode == uniRead) || (mode == biReadWrite)) { 111 103 // wire up child's stdout write so it is send down the pipe to the parent … … 113 105 } 114 106 else { 115 // noPipe or (parent is doing) uniWrite (which means we're not interested116 // in any output produced by the child process )107 // Parent is doing uniWrite, which means we're not interested 108 // in any output produced by the child process 117 109 // => child output remains going to stdout 118 110 ::close(child_stdout_write); 119 111 } 120 112 121 /* 122 // execve ... 123 int rv = CreateProcess(NULL, // no application name 124 cmdline, 125 NULL, 126 NULL, // no process or thread security attribues 127 TRUE, // Inherit handles 128 0, // Creation flag 129 NULL, // No environment block 130 ".", // current working directory 131 &si, 132 &pi_); // process info filled out as a result 133 if (!rv) { 134 fprintf(stderr,"os_process_windows(): Error creating process"); 135 } 136 */ 113 114 // execvp? 115 cerr << "Away to execve: " << cmdline << endl; 116 117 execve(cmdline, NULL, NULL); 137 118 138 119 … … 154 135 case uniRead: 155 136 ::close(child_stdin_write_); 137 child_stdin_write_ = -1; 156 138 break; 157 139 case uniWrite: 158 140 ::close(child_stdout_read_); 141 child_stdout_read_ = -1; 159 142 break; 160 143 case biReadWrite: … … 162 145 // the pipes are set up just the way we want them 163 146 break; 164 case noPipe:165 ::close(child_stdin_write_);166 ::close(child_stdout_read_);167 break;168 147 } 169 148 } … … 171 150 172 151 osprocessunix::~osprocessunix() 173 {} 174 175 /* 176 bool osprocessunix::eop() 177 {} 178 179 bool osprocessunix::eop(OSProcessPipeMode) 180 {} 181 */ 152 { 153 // close any file handles that are still open 154 close(); 155 } 156 182 157 183 158 int osprocessunix::write(char* buffer, const int buffer_len) … … 206 181 207 182 208 bool osprocessunix::close() 209 { 210 return true; 211 } 212 213 bool osprocessunix::close(OSProcessPipeMode mode) 214 { 215 return true; 216 } 183 bool osprocessunix::close_write_pipe(OSProcessWarnStatus warn_status) 184 { 185 int write_close_rv = 0; 186 187 if (child_stdin_write_ != -1) { 188 write_close_rv = ::close(child_stdin_write_); 189 child_stdin_write_ = -1; 190 } 191 else if (warn_status = withWarning) { 192 cerr << "osprocessunix::close_write_pipe(): Warning - Tried to close already closed pipe" << endl; 193 } 194 195 return (write_close_rv==0); 196 } 197 198 199 bool osprocessunix::close_read_pipe(OSProcessWarnStatus warn_status) 200 { 201 int read_close_rv = 0; 202 203 204 if (child_stdout_read_ != -1) { 205 read_close_rv = ::close(child_stdout_read_); 206 child_stdout_read_ = -1; 207 } 208 else if (warn_status == withWarning) { 209 cerr << "osprocessunix::close_read_pipe(): Warning - Tried to close already closed pipe" << endl; 210 } 211 212 return (read_close_rv==0); 213 } 214 215 216 217 217 218 218
Note:
See TracChangeset
for help on using the changeset viewer.