git: 7e8473273f02 - stable/14 - bhyve: insert VM name to the VNC screen title

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sun, 21 Sep 2025 14:53:01 UTC
The branch stable/14 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=7e8473273f0254f381871f56cb1792dac5b6269e

commit 7e8473273f0254f381871f56cb1792dac5b6269e
Author:     Yuichiro NAITO <naito.yuichiro@gmail.com>
AuthorDate: 2025-09-03 15:43:33 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-09-21 14:52:38 +0000

    bhyve: insert VM name to the VNC screen title
    
    Reviewed by:    markj
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D52329
    
    (cherry picked from commit 0e7f8abb45263c780a4b448fb52af6b6a3cbc9fd)
---
 usr.sbin/bhyve/rfb.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/bhyve/rfb.c b/usr.sbin/bhyve/rfb.c
index 4e9f52ed4700..0b4888483559 100644
--- a/usr.sbin/bhyve/rfb.c
+++ b/usr.sbin/bhyve/rfb.c
@@ -64,6 +64,7 @@
 #include "bhyvegc.h"
 #include "debug.h"
 #include "console.h"
+#include "config.h"
 #include "rfb.h"
 #include "sockstream.h"
 
@@ -153,6 +154,8 @@ struct rfb_softc {
 	struct pixfmt	pixfmt;		/* owned by the write thread */
 	struct pixfmt	new_pixfmt;	/* managed with pixfmt_mtx */
 	uint32_t	*pixrow;
+	char		*fbname;
+	int		fbnamelen;
 };
 
 struct rfb_pixfmt {
@@ -263,7 +266,7 @@ struct rfb_cuttext_msg {
 };
 
 static void
-rfb_send_server_init_msg(int cfd)
+rfb_send_server_init_msg(struct rfb_softc *rc, int cfd)
 {
 	struct bhyvegc_image *gc_image;
 	struct rfb_srvr_info sinfo;
@@ -285,9 +288,9 @@ rfb_send_server_init_msg(int cfd)
 	sinfo.pixfmt.pad[0] = 0;
 	sinfo.pixfmt.pad[1] = 0;
 	sinfo.pixfmt.pad[2] = 0;
-	sinfo.namelen = htonl(strlen("bhyve"));
+	sinfo.namelen = htonl(rc->fbnamelen);
 	(void)stream_write(cfd, &sinfo, sizeof(sinfo));
-	(void)stream_write(cfd, "bhyve", strlen("bhyve"));
+	(void)stream_write(cfd, rc->fbname, rc->fbnamelen);
 }
 
 static void
@@ -1145,7 +1148,7 @@ report_and_done:
 	len = stream_read(cfd, buf, 1);
 
 	/* 4a. Write server-init info */
-	rfb_send_server_init_msg(cfd);
+	rfb_send_server_init_msg(rc, cfd);
 
 	if (!rc->zbuf) {
 		rc->zbuf = malloc(RFB_ZLIB_BUFSZ + 16);
@@ -1277,6 +1280,13 @@ rfb_init(const char *hostname, int port, int wait, const char *password)
 
 	rc->password = password;
 
+	rc->fbnamelen = asprintf(&rc->fbname, "bhyve:%s",
+	    get_config_value("name"));
+	if (rc->fbnamelen < 0) {
+		EPRINTLN("rfb: failed to allocate memory for VNC title");
+		goto error;
+	}
+
 	rc->pixrow = malloc(RFB_MAX_WIDTH * sizeof(uint32_t));
 	if (rc->pixrow == NULL) {
 		EPRINTLN("rfb: failed to allocate memory for pixrow buffer");
@@ -1359,6 +1369,7 @@ rfb_init(const char *hostname, int port, int wait, const char *password)
 	free(rc->crc);
 	free(rc->crc_tmp);
 	free(rc->pixrow);
+	free(rc->fbname);
 	free(rc);
 	return (-1);
 }