Index: stand/defaults/loader.conf =================================================================== --- stand/defaults/loader.conf +++ 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: sys/kern/kern_jail.c =================================================================== --- sys/kern/kern_jail.c +++ sys/kern/kern_jail.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,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 +220,33 @@ 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 may include trailing whitespace, almost + * certainly a newline; skip over any non-printable + * characters including spaces to be safe. + */ + while (size > 0 && data[size - 1] <= 0x20) + --size; + if (size > 0 && size < HOSTUUIDLEN) + (void)strlcpy(prison0.pr_hostuuid, data, + size + 1); + } + } + if (bootverbose) + printf("hostuuid: using %s\n", prison0.pr_hostuuid); } /*