Index: head/stand/defaults/loader.conf =================================================================== --- head/stand/defaults/loader.conf +++ head/stand/defaults/loader.conf @@ -33,6 +33,11 @@ screensave_load="NO" # Set to YES to load a screensaver module screensave_name="green_saver" # Set to the name of the screensaver module +### Early hostid configuration ############################ +hostuuid_load="YES" +hostuuid_name="/etc/hostid" +hostuuid_type="hostuuid" + ### Random number generator configuration ################## # See rc.conf(5). The entropy_boot_file config variable must agree with the # settings below. Index: head/sys/kern/kern_jail.c =================================================================== --- head/sys/kern/kern_jail.c +++ head/sys/kern/kern_jail.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,7 @@ #include #include #include +#include #include #include @@ -75,6 +77,7 @@ #include #define DEFAULT_HOSTUUID "00000000-0000-0000-0000-000000000000" +#define PRISON0_HOSTUUID_MODULE "hostuuid" MALLOC_DEFINE(M_PRISON, "prison", "Prison structures"); static MALLOC_DEFINE(M_PRISON_RACCT, "prison_racct", "Prison racct structures"); @@ -218,10 +221,38 @@ void prison0_init(void) { + uint8_t *file, *data; + size_t size; prison0.pr_cpuset = cpuset_ref(thread0.td_cpuset); prison0.pr_osreldate = osreldate; strlcpy(prison0.pr_osrelease, osrelease, sizeof(prison0.pr_osrelease)); + + /* If we have a preloaded hostuuid, use it. */ + file = preload_search_by_type(PRISON0_HOSTUUID_MODULE); + if (file != NULL) { + data = preload_fetch_addr(file); + size = preload_fetch_size(file); + if (data != NULL) { + /* + * The preloaded data may include trailing whitespace, almost + * certainly a newline; skip over any whitespace or + * non-printable characters to be safe. + */ + while (size > 0 && data[size - 1] <= 0x20) { + data[size--] = '\0'; + } + if (validate_uuid(data, size, NULL, 0) == 0) { + (void)strlcpy(prison0.pr_hostuuid, data, + size + 1); + } else if (bootverbose) { + printf("hostuuid: preload data malformed: '%s'", + data); + } + } + } + if (bootverbose) + printf("hostuuid: using %s\n", prison0.pr_hostuuid); } /*