2
3
4
5
6
7
8
11
12
13
14
15
16
17
38
39
40
41
42
43
44
45
50 wmove(stdscr, LINES - 1, 0);
55
56
57
58
59
60
61
73
74
75
76
77
85 shellPtr = getenv(
"SHELL");
86 if (shellPtr ==
nullptr || *shellPtr ==
'\0')
88 Eargv[Eargc++] = strdup(shellPtr);
89 Eargv[Eargc++] =
"-c";
90 Eargv[Eargc++] = shellCmdPtr;
91 Eargv[Eargc++] =
nullptr;
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
122
123
124
125
133 Perror("fork_exec: missing argument for execvp");
146 keypad(stdscr,
true);
147 ssnprintf(tmp_str
, sizeof(tmp_str)
, "fork failed: %s, errno: %d",
151 }
else if (pid == 0) {
154 execvp(argv[0], argv);
155 fprintf(stderr,
"execvp failed: %s, errno: %d\n", argv[0], errno);
158 waitpid(pid, &status, 0);
159 if (WIFEXITED(status)) {
160 rc = WEXITSTATUS(status);
161 }
else if (WIFSIGNALED(status)) {
162 ssnprintf(tmp_str
, sizeof(tmp_str)
, "Child process terminated by signal: %d",
167 ssnprintf(tmp_str
, sizeof(tmp_str)
, "Child process terminated abnormally");
176
177
178
179
180
181
182
183
184
185
186
187
188
189
197 fprintf(stderr,
"First fork failed: %s\n", strerror(errno));
202 fprintf(stderr,
"Set session ID failed: %s\n", strerror(errno));
206 close(STDOUT_FILENO);
207 close(STDERR_FILENO);
208 int dev_null = open(
"/dev/null", O_RDWR);
209 if (dev_null != -1) {
210 dup2(dev_null, STDIN_FILENO);
211 dup2(dev_null, STDOUT_FILENO);
212 dup2(dev_null, STDERR_FILENO);
217 long max_fd = sysconf(_SC_OPEN_MAX);
218 for (
long fd = 3; fd < max_fd; fd++)
220 execvp(eargv[0], eargv);
221 perror(
"execvp failed");
char * stdio_names(char *, char *)
char stdio_names_str[MAXLEN]
void restore_wins()
Restore all windows after a screen resize.
int nf_error(int, char *)
Display error message and wait for key press.
int Perror(char *)
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 **)
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.