2
3
4
5
6
7
8
11
12
13
14
15
16
17
37
38
39
40
41
42
43
44
51
52
53
54
55
56
57
69
70
71
72
73
81 shellPtr = getenv(
"SHELL");
82 if (shellPtr ==
nullptr || *shellPtr ==
'\0')
84 Eargv[Eargc++] = strdup(shellPtr);
85 Eargv[Eargc++] =
"-c";
86 Eargv[Eargc++] = shellCmdPtr;
87 Eargv[Eargc++] =
nullptr;
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
129 ui_perror("fork_exec: missing argument for execvp");
148 }
else if (pid == 0) {
151 execvp(argv[0], argv);
152 fprintf(stderr,
_(
"execvp failed: %s, errno: %d\n"), argv[0], errno);
155 waitpid(pid, &status, 0);
156 if (WIFEXITED(status)) {
157 rc = WEXITSTATUS(status);
158 }
else if (WIFSIGNALED(status)) {
159 ssnprintf(tmp_str
, sizeof(tmp_str)
, _(
"Child process terminated by signal: %d"),
164 ssnprintf(tmp_str
, sizeof(tmp_str)
, _(
"Child process terminated abnormally"));
173
174
175
176
177
178
179
180
181
182
183
184
185
186
194 fprintf(stderr,
_(
"First fork failed: %s\n"), strerror(errno));
199 fprintf(stderr,
_(
"Set session ID failed: %s\n"), strerror(errno));
203 close(STDOUT_FILENO);
204 close(STDERR_FILENO);
205 int dev_null = open(
"/dev/null", O_RDWR);
206 if (dev_null != -1) {
207 dup2(dev_null, STDIN_FILENO);
208 dup2(dev_null, STDOUT_FILENO);
209 dup2(dev_null, STDERR_FILENO);
214 long max_fd = sysconf(_SC_OPEN_MAX);
215 for (
long fd = 3; fd < max_fd; fd++)
217 execvp(eargv[0], eargv);
218 perror(
_(
"execvp failed"));
char stdio_names_str[4096]
char * stdio_names(char *, char *)
int ui_wmove(UiSurface *s, ss_t w, uint y, uint x)
Move the cursor to a specified position within a UiSurface.
void ui_restore_wins()
Restore the state of all windows in the UI. This function refreshes the standard screen and all surfa...
int ui_curs_set(int visibility)
Set the visibility of the cursor.
int ui_resume()
Resume the UI, restoring the previous program state and updating the display.
void ui_endwin()
End the UI application, cleaning up resources and shutting down the UI runtime.
int ui_werase(UiSurface *s, ss_t w)
Erase the contents of a UiSurface or all surfaces.
int ui_keypad(UiSurface *s, ss_t w, bool enable)
Enable or disable the keypad for a UiSurface.
int fork_exec(char **)
Fork and exec a command.
int shell(char *)
Execute a shell command.
int full_screen_fork_exec(char **)
Execute a command in full screen mode.
int full_screen_shell(char *)
Execute a shell command in full screen mode.
int fork_detach_execvp(char **eargv)
Fork, set new session ID, close files, and execute detached command.
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
bool restore_program_tioctl()
restore_program_tioctl() - restore program terminal settings
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
bool capture_program_tioctl()
capture_program_tioctl() - capture program terminal settings
void sig_dfl_mode()
Set signal handlers to default behavior.
void sig_prog_mode()
Set up signal handlers for interrupt signals.
int ui_perror(char *emsg_str)
Display a simple error message window or print to stderr.