git: 0f2041a5b032 - main - [linprocfs] add sys/kernel/random/boot_id

From: Fernando Apesteguía <fernape_at_FreeBSD.org>
Date: Mon, 11 Apr 2022 16:27:44 UTC
The branch main has been updated by fernape (doc, ports committer):

URL: https://cgit.FreeBSD.org/src/commit/?id=0f2041a5b03259a8a7b20ffc98e34884cc5590b3

commit 0f2041a5b03259a8a7b20ffc98e34884cc5590b3
Author:     Fernando Apesteguía <fernape@FreeBSD.org>
AuthorDate: 2022-03-08 14:19:53 +0000
Commit:     Fernando Apesteguía <fernape@FreeBSD.org>
CommitDate: 2022-04-11 16:23:28 +0000

    [linprocfs] add sys/kernel/random/boot_id
    
    This file holds a UUID that is invariant for every boot. In our case, it is
    invariant per mount.
    
    PR:     262369
    Reported by:    sodynet1@gmail.com
    Approved by:    dchagin@
    Differential Revision:  https://reviews.freebsd.org/D34860
---
 sys/compat/linprocfs/linprocfs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index 8a9525b4375d..f930c1d71987 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -1887,6 +1887,24 @@ linprocfs_douuid(PFS_FILL_ARGS)
 	return(0);
 }
 
+/*
+ * Filler function for proc/sys/kernel/random/boot_id
+ */
+static int
+linprocfs_doboot_id(PFS_FILL_ARGS)
+{
+       static bool firstboot = 1;
+       static struct uuid uuid;
+
+       if (firstboot) {
+               kern_uuidgen(&uuid, 1);
+               firstboot = 0;
+       }
+       sbuf_printf_uuid(sb, &uuid);
+       sbuf_printf(sb, "\n");
+       return(0);
+}
+
 /*
  * Filler function for proc/pid/auxv
  */
@@ -2097,6 +2115,8 @@ linprocfs_init(PFS_INIT_ARGS)
 	dir = pfs_create_dir(dir, "random", NULL, NULL, NULL, 0);
 	pfs_create_file(dir, "uuid", &linprocfs_douuid,
 	    NULL, NULL, NULL, PFS_RD);
+	pfs_create_file(dir, "boot_id", &linprocfs_doboot_id,
+	    NULL, NULL, NULL, PFS_RD);
 
 	/* /proc/sys/vm/.... */
 	dir = pfs_create_dir(sys, "vm", NULL, NULL, NULL, 0);