From 009ff5eaef33c959f475ba16bfda7d04c24aa986 Mon Sep 17 00:00:00 2001 From: deraadt Date: Thu, 5 Mar 2026 05:38:58 +0000 Subject: [PATCH] Inspecting Flag(FTALKING) to activate curses in the spot chosen by the previous commit seems to fail in some circumstances because of order of operations in ksh startup. So move the test and curses initialization immediately before the tputs() calls. discussion with tb --- bin/ksh/emacs.c | 4 +++- bin/ksh/sh.h | 3 ++- bin/ksh/var.c | 28 ++++++++++++++-------------- bin/ksh/vi.c | 4 +++- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/bin/ksh/emacs.c b/bin/ksh/emacs.c index 3c9b0074d81..943970fea6d 100644 --- a/bin/ksh/emacs.c +++ b/bin/ksh/emacs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: emacs.c,v 1.90 2023/06/21 22:22:08 millert Exp $ */ +/* $OpenBSD: emacs.c,v 1.91 2026/03/05 05:38:58 deraadt Exp $ */ /* * Emacs-like command line editing and history @@ -1033,6 +1033,8 @@ x_redraw(int limit) if (limit == -2) { int cleared = 0; #ifndef SMALL + if (cur_term == NULL && Flag(FTALKING)) + initcurses(); if (cur_term != NULL && clear_screen != NULL) { if (tputs(clear_screen, 1, x_putc) != ERR) cleared = 1; diff --git a/bin/ksh/sh.h b/bin/ksh/sh.h index bffb374e0d1..db09a20a277 100644 --- a/bin/ksh/sh.h +++ b/bin/ksh/sh.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sh.h,v 1.77 2023/06/21 22:22:08 millert Exp $ */ +/* $OpenBSD: sh.h,v 1.78 2026/03/05 05:38:58 deraadt Exp $ */ /* * Public Domain Bourne/Korn shell @@ -602,4 +602,5 @@ void change_random(void); int array_ref_len(const char *); char * arrayname(const char *); void set_array(const char *, int, char **); +void initcurses(void); /* vi.c: see edit.h */ diff --git a/bin/ksh/var.c b/bin/ksh/var.c index 1971c5fc10e..800ee1aaf78 100644 --- a/bin/ksh/var.c +++ b/bin/ksh/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.74 2026/03/04 03:54:25 deraadt Exp $ */ +/* $OpenBSD: var.c,v 1.75 2026/03/05 05:38:58 deraadt Exp $ */ #include #include @@ -117,7 +117,6 @@ initvar(void) { "SECONDS", V_SECONDS }, { "TMOUT", V_TMOUT }, { "LINENO", V_LINENO }, - { "TERM", V_TERM }, { NULL, 0 } }; int i; @@ -1070,18 +1069,6 @@ setspec(struct tbl *vp) user_lineno = (unsigned int) intval(vp) - current_lineno - 1; vp->flag |= SPECIAL; break; - case V_TERM: -#ifndef SMALL - if (Flag(FTALKING)) { - int ret; - - vp->flag &= ~SPECIAL; - if (setupterm(str_val(vp), shl_out->fd, &ret) == ERR) - del_curterm(cur_term); - vp->flag |= SPECIAL; - } -#endif - break; } } @@ -1242,3 +1229,16 @@ set_array(const char *var, int reset, char **vals) setstr(vq, vals[i], KSH_RETURN_ERROR); } } + +void +initcurses(void) +{ + struct tbl *vp = global("TERM"); + int ret; + + if (vp) { + if (setupterm(str_val(vp), + shl_out->fd, &ret) == ERR) + del_curterm(cur_term); + } +} diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c index 28be809036d..d296e018c60 100644 --- a/bin/ksh/vi.c +++ b/bin/ksh/vi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vi.c,v 1.67 2025/07/20 21:24:07 schwarze Exp $ */ +/* $OpenBSD: vi.c,v 1.68 2026/03/05 05:38:58 deraadt Exp $ */ /* * vi command editing @@ -1739,6 +1739,8 @@ do_clear_screen(void) int neednl = 1; #ifndef SMALL + if (cur_term == NULL && Flag(FTALKING)) + initcurses(); if (cur_term != NULL && clear_screen != NULL) { if (tputs(clear_screen, 1, x_putc) != ERR) neednl = 0;