This change causes less(1) to open /dev/tty slightly earlier,
or fallback to stderr.

As a result the TIOCGWINSZ operation can be done against the most
likely tty descriptor.

As a side effect, that tty descriptor will be opened before the
first pledge call.

Anyone see a downside?

Index: usr.bin/less/main.c
===================================================================
RCS file: /cvs/src/usr.bin/less/main.c,v
retrieving revision 1.35
diff -u -p -u -r1.35 main.c
--- usr.bin/less/main.c 17 Sep 2016 15:06:41 -0000      1.35
+++ usr.bin/less/main.c 21 Jan 2017 06:10:53 -0000
@@ -90,6 +90,8 @@ main(int argc, char *argv[])
        if (s != NULL && *s != '\0')
                secure = 1;
 
+       open_getchr();
+
        if (secure) {
                if (pledge("stdio rpath wpath tty", NULL) == -1) {
                        perror("pledge");
@@ -225,7 +227,6 @@ main(int argc, char *argv[])
        if (missing_cap && !know_dumb)
                error("WARNING: terminal is not fully functional", NULL);
        init_mark();
-       open_getchr();
 
        if (secure)
                if (pledge("stdio rpath tty", NULL) == -1) {
Index: usr.bin/less/screen.c
===================================================================
RCS file: /cvs/src/usr.bin/less/screen.c,v
retrieving revision 1.24
diff -u -p -u -r1.24 screen.c
--- usr.bin/less/screen.c       8 Jul 2016 15:23:44 -0000       1.24
+++ usr.bin/less/screen.c       21 Jan 2017 12:06:22 -0000
@@ -181,7 +181,7 @@ scrsize(void)
 #define        DEF_SC_WIDTH    80
 #define        DEF_SC_HEIGHT   24
 
-       if (ioctl(2, TIOCGWINSZ, &w) == 0) {
+       if (ioctl(tty, TIOCGWINSZ, &w) == 0) {
                if (w.ws_row > 0)
                        sys_height = w.ws_row;
                if (w.ws_col > 0)

  • less Theo de Raadt

Reply via email to