F_execute_prohibited,
F_execute_resource_not,
F_execute_schedule,
+ F_execute_terminal,
+ F_execute_terminal_known_not,
+ F_execute_terminal_not,
+ F_execute_terminal_prohibited,
+ F_execute_terminal_valid_not,
F_execute_too_large,
F_execute_user,
F_execute_valid_not,
return F_execute_schedule;
}
+ if (F_status_set_fine(status) == F_terminal) {
+ return F_execute_terminal;
+ }
+
+ if (F_status_set_fine(status) == F_terminal_known_not) {
+ return F_execute_terminal_known_not;
+ }
+
+ if (F_status_set_fine(status) == F_terminal_not) {
+ return F_execute_terminal_not;
+ }
+
+ if (F_status_set_fine(status) == F_terminal_prohibited) {
+ return F_execute_terminal_prohibited;
+ }
+
+ if (F_status_set_fine(status) == F_terminal_valid_not) {
+ return F_execute_terminal_valid_not;
+ }
+
if (F_status_set_fine(status) == F_too_large) {
return F_execute_too_large;
}
return F_schedule;
}
+ if (status == F_execute_terminal) {
+ return F_terminal;
+ }
+
+ if (status == F_execute_terminal_known_not) {
+ return F_terminal_known_not;
+ }
+
+ if (status == F_execute_terminal_not) {
+ return F_terminal_not;
+ }
+
+ if (status == F_execute_terminal_prohibited) {
+ return F_terminal_prohibited;
+ }
+
+ if (status == F_execute_terminal_valid_not) {
+ return F_terminal_valid_not;
+ }
+
if (status == F_execute_too_large) {
return F_too_large;
}
// libc includes
#include <sched.h>
+#include <termios.h>
+#include <sys/types.h>
+#include <unistd.h>
// fll-0 includes
#include <fll/level_0/type.h>
* A structure for containing additional parameters for the execute functions that call the execv() family of functions.
*
* FL_execute_parameter_option_*:
- * - exit: used to desginate to exit after calling child otherwise child process will return.
- * - path: used to designate that the full path to the program is to be passed in argument[0] instead of the program name (such as '/bin/bash' instead of 'bash').
- * - threadsafe: used to designate that threadsafe functions are to be used (such as: f_thread_signal_mask instead of f_signal_mask).
- * - return: used to designate that the parent process will immediately return instead of waiting for the child process to complete.
- *
- * If thread support is disabled in the library, then FL_execute_parameter_option_threadsafe_d will fallback to non-threadsafe.
+ * - exit: Used to desginate to exit after calling child otherwise child process will return.
+ * - path: Used to designate that the full path to the program is to be passed in argument[0] instead of the program name (such as '/bin/bash' instead of 'bash').
+ * - return: Used to designate that the parent process will immediately return instead of waiting for the child process to complete.
+ * - session: Start a new session, set the process of the child as the controlling terminal.
+ * - terminal: (Not Implemented) open() a terminal (tty) before executing. @todo determine if and how to setup the terminal properly (this needs research and planning and may require further structural changes).
+ * - threadsafe: Used to designate that threadsafe functions are to be used (such as: f_thread_signal_mask instead of f_signal_mask).
*
* option: Accepts the bitwise options
* wait: Represents options passed to waitpid(), such as WUNTRACED.
* data: The data to pipe to the child process, set to 0 to not use.
*/
#ifndef _di_fl_execute_parameter_t_
- #define FL_execute_parameter_option_exit_d 0x1
- #define FL_execute_parameter_option_path_d 0x2
- #define FL_execute_parameter_option_threadsafe_d 0x4
- #define FL_execute_parameter_option_return_d 0x8
+ #define FL_execute_parameter_option_exit_d 0x1
+ #define FL_execute_parameter_option_path_d 0x2
+ #define FL_execute_parameter_option_return_d 0x4
+ #define FL_execute_parameter_option_session_d 0x8
+ #define FL_execute_parameter_option_terminal_d 0x10
+ #define FL_execute_parameter_option_threadsafe_d 0x20
typedef struct {
uint8_t option;
int code = 0;
+ if (option & FL_execute_parameter_option_session_d) {
+ setsid();
+ }
+
// full path is explicitly requested.
if (option & FL_execute_parameter_option_path_d) {
f_string_dynamic_t path = f_string_dynamic_t_initialize;
* A bitwise set of options, such as: FL_execute_parameter_option_exit_d and FL_execute_parameter_option_path_d.
* If FL_execute_parameter_option_exit_d: this will call exit() at the end of execution (be it success or failure).
* If FL_execute_parameter_option_path_d: use the whole program path (such as "/bin/bash" instead "bash" when populating argument[0].
+ * If FL_execute_parameter_option_session_d: will start a new session, setting process group id.
* @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.
* @see memcpy()
* @see nice()
* @see pipe()
+ * @see setsid()
* @see sched_setaffinity()
* @see sched_setscheduler()
* @see setgid()
}
if (id_process) {
-
if (as) {
// close the read pipe for the parent.
return F_none;
}
+ if (parameter && parameter->option & FL_execute_parameter_option_session_d) {
+ setsid();
+ }
+
if (as) {
// close the write pipe for the child.
return F_none;
}
+ if (parameter && parameter->option & FL_execute_parameter_option_session_d) {
+ setsid();
+ }
+
// close the write pipe for the child.
close(descriptors[1]);
controller_thread_process_cancel(is_entry, is_entry ? controller_thread_cancel_execute : controller_thread_cancel_exit_execute, global, process);
int result = 0;
+ int option = FL_execute_parameter_option_path_d;
- status = fll_execute_into(0, entry_action->parameters, FL_execute_parameter_option_path_d, 0, (void *) &result);
+ if (global->main->as_init) {
+ option |= FL_execute_parameter_option_session_d; // @todo need "session new" and "session same".
+ }
+
+ status = fll_execute_into(0, entry_action->parameters, option, 0, (void *) &result);
if (F_status_is_error(status)) {
if (F_status_set_fine(status) == F_file_found_not) {
else if (code == F_execute_schedule) {
fl_print_format("%[' failed to setup scheduler.%]%c", print->to.stream, print->context, print->context, f_string_eol_s[0]);
}
+ else if (code == F_execute_terminal) {
+ fl_print_format("%[' failed while processing the terminal.%]%c", print->to.stream, print->context, print->context, f_string_eol_s[0]);
+ }
+ else if (code == F_execute_terminal_known_not) {
+ fl_print_format("%[' cannot process terminal, unknown terminal control command.%]%c", print->to.stream, print->context, print->context, f_string_eol_s[0]);
+ }
+ else if (code == F_execute_terminal_not) {
+ fl_print_format("%[' cannot process terminal, not a known terminal.%]%c", print->to.stream, print->context, print->context, f_string_eol_s[0]);
+ }
+ else if (code == F_execute_terminal_prohibited) {
+ fl_print_format("%[' insufficient permissions to process the terminal.%]%c", print->to.stream, print->context, print->context, f_string_eol_s[0]);
+ }
+ else if (code == F_execute_terminal_valid_not) {
+ fl_print_format("%[' invalid parameter while processing the terminal.%]%c", print->to.stream, print->context, print->context, f_string_eol_s[0]);
+ }
else if (code == F_execute_too_large) {
fl_print_format("%[' too many arguments or arguments are too large.%]%c", print->to.stream, print->context, print->context, f_string_eol_s[0]);
}
execute_set.parameter.option |= FL_execute_parameter_option_path_d;
}
+ if (global.main->as_init) {
+ execute_set.parameter.option |= FL_execute_parameter_option_session_d; // @todo need "session new" and "session same".
+ }
+
if (process->rule.items.array[i].type == controller_rule_item_type_command) {
for (;;) {
maintenance:
- #execute /bin/agetty -8 -i -J - linux
+ #execute /bin/agetty -8 -i -J tty1 linux
+ #execute /bin/setsid -c /bin/bash --login
execute /bin/bash --login
show init
main:
- #execute /bin/agetty -8 -i -J - linux
+ #execute /bin/agetty -8 -i -J tty1 linux
+ #execute /bin/setsid -c /bin/bash --login
execute /bin/bash --login
name "Maintenance Console"
command:
+ #start setsid -c bash --login
start bash --login