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
77
78
79
80
81
89 shellPtr = getenv(
"SHELL");
90 if (shellPtr ==
nullptr || *shellPtr ==
'\0')
92 Eargv[Eargc++] = strdup(shellPtr);
93 Eargv[Eargc++] =
"-c";
94 Eargv[Eargc++] = shellCmdPtr;
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
126
127
128
129
137 Perror("fork_exec: missing argument for execvp");
149 keypad(stdscr, true);
150 ssnprintf(tmp_str
, sizeof(tmp_str)
, "fork failed: %s, errno: %d",
169 execvp(argv[0], argv);
172 keypad(stdscr, true);
173 ssnprintf(tmp_str
, sizeof(tmp_str)
, "execvp failed: %s, errno: %d",
181 waitpid(pid, &status, 0);
182 if (WIFEXITED(status)) {
183 rc = WEXITSTATUS(status);
185 keypad(stdscr, true);
187 "Child %s exited with status %d", argv[0]
, rc
);
190 if (WIFSIGNALED(status)) {
191 rc = WTERMSIG(status);
192 keypad(stdscr, true);
194 "Child %s terminated by signal %d", argv[0]
, rc
);
196 keypad(stdscr, true);
198 "Child %s terminated abnormally", argv[0]
);
206 wnoutrefresh(stdscr);
210 if (tmp_str[0] !=
'\0') {
216
217
218
219
220
221
222
223
224
225
234 fprintf(stderr,
"Failed to fork: %s\n", strerror(errno));
241 wnoutrefresh(stdscr);
247 fprintf(stderr,
"Failed to set session ID: %s\n", strerror(errno));
252 fprintf(stderr,
"Second fork failed: %s\n", strerror(errno));
258 char *e = getenv(
"HOME");
265 close(STDOUT_FILENO);
266 close(STDERR_FILENO);
267 int dev_null = open(
"/dev/null", O_RDWR);
268 if (dev_null != -1) {
269 dup2(dev_null, STDIN_FILENO);
270 dup2(dev_null, STDOUT_FILENO);
271 dup2(dev_null, STDERR_FILENO);
276 long max_fd = sysconf(_SC_OPEN_MAX);
277 for (
long fd = 3; fd < max_fd; fd++) {
280 execvp(eargv[0], eargv);
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 dmon(char **)
Fork and execute a command as a daemon.
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.
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.