156 lines
4.5 KiB
Diff
156 lines
4.5 KiB
Diff
From 0a60b8dd055ef2fcdf5cd780d8b88e0a7c92b378 Mon Sep 17 00:00:00 2001
|
|
From: Mark Nudelman <markn@greenwoodsoftware.com>
|
|
Date: Mon, 3 Oct 2022 21:34:43 -0700
|
|
Subject: [PATCH] lesstest: correctly handle less exit during run_interactive.
|
|
|
|
---
|
|
lesstest/Makefile | 2 +-
|
|
lesstest/lesstest.c | 7 -------
|
|
lesstest/lesstest.h | 2 ++
|
|
lesstest/pipeline.c | 8 ++++----
|
|
lesstest/run.c | 14 +++++++++++++-
|
|
screen.c | 7 +++++--
|
|
6 files changed, 25 insertions(+), 15 deletions(-)
|
|
|
|
diff --git a/lesstest/Makefile b/lesstest/Makefile
|
|
index d7e4987..694ce00 100644
|
|
--- a/lesstest/Makefile
|
|
+++ b/lesstest/Makefile
|
|
@@ -1,5 +1,5 @@
|
|
CC = gcc
|
|
-CFLAGS = -Wall -g
|
|
+CFLAGS = -Wall -O2
|
|
TERMLIB = -lncurses
|
|
|
|
all: lesstest lt_screen
|
|
diff --git a/lesstest/lesstest.c b/lesstest/lesstest.c
|
|
index c374e5e..51f0b93 100644
|
|
--- a/lesstest/lesstest.c
|
|
+++ b/lesstest/lesstest.c
|
|
@@ -1,4 +1,3 @@
|
|
-#include <sys/wait.h>
|
|
#include <setjmp.h>
|
|
#include "lesstest.h"
|
|
|
|
@@ -19,12 +18,6 @@ static int usage(void) {
|
|
return 0;
|
|
}
|
|
|
|
-static 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);
|
|
-}
|
|
-
|
|
static void intr_handler(int signum) {
|
|
less_quit = 1;
|
|
if (run_catching) longjmp(run_catch, 1);
|
|
diff --git a/lesstest/lesstest.h b/lesstest/lesstest.h
|
|
index 4c12fbd..5192702 100644
|
|
--- a/lesstest/lesstest.h
|
|
+++ b/lesstest/lesstest.h
|
|
@@ -26,6 +26,7 @@ typedef struct LessPipeline {
|
|
int screen_out;
|
|
int screen_width;
|
|
int screen_height;
|
|
+ pid_t less_pid;
|
|
pid_t screen_pid;
|
|
const char* tempfile;
|
|
int less_in_pipe[2];
|
|
@@ -80,3 +81,4 @@ int run_testfile(const char* testfile, const char* less);
|
|
void env_init(EnvBuf* env);
|
|
void env_addpair(EnvBuf* env, const char* name, const char* value);
|
|
char* const* less_envp(char* const* envp, const char* env_prefix);
|
|
+void child_handler(int signum);
|
|
diff --git a/lesstest/pipeline.c b/lesstest/pipeline.c
|
|
index 98a6f4e..8f225c7 100644
|
|
--- a/lesstest/pipeline.c
|
|
+++ b/lesstest/pipeline.c
|
|
@@ -117,14 +117,14 @@ LessPipeline* create_less_pipeline(char* const* argv, int argc, char* const* env
|
|
if (verbose) fprintf(stderr, "less in pipe %d,%d\n", pipeline->less_in_pipe[RD], pipeline->less_in_pipe[WR]);
|
|
char* less = argv[0];
|
|
if (verbose) fprintf(stderr, "testing %s on %s\n", less, textfile);
|
|
- pid_t less_pid = fork();
|
|
- if (less_pid < 0) {
|
|
+ pipeline->less_pid = fork();
|
|
+ if (pipeline->less_pid < 0) {
|
|
destroy_less_pipeline(pipeline);
|
|
return NULL;
|
|
}
|
|
- if (!less_pid)
|
|
+ if (!pipeline->less_pid)
|
|
become_child_less(less, argc, argv, envp, pipeline->tempfile, pipeline->less_in_pipe, pipeline->screen_in_pipe);
|
|
- if (verbose) fprintf(stderr, "less child %ld\n", (long) less_pid);
|
|
+ if (verbose) fprintf(stderr, "less child %ld\n", (long) pipeline->less_pid);
|
|
close(pipeline->less_in_pipe[RD]); pipeline->less_in_pipe[RD] = -1;
|
|
close(pipeline->screen_in_pipe[WR]); pipeline->screen_in_pipe[WR] = -1;
|
|
}
|
|
diff --git a/lesstest/run.c b/lesstest/run.c
|
|
index 0c793a7..da306e8 100644
|
|
--- a/lesstest/run.c
|
|
+++ b/lesstest/run.c
|
|
@@ -1,8 +1,9 @@
|
|
#include <time.h>
|
|
#include <errno.h>
|
|
#include <setjmp.h>
|
|
-#include "lesstest.h"
|
|
#include <errno.h>
|
|
+#include <sys/wait.h>
|
|
+#include "lesstest.h"
|
|
|
|
extern int verbose;
|
|
extern int less_quit;
|
|
@@ -11,6 +12,16 @@ extern TermInfo terminfo;
|
|
extern int run_catching;
|
|
extern jmp_buf run_catch;
|
|
|
|
+static pid_t less_pid;
|
|
+
|
|
+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)
|
|
+ less_quit = 1;
|
|
+}
|
|
+
|
|
static void send_char(LessPipeline* pipeline, wchar ch) {
|
|
if (verbose) fprintf(stderr, "send %lx\n", ch);
|
|
byte cbuf[UNICODE_MAX_BYTES];
|
|
@@ -62,6 +73,7 @@ int run_interactive(char* const* argv, int argc, char* const* prog_envp) {
|
|
LessPipeline* pipeline = create_less_pipeline(argv, argc, envp);
|
|
if (pipeline == NULL)
|
|
return 0;
|
|
+ less_pid = pipeline->less_pid;
|
|
const char* textfile = (pipeline->tempfile != NULL) ? pipeline->tempfile : argv[argc-1];
|
|
if (!log_test_header(argv, argc, textfile)) {
|
|
destroy_less_pipeline(pipeline);
|
|
diff --git a/screen.c b/screen.c
|
|
index fffbdfc..f8fa1f5 100644
|
|
--- a/screen.c
|
|
+++ b/screen.c
|
|
@@ -763,7 +763,10 @@ scrsize(VOID_PARAM)
|
|
|
|
sys_width = sys_height = 0;
|
|
|
|
-#if !LESSTEST
|
|
+#if LESSTEST
|
|
+ if (ttyin_name != NULL)
|
|
+#endif /*LESSTEST*/
|
|
+ {
|
|
#if MSDOS_COMPILER==MSOFTC
|
|
{
|
|
struct videoconfig w;
|
|
@@ -846,7 +849,7 @@ scrsize(VOID_PARAM)
|
|
#endif
|
|
#endif
|
|
#endif
|
|
-#endif /*LESSTEST*/
|
|
+ }
|
|
|
|
if (sys_height > 0)
|
|
sc_height = sys_height;
|
|
--
|
|
2.27.0
|
|
|