133 const unsigned int envArraySize = envs.size() + 1;
134 char**
const env =
new char*[envArraySize];
137 const env_collection::const_iterator b = envs.begin();
138 const env_collection::const_iterator e = envs.end();
139 env_collection::const_iterator it;
141 unsigned int counter = 0;
142 for(it = b; it != e; ++it) {
143 const std::string entry = it->first +
"=" + it->second;
144 env[counter] =
new char[entry.size() + 1];
145 ::strcpy(env[counter], entry.c_str());
149 env[envArraySize - 1] = (
char*) 0;
153 const unsigned int paramArraySize = params.size() + 2;
154 char**
const par =
new char*[paramArraySize];
157 const std::string& binName = this->full_name();
158 par[0] =
new char[binName.size() + 1];
159 ::strcpy(par[0], binName.c_str());
161 const param_collection::const_iterator b = params.begin();
162 const param_collection::const_iterator e = params.end();
163 param_collection::const_iterator it;
165 unsigned int counter = 1;
166 for(it = b; it != e; ++it) {
167 const std::string& value = *it;
168 par[counter] =
new char[value.size() + 1];
169 ::strcpy(par[counter], value.c_str());
173 par[paramArraySize - 1] = (
char*) 0;
179 catch(OksSystem::ExecutionIssue& ex) {
182 for(
unsigned int i = 0; i < envArraySize; ++i) {
187 for(
unsigned int i = 0; i < paramArraySize; ++i) {
209 sigfillset(&new_set);
210 pthread_sigmask(SIG_SETMASK, &new_set, &old_set);
212 const pid_t child_id = fork();
216 signal(SIGTERM, SIG_DFL);
217 signal(SIGINT, SIG_DFL);
220 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
225 catch(OksSystem::ExecutionIssue &ex) {
238 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
240 return Process(child_id,to_string(params));
245 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
247 throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"fork",
"" );
261 sigfillset(&new_set);
262 pthread_sigmask(SIG_SETMASK, &new_set, &old_set);
264 signal(SIGCLD, SIG_IGN);
266 const pid_t child_id = fork();
270 signal(SIGTERM, SIG_DFL);
271 signal(SIGINT, SIG_DFL);
272 signal(SIGCLD, SIG_DFL);
275 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
280 catch(OksSystem::ExecutionIssue &ex) {
293 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
295 return Process(child_id,to_string(params));
299 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
301 throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"fork",
"" );
330 const int input_pipe_status = pipe(input_pipe);
331 if (input_pipe_status<0)
throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"pipe",
"" );
332 const int data_pipe_status = pipe(data_pipe);
333 if (data_pipe_status<0)
throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"pipe",
"" );
334 const int error_pipe_status = pipe(error_pipe);
335 if (error_pipe_status<0)
throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"pipe",
"" );
340 sigfillset(&new_set);
341 pthread_sigmask(SIG_SETMASK, &new_set, &old_set);
343 const pid_t child_id = fork();
347 signal(SIGTERM, SIG_DFL);
348 signal(SIGINT, SIG_DFL);
351 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
353 dup2(input_pipe[1], fileno(stdin));
354 dup2(data_pipe[1], fileno(stdout));
355 dup2(error_pipe[1], fileno(stderr));
360 catch(OksSystem::ExecutionIssue &ex) {
373 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
375 Process child_process(child_id,to_string(params));
376 close(input_pipe[1]);
378 close(error_pipe[1]);
379 const int child_status = child_process.
join();
380 const int in_fd = input_pipe[0];
381 const int err_fd = error_pipe[0];
382 const int out_fd = data_pipe[0];
383 std::ostringstream in_stream;
384 std::ostringstream out_stream;
385 std::ostringstream err_stream;
386 copy_fd(in_fd,in_stream);
387 copy_fd(out_fd,out_stream);
388 copy_fd(err_fd,err_stream);
392 if (0==child_status) {
393 return out_stream.str();
395 std::string command = to_string(params);
396 std::string error_str = err_stream.str();
397 throw OksSystem::ExecutionIssue(
ERS_HERE,errno,command.c_str(),child_status);
401 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
403 return std::string();
430 sigfillset(&new_set);
431 pthread_sigmask(SIG_SETMASK, &new_set, &old_set);
437 const pid_t child_id = fork();
441 signal(SIGTERM, SIG_DFL);
442 signal(SIGINT, SIG_DFL);
445 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
448 ::dup2(in,::fileno(stdin));
449 ::dup2(out,::fileno(stdout));
450 ::dup2(err,::fileno(stderr));
456 catch(OksSystem::ExecutionIssue &ex) {
460 catch(OksSystem::PosixIssue &ex) {
473 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
475 return Process(child_id,to_string(params));
479 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
481 throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"fork",
"" );
498 sigfillset(&new_set);
499 pthread_sigmask(SIG_SETMASK, &new_set, &old_set);
505 const pid_t child_id = fork();
509 signal(SIGTERM, SIG_DFL);
510 signal(SIGINT, SIG_DFL);
513 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
516 ::dup2(in,::fileno(stdin));
517 ::dup2(out,::fileno(stdout));
518 ::dup2(err,::fileno(stderr));
522 this->exec(params,envs);
524 catch(OksSystem::ExecutionIssue &ex) {
528 catch(OksSystem::PosixIssue &ex) {
541 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
543 return Process(child_id,to_string(params));
547 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
549 throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"fork",
"" );
563 sigfillset(&new_set);
564 pthread_sigmask(SIG_SETMASK, &new_set, &old_set);
566 const pid_t child_id = fork();
570 signal(SIGTERM, SIG_DFL);
571 signal(SIGINT, SIG_DFL);
574 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
579 catch(OksSystem::ExecutionIssue &ex) {
592 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
598 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
600 throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"fork",
"" );