1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[libevent] copied related to signals code from links2

I don't know how it works, but CTRL-Z suspends without additional
keystrokes when libevent is enabled.
This commit is contained in:
Witold Filipczyk 2024-03-08 21:14:17 +01:00
parent 8d7f081961
commit b53bcce570
3 changed files with 52 additions and 8 deletions

View File

@ -50,13 +50,6 @@
#include <sys/select.h> #include <sys/select.h>
#endif #endif
#define EINTRLOOPX(ret_, call_, x_) \
do { \
(ret_) = (call_); \
} while ((ret_) == (x_) && errno == EINTR)
#define EINTRLOOP(ret_, call_) EINTRLOOPX(ret_, call_, -1)
#ifdef CONFIG_LIBCURL #ifdef CONFIG_LIBCURL
#include <curl/curl.h> #include <curl/curl.h>
#include <sys/cdefs.h> #include <sys/cdefs.h>
@ -1101,11 +1094,35 @@ try_redraw_all_terminals(void)
redraw_all_terminals(); redraw_all_terminals();
} }
#ifndef NO_SIGNAL_HANDLERS
static void
clear_events(int h, int blocking)
{
#if !defined(O_NONBLOCK) && !defined(FIONBIO)
blocking = 1;
#endif
while (blocking ? can_read(h) : 1) {
unsigned char c[64];
int rd;
EINTRLOOP(rd, (int)read(h, c, sizeof c));
if (rd != sizeof c) break;
}
}
pid_t signal_pid;
int signal_pipe[2] = { -1, -1 };
static void
clear_events_ptr(void *handle)
{
clear_events((int)(intptr_t)handle, 0);
}
#endif
void void
select_loop(void (*init)(void)) select_loop(void (*init)(void))
{ {
timeval_T last_time; timeval_T last_time;
int select_errors = 0; int select_errors = 0;
@ -1117,6 +1134,16 @@ select_loop(void (*init)(void))
timeval_now(&last_time); timeval_now(&last_time);
#ifdef SIGPIPE #ifdef SIGPIPE
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
#endif
#if !defined(NO_SIGNAL_HANDLERS)
signal_pid = getpid();
if (c_pipe(signal_pipe)) {
elinks_internal("ERROR: can't create pipe for signal handling");
}
set_nonblocking_fd(signal_pipe[0]);
set_nonblocking_fd(signal_pipe[1]);
set_handlers(signal_pipe[0], clear_events_ptr, NULL, NULL, (void *)(intptr_t)signal_pipe[0]);
#endif #endif
init(); init();
check_bottom_halves(); check_bottom_halves();

View File

@ -31,6 +31,18 @@
extern "C" { extern "C" {
#endif #endif
#define EINTRLOOPX(ret_, call_, x_) \
do { \
(ret_) = (call_); \
} while ((ret_) == (x_) && errno == EINTR)
#define EINTRLOOP(ret_, call_) EINTRLOOPX(ret_, call_, -1)
#ifndef NO_SIGNAL_HANDLERS
extern pid_t signal_pid;
extern int signal_pipe[2];
#endif
#if defined(CONFIG_LIBCURL) && defined(CONFIG_LIBEVENT) #if defined(CONFIG_LIBCURL) && defined(CONFIG_LIBEVENT)
/* Global information, common to all connections */ /* Global information, common to all connections */
typedef struct _GlobalInfo typedef struct _GlobalInfo

View File

@ -277,6 +277,11 @@ got_signal(int sig)
s->mask = 1; s->mask = 1;
check_for_select_race(); check_for_select_race();
if (can_write(signal_pipe[1])) {
int wr;
EINTRLOOP(wr, (int)write(signal_pipe[1], "", 1));
}
errno = saved_errno; errno = saved_errno;
} }