Fix for mac support.
This commit is contained in:
parent
0e94d55807
commit
1d69bb63ce
34
bb.c
34
bb.c
@ -79,7 +79,7 @@ void cleanup(void)
|
|||||||
cmdfilename = NULL;
|
cmdfilename = NULL;
|
||||||
}
|
}
|
||||||
if (tty_out) {
|
if (tty_out) {
|
||||||
fputs(T_OFF(T_ALT_SCREEN) T_ON(T_SHOW_CURSOR), tty_out);
|
fputs(T_LEAVE_BBMODE, tty_out);
|
||||||
fflush(tty_out);
|
fflush(tty_out);
|
||||||
tcsetattr(fileno(tty_out), TCSANOW, &orig_termios);
|
tcsetattr(fileno(tty_out), TCSANOW, &orig_termios);
|
||||||
}
|
}
|
||||||
@ -631,8 +631,12 @@ void run_bbcmd(bb_t *bb, const char *cmd)
|
|||||||
move_cursor(tty_out, 0, winsize.ws_row-1);
|
move_cursor(tty_out, 0, winsize.ws_row-1);
|
||||||
fputs("\033[K", tty_out);
|
fputs("\033[K", tty_out);
|
||||||
restore_term(&default_termios);
|
restore_term(&default_termios);
|
||||||
|
signal(SIGTTOU, SIG_IGN);
|
||||||
|
if (tcsetpgrp(fileno(tty_out), child->pid))
|
||||||
|
err("Couldn't set pgrp");
|
||||||
kill(-(child->pid), SIGCONT);
|
kill(-(child->pid), SIGCONT);
|
||||||
wait_for_process(&child);
|
wait_for_process(&child);
|
||||||
|
signal(SIGTTOU, SIG_DFL);
|
||||||
init_term();
|
init_term();
|
||||||
dirty = 1;
|
dirty = 1;
|
||||||
} else if (matches_cmd(cmd, "goto:")) { // +goto:
|
} else if (matches_cmd(cmd, "goto:")) { // +goto:
|
||||||
@ -952,10 +956,14 @@ int run_script(bb_t *bb, const char *cmd)
|
|||||||
strcat(fullcmd, cmd);
|
strcat(fullcmd, cmd);
|
||||||
|
|
||||||
proc_t *proc = memcheck(calloc(1, sizeof(proc_t)));
|
proc_t *proc = memcheck(calloc(1, sizeof(proc_t)));
|
||||||
|
signal(SIGTTOU, SIG_IGN);
|
||||||
if ((proc->pid = fork()) == 0) {
|
if ((proc->pid = fork()) == 0) {
|
||||||
fclose(tty_out); tty_out = NULL;
|
fclose(tty_out); tty_out = NULL;
|
||||||
fclose(tty_in); tty_in = NULL;
|
fclose(tty_in); tty_in = NULL;
|
||||||
setpgid(0, 0);
|
pid_t pgrp = getpid();
|
||||||
|
(void)setpgid(0, pgrp);
|
||||||
|
if (tcsetpgrp(STDIN_FILENO, pgrp))
|
||||||
|
err("Couldn't set pgrp");
|
||||||
char **args = memcheck(calloc(4 + (size_t)bb->nselected + 1, sizeof(char*)));
|
char **args = memcheck(calloc(4 + (size_t)bb->nselected + 1, sizeof(char*)));
|
||||||
int i = 0;
|
int i = 0;
|
||||||
args[i++] = SH;
|
args[i++] = SH;
|
||||||
@ -983,6 +991,7 @@ int run_script(bb_t *bb, const char *cmd)
|
|||||||
if (proc->pid == -1)
|
if (proc->pid == -1)
|
||||||
err("Failed to fork");
|
err("Failed to fork");
|
||||||
|
|
||||||
|
(void)setpgid(proc->pid, proc->pid);
|
||||||
LL_PREPEND(running_procs, proc, running);
|
LL_PREPEND(running_procs, proc, running);
|
||||||
int status = wait_for_process(&proc);
|
int status = wait_for_process(&proc);
|
||||||
dirty = 1;
|
dirty = 1;
|
||||||
@ -1136,18 +1145,21 @@ void update_term_size(int sig)
|
|||||||
*/
|
*/
|
||||||
int wait_for_process(proc_t **proc)
|
int wait_for_process(proc_t **proc)
|
||||||
{
|
{
|
||||||
signal(SIGTTOU, SIG_IGN);
|
|
||||||
tcsetpgrp(fileno(tty_out), (*proc)->pid);
|
tcsetpgrp(fileno(tty_out), (*proc)->pid);
|
||||||
int status;
|
int status;
|
||||||
while (waitpid((*proc)->pid, &status, WUNTRACED) < 0 && errno == EINTR) // Can happen, e.g. if process sends SIGTSTP
|
while (*proc) {
|
||||||
continue;
|
if (waitpid((*proc)->pid, &status, WUNTRACED) < 0)
|
||||||
tcsetpgrp(fileno(tty_out), getpgid(0));
|
continue;
|
||||||
signal(SIGTTOU, SIG_DFL);
|
if (WIFEXITED(status) || WIFSIGNALED(status)) {
|
||||||
if (!WIFSTOPPED(status)) {
|
LL_REMOVE((*proc), running);
|
||||||
LL_REMOVE((*proc), running);
|
free(*proc);
|
||||||
free(*proc);
|
*proc = NULL;
|
||||||
*proc = NULL;
|
} else if (WIFSTOPPED(status))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (tcsetpgrp(fileno(tty_out), getpid()))
|
||||||
|
err("Failed to set pgrp");
|
||||||
|
signal(SIGTTOU, SIG_DFL);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
bb.h
6
bb.h
@ -25,7 +25,7 @@
|
|||||||
#include "bterm.h"
|
#include "bterm.h"
|
||||||
|
|
||||||
// Macros:
|
// Macros:
|
||||||
#define BB_VERSION "0.20.2"
|
#define BB_VERSION "0.20.3"
|
||||||
|
|
||||||
#ifndef PATH_MAX
|
#ifndef PATH_MAX
|
||||||
#define PATH_MAX 4096
|
#define PATH_MAX 4096
|
||||||
@ -292,13 +292,13 @@ ASK1 ";\n"
|
|||||||
#else
|
#else
|
||||||
" tput civis >/dev/tty;\n"
|
" tput civis >/dev/tty;\n"
|
||||||
" printf \"\033[1m%s\033[0m\" \"$2\" >/dev/tty;\n"
|
" printf \"\033[1m%s\033[0m\" \"$2\" >/dev/tty;\n"
|
||||||
" stty -icanon -echo >/dev/tty;\n"
|
" stty -icanon -echo >/dev/tty 2>/dev/tty;\n"
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
" read -n 1 $1 </dev/tty >/dev/tty;\n"
|
" read -n 1 $1 </dev/tty >/dev/tty;\n"
|
||||||
#else
|
#else
|
||||||
" eval \"$1=\\$(dd bs=1 count=1 2>/dev/null </dev/tty)\";\n"
|
" eval \"$1=\\$(dd bs=1 count=1 2>/dev/null </dev/tty)\";\n"
|
||||||
#endif
|
#endif
|
||||||
" stty icanon echo >/dev/tty;\n"
|
" stty icanon echo >/dev/tty 2>/dev/tty;\n"
|
||||||
" tput cvvis >/dev/tty;\n"
|
" tput cvvis >/dev/tty;\n"
|
||||||
#endif
|
#endif
|
||||||
"}\n"
|
"}\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user