#endif // _di_fll_execute_arguments_dynamic_add_set_
#ifndef _di_fll_execute_into_
- f_status_t fll_execute_into(const f_string_t program, const f_string_statics_t arguments, const uint8_t option, int *result) {
+ f_status_t fll_execute_into(const f_string_t program, const f_string_statics_t arguments, const uint8_t option, const f_string_maps_t *environment, int *result) {
#ifndef _di_level_2_parameter_checking_
if (!program && !arguments.used) return F_status_set_error(F_parameter);
if (!result) return F_status_set_error(F_parameter);
fixed_arguments[0] = program_path;
+ if (environment) {
+ clearenv();
+
+ for (f_array_length_t i = 0; i < environment->used; ++i) {
+ f_environment_set_dynamic(environment->array[i].name, environment->array[i].value, F_true);
+ } // for
+ }
+
code = execv(program_path, fixed_arguments);
}
else {
+ if (environment) {
+ clearenv();
+
+ for (f_array_length_t i = 0; i < environment->used; ++i) {
+ f_environment_set_dynamic(environment->array[i].name, environment->array[i].value, F_true);
+ } // for
+ }
+
code = last_slash ? execv(program ? program : arguments.array[0].string, fixed_arguments) : execvp(program ? program : arguments.array[0].string, fixed_arguments);
}
* @param option
* A bitwise set of options, such as: fl_execute_parameter_option_exit and fl_execute_parameter_option_path.
* If fl_execute_parameter_option_exit: this will call exit() at the end of execution (be it success or failure).
- * If fl_execute_parameter_option_path: use the whole program path (such as "/bin/bash" instead "bash" when populated argument[0].
+ * If fl_execute_parameter_option_path: use the whole program path (such as "/bin/bash" instead "bash" when populating argument[0].
+ * @param environment
+ * (optional) An map of strings representing the environment variable names and their respective values.
+ * Completely clears the environment and then creates environment variables for each name and value pair in this map.
+ * Set to an empty map (set map used length to 0).
+ * Set to NULL to not make any changes to the environment.
+ * Be careful, when executing without the full path (such as "bash" rather than "/bin/bash") either set this to NULL or be sure to include the PATH in this map.
+ * Be careful, scripts might return and the environment will have changed when this is not NULL.
+ * Be careful, if this returns F_failure, the environment will have changed when this is not NULL.
* @param result
* The code returned after finishing execution of program.
*
* @see strnlen()
*/
#ifndef _di_fll_execute_into_
- extern f_status_t fll_execute_into(const f_string_t program, const f_string_statics_t arguments, const uint8_t option, int *result);
+ extern f_status_t fll_execute_into(const f_string_t program, const f_string_statics_t arguments, const uint8_t option, const f_string_maps_t *environment, int *result);
#endif // _di_fll_execute_into_
/**
*
* The program will be executed via a forked child process.
*
- * If parameter.names is specified:
- * Uses the provided environment array to designate the environment for the program being executed.
- * The environment is defined by the names and values pair.
- * This requires paramete.values to also be specified with the same used length as parameter.names.
- *
* When the path has a slash "/" or the environment is to be cleared, then this does validate the path to the program.
* Otherwise, this does not validate the path to the program.
*
* (optional) This and most of its fields are optional and are disabled when set to 0.
* option:
* A bitwise set of options, such as: fl_execute_parameter_option_exit and fl_execute_parameter_option_path.
- * names:
- * An array of strings representing the environment variable names.
- * At most names.used variables are created.
- * Duplicate names are overwritten.
+ * environment:
+ * An map of strings representing the environment variable names and their respective values.
+ * Completely clears the environment and then creates environment variables for each name and value pair in this map.
+ * Set to an empty map (set map used length to 0).
+ * Set to NULL to not make any changes to the environment.
* values:
* An array of strings representing the environment variable names.
* The values.used must be of at least names.used.
}
else {
if (main->parameters[controller_parameter_daemon].result == f_console_result_found) {
-
setting->ready = controller_setting_ready_done;
if (f_file_exists(setting->path_pid.string) == F_true) {
}
}
else if (global.setting->name_entry.used) {
-
const controller_main_entry_t entry = macro_controller_main_entry_t_initialize(&global, global.setting);
status = f_thread_create(0, &thread.id_entry, &controller_thread_entry, (void *) &entry);
// only make the rule and control threads available once any/all pre-processing and are completed.
if (F_status_is_error_not(status) && status != F_signal && status != F_failure && status != F_child && thread.enabled == controller_thread_enabled) {
-
if (main->parameters[controller_parameter_validate].result == f_console_result_none) {
// wait for the entry thread to complete before starting the rule thread.