Page MenuHomeFreeBSD

Screenshot with vt(4)
Needs ReviewPublic

Authored by hiroo_oikumene.net on Jul 3 2023, 3:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 26, 8:05 AM
Unknown Object (File)
Fri, Apr 26, 8:04 AM
Unknown Object (File)
Fri, Apr 26, 8:04 AM
Unknown Object (File)
Fri, Apr 26, 1:01 AM
Unknown Object (File)
Fri, Apr 26, 12:39 AM
Unknown Object (File)
Feb 15 2024, 9:16 AM
Unknown Object (File)
Jan 11 2024, 6:12 AM
Unknown Object (File)
Dec 20 2023, 5:46 AM

Details

Summary

Screenshot with vt(4) is implemented. Used like

vidcontrol -p text < /dev/ttyv0 > screenshot.txt

There are three types of screenshot. Plain text (vidcontrol -p text), Text with ansi escape sequences (vidcontrol -p term) and Raw picture (vidcontrol -p raw). The raw file can be converted to PNG via the separate program ( http://barleycorn.oikumene.net/ports-patch/vtraw2png.tar.gz ) which needs libpng (graphics/png). Currently vtraw2png supports only 32bit depth, but should be enough I think.

Test Plan

Tested on i386(vga) and amd64(efifb). Other platform and type of fb need to be tested.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

hiroo_oikumene.net created this revision.

A stupid question: when is it useful to be able to take vt screenshots? This feature adds some unprivileged ioctls, so requires careful review, but I don't see the motivation for this.

Please upload a diff with more context (i.e., use diff -U999999 or so).

usr.sbin/vidcontrol/vidcontrol.c
1497

Can we write something like

int colormap[TC_NCOLORS] = {
    [TC_BLACK] = 30,
    [TC_RED] = 31,
    ...
};
...
switch (bg & ~TC_LIGHT) {
case TC_BLACK:
case TC_RED:
...
    snprintf(buf, sizeof(buf), "%2d;", colormap(bg & ~TC_LIGHT));
    strncat(escsq, buf, BUFSIZ - strlen(escsq) - 1);
    break;
}

instead of this ugly code duplication?

I think calling strncat()/strlen() over and over this way can become quite expensive...? And we're not checking for truncation here, is it impossible?

christos added inline comments.
sys/dev/vt/vt.h
429

One indentation level less.

sys/dev/vt/vt_screenshot.c
38

Same for the other function definitions.

75
sys/sys/consio.h
297–300

One indentation level less.

usr.sbin/vidcontrol/vidcontrol.c
1360

Maybe it'd be cleaner to declare all the variables at the beginning of the functions.

1417

4-space indented.

Updated the patch according to review by markj and christos, and made diff with -U999999 option. Thank you.

A stupid question: when is it useful to be able to take vt screenshots? This feature adds some unprivileged ioctls, so requires careful review, but I don't see the motivation for this.

I saw some demands in FreeBSD forum like:

https://forums.freebsd.org/threads/how-does-one-make-console-screenshots.37456/
https://forums.freebsd.org/threads/cron-script-utility-to-make-screenshots-and-periodically-emailing.88197/

So, there is a need to take "snapshot" of console output and check it.
For me, I sometimes want to take screenshot of console to document the steps of operations on the console.
Sometimes, script(1) is suggested but its output needs much editing. textproc/py-asciinema is good, but it is not well suited to the needs of "snapshot".
Servers with IPMI have screenshot function with it (which also show the need for console screenshot, I think), but PCs without IPMI, single board computers like Raspberry Pi and embedded systems need the functionality within FreeBSD.