From 62fad4a13fbcb1cfd051b7b63db5416d24076e4c Mon Sep 17 00:00:00 2001 From: "Simon L. B. Nielsen" Date: Sat, 15 Jul 2006 12:23:56 +0000 Subject: [PATCH] Add FreeBSD version information to the menu title so it's possible to see which release you are installing (really which FreeBSD version the installer is running, but that shouldn't matter in all normal cases). PR: bin/100309 Submitted by: Joao Barros (original version) Idea from: FreeBSD ideas page MFC after: 1 week --- usr.sbin/sysinstall/install.c | 18 +++--------------- usr.sbin/sysinstall/main.c | 12 ++++++++++++ usr.sbin/sysinstall/misc.c | 24 ++++++++++++++++++++++++ usr.sbin/sysinstall/sysinstall.h | 1 + 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/usr.sbin/sysinstall/install.c b/usr.sbin/sysinstall/install.c index 3ff7d8ec6771..f45a74c977fc 100644 --- a/usr.sbin/sysinstall/install.c +++ b/usr.sbin/sysinstall/install.c @@ -1182,20 +1182,6 @@ installFilesystems(dialogMenuItem *self) return DITEM_SUCCESS | DITEM_RESTORE; } -static char * -getRelname(void) -{ - static char buf[64]; - size_t sz = (sizeof buf) - 1; - - if (sysctlbyname("kern.osrelease", buf, &sz, NULL, 0) != -1) { - buf[sz] = '\0'; - return buf; - } - else - return ""; -} - /* Initialize various user-settable values to their defaults */ int installVarDefaults(dialogMenuItem *self) @@ -1203,7 +1189,9 @@ installVarDefaults(dialogMenuItem *self) char *cp, ncpus[10]; /* Set default startup options */ - variable_set2(VAR_RELNAME, getRelname(), 0); + cp = getsysctlbyname("kern.osrelease"); + variable_set2(VAR_RELNAME, cp, 0); + free(cp); variable_set2(VAR_CPIO_VERBOSITY, "high", 0); variable_set2(VAR_TAPE_BLOCKSIZE, DEFAULT_TAPE_BLOCKSIZE, 0); variable_set2(VAR_INSTALL_ROOT, "/", 0); diff --git a/usr.sbin/sysinstall/main.c b/usr.sbin/sysinstall/main.c index ca31125bb377..7af8d44b61d5 100644 --- a/usr.sbin/sysinstall/main.c +++ b/usr.sbin/sysinstall/main.c @@ -51,6 +51,7 @@ int main(int argc, char **argv) { int choice, scroll, curr, max, status; + char titlestr[80], *arch, *osrel, *ostype; /* Record name to be able to restart */ StartName = argv[0]; @@ -162,6 +163,17 @@ main(int argc, char **argv) if (RunningAsInit) configCountry(NULL); + /* Add FreeBSD version info to the menu title */ + arch = getsysctlbyname("hw.machine_arch"); + osrel = getsysctlbyname("kern.osrelease"); + ostype = getsysctlbyname("kern.ostype"); + snprintf(titlestr, sizeof(titlestr), "%s/%s %s - %s", ostype, arch, + osrel, MenuInitial.title); + free(arch); + free(osrel); + free(ostype); + MenuInitial.title = titlestr; + /* Begin user dialog at outer menu */ dialog_clear(); while (1) { diff --git a/usr.sbin/sysinstall/misc.c b/usr.sbin/sysinstall/misc.c index 07cbc81751d1..c978b76ea287 100644 --- a/usr.sbin/sysinstall/misc.c +++ b/usr.sbin/sysinstall/misc.c @@ -46,6 +46,7 @@ #include #include #include +#include /* Quick check to see if a file is readable */ Boolean @@ -527,3 +528,26 @@ restorescr(WINDOW *w) delwin(w); } +/* + * Get a sysctl variable as a string or "" if sysctl fails. + * Caller must free returned string. + */ +char * +getsysctlbyname(const char *sysctlname) +{ + char *buf; + size_t sz, buf_sz = 0; + const char unk_str[] = ""; + + sysctlbyname(sysctlname, NULL, &buf_sz, NULL, 0); + buf_sz = MAX(sizeof(unk_str), buf_sz) + 1; + sz = buf_sz - 1; + buf = (char *)safe_malloc(buf_sz); + + if (sysctlbyname(sysctlname, buf, &sz, NULL, 0) != -1) + buf[sz] = '\0'; + else + strlcpy(buf, unk_str, buf_sz); + + return buf; +} diff --git a/usr.sbin/sysinstall/sysinstall.h b/usr.sbin/sysinstall/sysinstall.h index afc1ab53f67f..4ec2bcf58d5a 100644 --- a/usr.sbin/sysinstall/sysinstall.h +++ b/usr.sbin/sysinstall/sysinstall.h @@ -784,6 +784,7 @@ extern int layoutDialogLoop(WINDOW *win, Layout *layout, ComposeObj **obj, extern WINDOW *savescr(void); extern void restorescr(WINDOW *w); extern char *sstrncpy(char *dst, const char *src, int size); +extern char *getsysctlbyname(const char *sysctlname); /* modules.c */ extern void driverFloppyCheck(void);