27 #include <sys/types.h>
41 using namespace basis;
48 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s);
55 static mutex __hidden_synch;
56 return __hidden_synch;
81 #define SUPPORT_SHELL_EXECUTE
94 void launch_process::exiting_child_signal_handler(
int sig_num)
96 FUNCDEF(
"exiting_child_signal_handler");
97 if (sig_num != SIGCHLD) {
103 pid_t exited = waitpid(
__our_kids()[i], &status, WNOHANG);
104 if ( (exited == -1) || (exited ==
__our_kids()[i]) ) {
110 }
else if (exited != 0) {
112 #ifdef DEBUG_LAUNCH_PROCESS
128 for (
int j = 0; j < parameters.
length(); j++) {
129 if (parameters[j] ==
' ') {
135 to_return +=
new char[app.
length() + 1];
139 for (
int i = 0; i <
num; i++) {
140 int len = posns[i] - last_posn;
141 to_return +=
new char[len + 1];
142 parameters.
substring(last_posn, posns[i] - 1).stuff(to_return[i + 1], len);
143 last_posn = posns[i] + 1;
146 if (last_posn < parameters.
length() - 1) {
147 int len = parameters.
length() - last_posn;
148 to_return +=
new char[len + 1];
150 .stuff(to_return[to_return.
last()], len);
154 #ifdef DEBUG_LAUNCH_PROCESS
155 for (
int q = 0; to_return[q]; q++) {
161 if (app[0] ==
'"') app.
zap(0, 0);
162 if (app[app.
end()] ==
'"') app.
zap(app.
end(), app.
end());
169 #ifdef DEBUG_LAUNCH_PROCESS
173 astring app_name = app_name_in;
174 if (app_name[0] !=
'"')
176 if (app_name[app_name.
end()] !=
'"')
180 if (flag & RETURN_IMMEDIATELY) {
182 pid_t kid_pid = fork();
183 #ifdef DEBUG_LAUNCH_PROCESS
188 #ifdef DEBUG_LAUNCH_PROCESS
189 LOG(
a_sprintf(
"process %d execing ", application_configuration::process_id()) + app_name
190 +
" parms " + command_line +
"\n");
195 #ifdef DEBUG_LAUNCH_PROCESS
196 LOG(
a_sprintf(
"child of fork (pid %d) failed to exec, error is ",
197 application_configuration::process_id())
198 + critical_events::system_error_text(critical_events::system_error())
207 #ifdef DEBUG_LAUNCH_PROCESS
208 LOG(
a_sprintf(
"parent %d is returning after failing to create, "
209 "error is ", application_configuration::process_id())
210 + critical_events::system_error_text(to_return)
222 signal(SIGCHLD, exiting_child_signal_handler);
224 #ifdef DEBUG_LAUNCH_PROCESS
225 LOG(
a_sprintf(
"parent %d is returning after successfully "
226 "creating %d ", application_configuration::process_id(), kid_pid) + app_name
227 +
" parms " + command_line +
"\n");
234 return system((app_name +
" " + command_line).s());
a_sprintf is a specialization of astring that provides printf style support.
const contents * observe() const
Returns a pointer to the underlying C array of data.
int length() const
Returns the current reported length of the allocated C array.
outcome zap(int start, int end)
Deletes from "this" the objects inclusively between "start" and "end".
int last() const
Returns the last valid element in the array.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
bool substring(astring &target, int start, int end) const
a version that stores the substring in an existing "target" string.
void stuff(char *to_stuff, int count) const
a synonym for copy().
void insert(int position, const astring &to_insert)
Copies "to_insert" into "this" at the "position".
int end() const
returns the index of the last (non-null) character in the string.
int length() const
Returns the current length of the string.
auto_synchronizer simplifies concurrent code by automatically unlocking.
A simple object that wraps a templated array of ints.
a simple wrapper of an array of char *, used by launch_process::break_line().
A simple object that wraps a templated set of ints.
#define NULL_POINTER
The value representing a pointer to nothing.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
unsigned int un_int
Abbreviated name for unsigned integers.
A logger that sends to the console screen using the standard output device.
mutex & __process_synchronizer()
A dynamic container class that holds any kind of object via pointers.
Support for unicode builds.
Aids in achievement of platform independence.