devd: Add vm_guest variable

Fetch vm_guest on startup in case we're running under a hypervisor.

Co-authored-by: eugen@
PR: 287873
Sponsored by:		Netflix
This commit is contained in:
Warner Losh
2025-07-18 23:31:50 -06:00
parent b21e67875b
commit bd4a4e46ce
+12
View File
@@ -153,6 +153,8 @@ static volatile sig_atomic_t romeo_must_die = 0;
static const char *configfile = CF;
static char vm_guest[80];
static void devdlog(int priority, const char* message, ...)
__printflike(2, 3);
static void event_loop(void);
@@ -867,6 +869,8 @@ process_event(char *buffer)
cfg.set_variable("timestamp", timestr);
free(timestr);
cfg.set_variable("vm_guest", vm_guest);
// Match doesn't have a device, and the format is a little
// different, so handle it separately.
switch (type) {
@@ -1322,6 +1326,7 @@ int
main(int argc, char **argv)
{
int ch;
size_t len;
check_devd_enabled();
while ((ch = getopt(argc, argv, "df:l:nq")) != -1) {
@@ -1346,6 +1351,13 @@ main(int argc, char **argv)
}
}
len = sizeof(vm_guest);
if (sysctlbyname("kern.vm_guest", vm_guest, &len, NULL, 0) < 0) {
devdlog(LOG_ERR,
"sysctlnametomib(kern.vm_guest) failed: %d\n",
errno);
}
cfg.parse();
if (!no_daemon && daemonize_quick) {
cfg.open_pidfile();