While debugging simplefb-related issues with /dev/console initialization
on Pinebook Pro I've discovered that wsconscfg(8) does not provide 
a way to call WSDISPLAY_GETSCREEN ioctl. Hence this small patch. 

It is similar to what NetBSD has in their codebase.


Index: usr.sbin/wsconscfg/wsconscfg.8
===================================================================
RCS file: /cvs/src/usr.sbin/wsconscfg/wsconscfg.8,v
retrieving revision 1.20
diff -u -p -r1.20 wsconscfg.8
--- usr.sbin/wsconscfg/wsconscfg.8      1 Jul 2010 02:46:06 -0000       1.20
+++ usr.sbin/wsconscfg/wsconscfg.8      17 May 2022 11:48:52 -0000
@@ -33,7 +33,7 @@
 .Nd configure virtual terminals on a wscons display
 .Sh SYNOPSIS
 .Nm wsconscfg
-.Op Fl dFkm
+.Op Fl gdFkm
 .Op Fl e Ar emul
 .Op Fl f Ar ctldev
 .Op Fl t Ar type
@@ -41,7 +41,7 @@
 .Sh DESCRIPTION
 The
 .Nm
-tool allows for the creation and removal of virtual terminals
+tool allows for the viewing, creation and removal of virtual terminals
 on display devices controlled by the wscons terminal framework,
 as long as the underlying display hardware driver supports multiple screens.
 Furthermore, it controls the assignment of keyboards to displays.
@@ -111,6 +111,13 @@ display properties.
 Valid
 .Ar type
 arguments are defined by the underlying display device driver.
+.It Fl g
+Print information (index, screen type and terminal emulation) about
+virtual terminal, specified by
+.Ar index .
+If the
+.Ar index
+argument is omitted, information about current terminal is displayed.
 .El
 .\" .Pp
 .\" Typically, the
Index: usr.sbin/wsconscfg/wsconscfg.c
===================================================================
RCS file: /cvs/src/usr.sbin/wsconscfg/wsconscfg.c,v
retrieving revision 1.17
diff -u -p -r1.17 wsconscfg.c
--- usr.sbin/wsconscfg/wsconscfg.c      24 Oct 2021 21:24:19 -0000      1.17
+++ usr.sbin/wsconscfg/wsconscfg.c      17 May 2022 11:48:52 -0000
@@ -52,21 +52,23 @@ usage(void)
        extern char *__progname;
 
        (void)fprintf(stderr,
-           "usage: %s [-dFkm] [-e emul] [-f ctldev] [-t type] index\n",
+           "usage: %s [-gdFkm] [-e emul] [-f ctldev] [-t type] index\n",
            __progname);
        exit(1);
 }
 
+
 int
 main(int argc, char *argv[])
 {
        char *wsdev;
-       int c, delete, kbd, idx, wsfd, res, mux;
+       int c, get, delete, kbd, idx, wsfd, res, mux;
        struct wsdisplay_addscreendata asd;
        struct wsdisplay_delscreendata dsd;
        struct wsmux_device wmd;
 
        wsdev = DEFDEV;
+       get = 0;
        delete = 0;
        kbd = 0;
        mux = 0;
@@ -74,11 +76,14 @@ main(int argc, char *argv[])
        asd.emul[0] = 0;
        dsd.flags = 0;
 
-       while ((c = getopt(argc, argv, "f:dkmt:e:F")) != -1) {
+       while ((c = getopt(argc, argv, "f:gdkmt:e:F")) != -1) {
                switch (c) {
                case 'f':
                        wsdev = optarg;
                        break;
+               case 'g':
+                       get = 1;
+                       break;
                case 'd':
                        delete = 1;
                        break;
@@ -107,14 +112,14 @@ main(int argc, char *argv[])
        argc -= optind;
        argv += optind;
 
-       if (kbd ? (argc > 1) : (argc != 1))
+       if ((kbd ^ get) ? (argc > 1) : (argc != 1))
                usage();
 
        idx = -1;
        if (argc > 0 && sscanf(argv[0], "%d", &idx) != 1)
                errx(1, "invalid index");
 
-       wsfd = open(wsdev, O_RDWR);
+       wsfd = open(wsdev, get ? O_RDONLY : O_RDWR);
        if (wsfd < 0)
                err(2, "%s", wsdev);
 
@@ -133,6 +138,14 @@ main(int argc, char *argv[])
                        if (res < 0)
                                err(3, "WSMUXIO_ADD_DEVICE");
                }
+       } else if (get) {
+               asd.idx = idx;
+               res = ioctl(wsfd, WSDISPLAYIO_GETSCREEN, &asd);
+               if (res < 0)
+                       err(3, "WSDISPLAYIO_GETSCREEN");
+               else
+                       printf("idx: %d; screentype: %s; emul: %s\n",
+                              asd.idx, asd.screentype, asd.emul);
        } else if (delete) {
                dsd.idx = idx;
                res = ioctl(wsfd, WSDISPLAYIO_DELSCREEN, &dsd);

Reply via email to