153 lines
4.3 KiB
Diff
153 lines
4.3 KiB
Diff
From edf9b5365bf3d3e104d5a6dc055bc5110e328185 Mon Sep 17 00:00:00 2001
|
|
From: Mark Nudelman <markn@greenwoodsoftware.com>
|
|
Date: Tue, 4 Oct 2022 14:54:57 -0700
|
|
Subject: [PATCH] Rearrange signal handling a little.
|
|
|
|
---
|
|
lesstest/lesstest.c | 18 +-----------------
|
|
lesstest/run.c | 27 ++++++++++++++++++++-------
|
|
2 files changed, 21 insertions(+), 24 deletions(-)
|
|
|
|
diff --git a/lesstest/lesstest.c b/lesstest/lesstest.c
|
|
index 51f0b93..b4ce319 100644
|
|
--- a/lesstest/lesstest.c
|
|
+++ b/lesstest/lesstest.c
|
|
@@ -7,8 +7,6 @@ int verbose = 0;
|
|
int less_quit = 0;
|
|
int details = 0;
|
|
char* lt_screen = "./lt_screen";
|
|
-int run_catching = 0;
|
|
-jmp_buf run_catch;
|
|
|
|
static char* testfile = NULL;
|
|
|
|
@@ -18,11 +16,6 @@ static int usage(void) {
|
|
return 0;
|
|
}
|
|
|
|
-static void intr_handler(int signum) {
|
|
- less_quit = 1;
|
|
- if (run_catching) longjmp(run_catch, 1);
|
|
-}
|
|
-
|
|
static int setup(int argc, char* const* argv) {
|
|
char* logfile = NULL;
|
|
int ch;
|
|
@@ -55,10 +48,6 @@ static int setup(int argc, char* const* argv) {
|
|
}
|
|
|
|
int main(int argc, char* const* argv, char* const* envp) {
|
|
- signal(SIGCHLD, child_handler);
|
|
- signal(SIGINT, intr_handler);
|
|
- signal(SIGQUIT, intr_handler);
|
|
- signal(SIGKILL, intr_handler);
|
|
if (!setup(argc, argv))
|
|
return RUN_ERR;
|
|
setup_term();
|
|
@@ -68,12 +57,7 @@ int main(int argc, char* const* argv, char* const* envp) {
|
|
usage();
|
|
return RUN_ERR;
|
|
}
|
|
- //if (setjmp(run_catch)) {
|
|
- // fprintf(stderr, "\nINTR test interrupted\n");
|
|
- // ok = 0;
|
|
- //} else {
|
|
- ok = run_testfile(testfile, argv[optind]);
|
|
- //}
|
|
+ ok = run_testfile(testfile, argv[optind]);
|
|
} else { // gen; create new test
|
|
if (optind+2 > argc) {
|
|
usage();
|
|
diff --git a/lesstest/run.c b/lesstest/run.c
|
|
index c07048e..252a25d 100644
|
|
--- a/lesstest/run.c
|
|
+++ b/lesstest/run.c
|
|
@@ -2,6 +2,7 @@
|
|
#include <errno.h>
|
|
#include <setjmp.h>
|
|
#include <errno.h>
|
|
+#include <signal.h>
|
|
#include <sys/wait.h>
|
|
#include "lesstest.h"
|
|
|
|
@@ -9,17 +10,29 @@ extern int verbose;
|
|
extern int less_quit;
|
|
extern int details;
|
|
extern TermInfo terminfo;
|
|
-extern int run_catching;
|
|
-extern jmp_buf run_catch;
|
|
|
|
static pid_t less_pid;
|
|
+static jmp_buf run_catch;
|
|
|
|
void child_handler(int signum) {
|
|
int status;
|
|
pid_t child = wait(&status);
|
|
if (verbose) fprintf(stderr, "child %d died, status 0x%x\n", child, status);
|
|
- if (child == less_pid)
|
|
+ if (child == less_pid) {
|
|
+ if (verbose) fprintf(stderr, "less died\n");
|
|
less_quit = 1;
|
|
+ }
|
|
+}
|
|
+
|
|
+static void intr_handler(int signum) {
|
|
+ less_quit = 1;
|
|
+ longjmp(run_catch, 1);
|
|
+}
|
|
+
|
|
+static void set_intr_handler(void (*handler)(int)) {
|
|
+ signal(SIGINT, handler);
|
|
+ signal(SIGQUIT, handler);
|
|
+ signal(SIGKILL, handler);
|
|
}
|
|
|
|
static void send_char(LessPipeline* pipeline, wchar ch) {
|
|
@@ -33,8 +46,6 @@ static void send_char(LessPipeline* pipeline, wchar ch) {
|
|
static int read_screen(LessPipeline* pipeline, byte* buf, int buflen) {
|
|
if (verbose) fprintf(stderr, "gen: read screen\n");
|
|
send_char(pipeline, LESS_DUMP_CHAR);
|
|
- if (less_quit) //@@@ FIXME need?
|
|
- return 0;
|
|
int rn = 0;
|
|
for (; rn <= buflen; ++rn) {
|
|
if (read(pipeline->screen_out, &buf[rn], 1) != 1)
|
|
@@ -69,6 +80,7 @@ static int curr_screen_match(LessPipeline* pipeline, const byte* img, int imglen
|
|
}
|
|
|
|
int run_interactive(char* const* argv, int argc, char* const* prog_envp) {
|
|
+ signal(SIGCHLD, child_handler);
|
|
char* const* envp = less_envp(prog_envp, LT_ENV_PREFIX);
|
|
LessPipeline* pipeline = create_less_pipeline(argv, argc, envp);
|
|
if (pipeline == NULL)
|
|
@@ -99,6 +111,7 @@ int run_interactive(char* const* argv, int argc, char* const* prog_envp) {
|
|
}
|
|
|
|
int run_test(TestSetup* setup, FILE* testfd) {
|
|
+ signal(SIGCHLD, child_handler);
|
|
const char* setup_name = setup->argv[setup->argc-1];
|
|
fprintf(stderr, "RUN %s\n", setup_name);
|
|
LessPipeline* pipeline = create_less_pipeline(setup->argv, setup->argc,
|
|
@@ -113,7 +126,7 @@ int run_test(TestSetup* setup, FILE* testfd) {
|
|
fprintf(stderr, "\nINTR test interrupted\n");
|
|
ok = 0;
|
|
} else {
|
|
- run_catching = 1;
|
|
+ set_intr_handler(intr_handler);
|
|
while (!less_quit) {
|
|
char line[10000];
|
|
int line_len = read_zline(testfd, line, sizeof(line));
|
|
@@ -145,8 +158,8 @@ int run_test(TestSetup* setup, FILE* testfd) {
|
|
return 0;
|
|
}
|
|
}
|
|
+ set_intr_handler(SIG_DFL);
|
|
}
|
|
- run_catching = 0;
|
|
destroy_less_pipeline(pipeline);
|
|
fprintf(stderr, "%s %s (%d commands)\n", ok ? "OK " : "FAIL", setup_name, cmds);
|
|
return ok;
|
|
--
|
|
2.27.0
|
|
|