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 Perror("fork_exec: missing argument for execvp");
143 ssnprintf(tmp_str
, sizeof(tmp_str)
, "fork failed: %s, errno: %d",
147 }
else if (pid == 0) {
150 execvp(argv[0], argv);
151 fprintf(stderr,
"execvp failed: %s, errno: %d\n", argv[0], errno);
154 waitpid(pid, &status, 0);
155 if (WIFEXITED(status)) {
156 rc = WEXITSTATUS(status);
157 }
else if (WIFSIGNALED(status)) {
158 ssnprintf(tmp_str
, sizeof(tmp_str)
, "Child process terminated by signal: %d",
163 ssnprintf(tmp_str
, sizeof(tmp_str)
, "Child process terminated abnormally");
172
173
174
175
176
177
178
179
180
181
182
183
184
185
193 fprintf(stderr,
"First fork failed: %s\n", strerror(errno));
198 fprintf(stderr,
"Set session ID failed: %s\n", strerror(errno));
202 close(STDOUT_FILENO);
203 close(STDERR_FILENO);
204 int dev_null = open(
"/dev/null", O_RDWR);
205 if (dev_null != -1) {
206 dup2(dev_null, STDIN_FILENO);
207 dup2(dev_null, STDOUT_FILENO);
208 dup2(dev_null, STDERR_FILENO);
213 long max_fd = sysconf(_SC_OPEN_MAX);
214 for (
long fd = 3; fd < max_fd; fd++)
216 execvp(eargv[0], eargv);
217 perror(
"execvp failed");
char stdio_names_str[4096]
char * stdio_names(char *, char *)
int ui_wmove(UiSurface *s, uint w, uint y, uint x)
int ui_werase(UiSurface *s, uint w)
int ui_curs_set(int visibility)
int ui_keypad(UiSurface *s, uint w, bool enable)
int Perror(char *emsg_str)
Display a simple error message window or print to stderr.
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_curses_tioctl()
restore_curses_tioctl() - restore curses terminal settings
bool capture_curses_tioctl()
capture_curses_tioctl() - capture curses terminal settings
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
void sig_dfl_mode()
Set signal handlers to default behavior.
void sig_prog_mode()
Set up signal handlers for interrupt signals.