mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-21 00:56:21 +00:00
fix(editor): prevent UI redraw conflicts during editor suspend/resume
Guard against re-entrant editor launches, abort editor on Ctrl-Z, and centralize suspend-aware redraws through prof_doupdate() to prevent terminal corruption when SIGTSTP is received while editor is active. Removes SIGUSR1 editor escape in favor of standard pkill <editor> recovery.
This commit is contained in:
@@ -70,6 +70,38 @@ static void _connect_default(const char* const account);
|
||||
pthread_mutex_t lock;
|
||||
static gboolean force_quit = FALSE;
|
||||
|
||||
static volatile sig_atomic_t suspend_requested = FALSE;
|
||||
static volatile sig_atomic_t cont_requested = FALSE;
|
||||
|
||||
static void
|
||||
_handle_suspend_signals(void)
|
||||
{
|
||||
if (cont_requested) {
|
||||
cont_requested = FALSE;
|
||||
if (!editor_is_active()) {
|
||||
clearok(stdscr, TRUE);
|
||||
ui_resize();
|
||||
}
|
||||
}
|
||||
|
||||
if (editor_check_stopped()) {
|
||||
log_info("[Editor] stopped; aborting back to profanity");
|
||||
suspend_requested = FALSE;
|
||||
editor_emergency_kill();
|
||||
} else if (suspend_requested) {
|
||||
suspend_requested = FALSE;
|
||||
if (editor_is_active()) {
|
||||
log_info("[Editor] SIGTSTP from vim group; deferring to next poll");
|
||||
} else {
|
||||
log_info("[Suspend] dropping to shell");
|
||||
if (!isendwin()) {
|
||||
endwin();
|
||||
}
|
||||
kill(0, SIGSTOP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_run(gchar* log_level, gchar* account_name, gchar* config_file, gchar* log_file, gchar* theme_name, gchar** commands)
|
||||
{
|
||||
@@ -93,6 +125,7 @@ prof_run(gchar* log_level, gchar* account_name, gchar* config_file, gchar* log_f
|
||||
int waittime = 0;
|
||||
while (cont && !force_quit) {
|
||||
log_stderr_handler();
|
||||
_handle_suspend_signals();
|
||||
session_check_autoaway();
|
||||
|
||||
line = commands ? *commands : inp_readline();
|
||||
@@ -182,6 +215,18 @@ sigterm_handler(int sig)
|
||||
force_quit = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
sigtstp_handler(int sig)
|
||||
{
|
||||
suspend_requested = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
sigcont_handler(int sig)
|
||||
{
|
||||
cont_requested = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_init(char* log_level, char* config_file, char* log_file, char* theme_name)
|
||||
{
|
||||
@@ -189,7 +234,8 @@ _init(char* log_level, char* config_file, char* log_file, char* theme_name)
|
||||
// ignore SIGPIPE
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGINT, SIG_IGN);
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
signal(SIGTSTP, sigtstp_handler);
|
||||
signal(SIGCONT, sigcont_handler);
|
||||
signal(SIGWINCH, ui_sigwinch_handler);
|
||||
signal(SIGTERM, sigterm_handler);
|
||||
signal(SIGHUP, sigterm_handler);
|
||||
|
||||
Reference in New Issue
Block a user