jcs's openbsd hax
openbsd

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

deraadt 009ff5ea d17ee606

+22 -17
+3 -1
bin/ksh/emacs.c
··· 1 - /* $OpenBSD: emacs.c,v 1.90 2023/06/21 22:22:08 millert Exp $ */ 1 + /* $OpenBSD: emacs.c,v 1.91 2026/03/05 05:38:58 deraadt Exp $ */ 2 2 3 3 /* 4 4 * Emacs-like command line editing and history ··· 1033 1033 if (limit == -2) { 1034 1034 int cleared = 0; 1035 1035 #ifndef SMALL 1036 + if (cur_term == NULL && Flag(FTALKING)) 1037 + initcurses(); 1036 1038 if (cur_term != NULL && clear_screen != NULL) { 1037 1039 if (tputs(clear_screen, 1, x_putc) != ERR) 1038 1040 cleared = 1;
+2 -1
bin/ksh/sh.h
··· 1 - /* $OpenBSD: sh.h,v 1.77 2023/06/21 22:22:08 millert Exp $ */ 1 + /* $OpenBSD: sh.h,v 1.78 2026/03/05 05:38:58 deraadt Exp $ */ 2 2 3 3 /* 4 4 * Public Domain Bourne/Korn shell ··· 602 602 int array_ref_len(const char *); 603 603 char * arrayname(const char *); 604 604 void set_array(const char *, int, char **); 605 + void initcurses(void); 605 606 /* vi.c: see edit.h */
+14 -14
bin/ksh/var.c
··· 1 - /* $OpenBSD: var.c,v 1.74 2026/03/04 03:54:25 deraadt Exp $ */ 1 + /* $OpenBSD: var.c,v 1.75 2026/03/05 05:38:58 deraadt Exp $ */ 2 2 3 3 #include <sys/stat.h> 4 4 #include <sys/time.h> ··· 117 117 { "SECONDS", V_SECONDS }, 118 118 { "TMOUT", V_TMOUT }, 119 119 { "LINENO", V_LINENO }, 120 - { "TERM", V_TERM }, 121 120 { NULL, 0 } 122 121 }; 123 122 int i; ··· 1070 1069 user_lineno = (unsigned int) intval(vp) - current_lineno - 1; 1071 1070 vp->flag |= SPECIAL; 1072 1071 break; 1073 - case V_TERM: 1074 - #ifndef SMALL 1075 - if (Flag(FTALKING)) { 1076 - int ret; 1077 - 1078 - vp->flag &= ~SPECIAL; 1079 - if (setupterm(str_val(vp), shl_out->fd, &ret) == ERR) 1080 - del_curterm(cur_term); 1081 - vp->flag |= SPECIAL; 1082 - } 1083 - #endif 1084 - break; 1085 1072 } 1086 1073 } 1087 1074 ··· 1242 1229 setstr(vq, vals[i], KSH_RETURN_ERROR); 1243 1230 } 1244 1231 } 1232 + 1233 + void 1234 + initcurses(void) 1235 + { 1236 + struct tbl *vp = global("TERM"); 1237 + int ret; 1238 + 1239 + if (vp) { 1240 + if (setupterm(str_val(vp), 1241 + shl_out->fd, &ret) == ERR) 1242 + del_curterm(cur_term); 1243 + } 1244 + }
+3 -1
bin/ksh/vi.c
··· 1 - /* $OpenBSD: vi.c,v 1.67 2025/07/20 21:24:07 schwarze Exp $ */ 1 + /* $OpenBSD: vi.c,v 1.68 2026/03/05 05:38:58 deraadt Exp $ */ 2 2 3 3 /* 4 4 * vi command editing ··· 1739 1739 int neednl = 1; 1740 1740 1741 1741 #ifndef SMALL 1742 + if (cur_term == NULL && Flag(FTALKING)) 1743 + initcurses(); 1742 1744 if (cur_term != NULL && clear_screen != NULL) { 1743 1745 if (tputs(clear_screen, 1, x_putc) != ERR) 1744 1746 neednl = 0;