4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "threadexec.h"
27 #include <sys/types.h>
37 ThreadExec::ThreadExec()
40 Thread::set_synchronous(1);
41 arguments = new char*[MAX_ARGS];
43 start_lock = new Mutex;
49 ThreadExec::~ThreadExec()
61 for(int i = 0; i < total_arguments; i++)
62 delete [] arguments[i];
70 void ThreadExec::start_command(const char *command_line, int pipe_stdin)
72 this->command_line = command_line;
73 this->pipe_stdin = pipe_stdin;
83 void ThreadExec::run()
88 char argument[BCTEXTLEN];
89 char command_line[BCTEXTLEN];
91 strcpy(command_line, this->command_line);
95 // Set up arguments for exec
98 while(*ptr != ' ' && *ptr != 0)
100 *path_ptr++ = *ptr++;
104 arguments[total_arguments] = new char[strlen(path) + 1];
105 strcpy(arguments[total_arguments], path);
106 //printf("%s\n", arguments[total_arguments]);
108 arguments[total_arguments] = 0;
113 argument_ptr = argument;
114 while(*ptr != ' ' && *ptr != 0)
116 *argument_ptr++ = *ptr++;
119 //printf("%s\n", argument);
121 arguments[total_arguments] = new char[strlen(argument) + 1];
122 strcpy(arguments[total_arguments], argument);
124 arguments[total_arguments] = 0;
139 stdin_fd = fdopen(filedes[1], "w");
142 start_lock->unlock();
144 printf("ThreadExec::run 1\n");
145 run_program(total_arguments, arguments, filedes[0]);
147 printf("ThreadExec::run 2\n");
153 FILE* ThreadExec::get_stdin()
160 void ThreadExec::run_program(int argc, char *argv[], int stdin_fd)