Print this page
eeprom

*** 298,342 **** eeprom_error(EXEC_FAIL, cmdline, ret); return (-1); } } ! #define BOOTADM_STR "bootadm: " /* ! * bootadm starts all error messages with "bootadm: ". ! * Add a note so users don't get confused on how they ran bootadm. */ static void output_error_msg(const char *msg) { ! size_t len = sizeof (BOOTADM_STR) - 1; ! if (strncmp(msg, BOOTADM_STR, len) == 0) { eeprom_error("error returned from %s\n", msg); } else if (msg[0] != '\0') { eeprom_error("%s\n", msg); } } static char * ! get_bootadm_value(char *name, const int quiet) { char *ptr, *ret_str, *end_ptr, *orig_ptr; char output[BUFSIZ]; int is_console, is_kernel = 0; size_t len; is_console = (strcmp(name, "console") == 0); if (strcmp(name, "boot-file") == 0) { is_kernel = 1; ! ptr = "/sbin/bootadm set-menu kernel 2>&1"; } else if (is_console || (strcmp(name, "boot-args") == 0)) { ! ptr = "/sbin/bootadm set-menu args 2>&1"; } else { ! eeprom_error("Unknown value in get_bootadm_value: %s\n", name); return (NULL); } if (exec_cmd(ptr, output, BUFSIZ) != 0) { if (quiet == 0) { --- 298,342 ---- eeprom_error(EXEC_FAIL, cmdline, ret); return (-1); } } ! #define GRUBADM_STR "grubadm: " /* ! * grubadm starts all error messages with "grubadm: ". ! * Add a note so users don't get confused on how they ran grubadm. */ static void output_error_msg(const char *msg) { ! size_t len = sizeof (GRUBADM_STR) - 1; ! if (strncmp(msg, GRUBADM_STR, len) == 0) { eeprom_error("error returned from %s\n", msg); } else if (msg[0] != '\0') { eeprom_error("%s\n", msg); } } static char * ! get_grubadm_value(char *name, const int quiet) { char *ptr, *ret_str, *end_ptr, *orig_ptr; char output[BUFSIZ]; int is_console, is_kernel = 0; size_t len; is_console = (strcmp(name, "console") == 0); if (strcmp(name, "boot-file") == 0) { is_kernel = 1; ! ptr = "/sbin/grubadm --number -1 --get-kernel 2>&1"; } else if (is_console || (strcmp(name, "boot-args") == 0)) { ! ptr = "/sbin/grubadm --number -1 --get-opts 2>&1"; } else { ! eeprom_error("Unknown value in get_grubadm_value: %s\n", name); return (NULL); } if (exec_cmd(ptr, output, BUFSIZ) != 0) { if (quiet == 0) {
*** 415,428 **** /* * If quiet is 1, print nothing if there is no value. If quiet is 0, print * a message. Return 1 if the value is printed, 0 otherwise. */ static int ! print_bootadm_value(char *name, const int quiet) { int rv = 0; ! char *value = get_bootadm_value(name, quiet); if ((value != NULL) && (value[0] != '\0')) { (void) printf("%s=%s\n", name, value); rv = 1; } else if (quiet == 0) { --- 415,428 ---- /* * If quiet is 1, print nothing if there is no value. If quiet is 0, print * a message. Return 1 if the value is printed, 0 otherwise. */ static int ! print_grubadm_value(char *name, const int quiet) { int rv = 0; ! char *value = get_grubadm_value(name, quiet); if ((value != NULL) && (value[0] != '\0')) { (void) printf("%s=%s\n", name, value); rv = 1; } else if (quiet == 0) {
*** 443,453 **** /* * The console property is kept in both menu.lst and bootenv.rc. The * menu.lst value takes precedence. */ if (strcmp(name, "console") == 0) { ! if (print_bootadm_value(name, 1) == 0) { if ((p = get_var(name, list)) != NULL) { (void) printf("%s=%s\n", name, p->val ? p->val : ""); } else { (void) printf("%s: data not available.\n", --- 443,453 ---- /* * The console property is kept in both menu.lst and bootenv.rc. The * menu.lst value takes precedence. */ if (strcmp(name, "console") == 0) { ! if (print_grubadm_value(name, 1) == 0) { if ((p = get_var(name, list)) != NULL) { (void) printf("%s=%s\n", name, p->val ? p->val : ""); } else { (void) printf("%s: data not available.\n",
*** 457,467 **** } else if (strcmp(name, "bootcmd") == 0) { bootcmd = getbootcmd(); (void) printf("%s=%s\n", name, bootcmd ? bootcmd : ""); } else if ((strcmp(name, "boot-file") == 0) || (strcmp(name, "boot-args") == 0)) { ! (void) print_bootadm_value(name, 0); } else if ((p = get_var(name, list)) == NULL) { (void) printf("%s: data not available.\n", name); } else { (void) printf("%s=%s\n", name, p->val ? p->val : ""); } --- 457,467 ---- } else if (strcmp(name, "bootcmd") == 0) { bootcmd = getbootcmd(); (void) printf("%s=%s\n", name, bootcmd ? bootcmd : ""); } else if ((strcmp(name, "boot-file") == 0) || (strcmp(name, "boot-args") == 0)) { ! (void) print_grubadm_value(name, 0); } else if ((p = get_var(name, list)) == NULL) { (void) printf("%s: data not available.\n", name); } else { (void) printf("%s=%s\n", name, p->val ? p->val : ""); }
*** 477,487 **** /* * The console property is kept both in menu.lst and bootenv.rc. * The menu.lst value takes precedence, so try printing that one * first. */ ! console_printed = print_bootadm_value("console", 1); for (e = list->next; e != list; e = e->next) { p = (benv_ent_t *)e->item; if (p->name != NULL) { if (((strcmp(p->name, "console") == 0) && --- 477,487 ---- /* * The console property is kept both in menu.lst and bootenv.rc. * The menu.lst value takes precedence, so try printing that one * first. */ ! console_printed = print_grubadm_value("console", 1); for (e = list->next; e != list; e = e->next) { p = (benv_ent_t *)e->item; if (p->name != NULL) { if (((strcmp(p->name, "console") == 0) &&
*** 492,503 **** continue; } (void) printf("%s=%s\n", p->name, p->val ? p->val : ""); } } ! (void) print_bootadm_value("boot-file", 1); ! (void) print_bootadm_value("boot-args", 1); } /* * Write a string to a file, quoted appropriately. We use single * quotes to prevent any variable expansion. Of course, we backslash-quote --- 492,503 ---- continue; } (void) printf("%s=%s\n", p->name, p->val ? p->val : ""); } } ! (void) print_grubadm_value("boot-file", 1); ! (void) print_grubadm_value("boot-args", 1); } /* * Write a string to a file, quoted appropriately. We use single * quotes to prevent any variable expansion. Of course, we backslash-quote
*** 521,540 **** } (void) putc('\'', fp); } static void ! set_bootadm_var(char *name, char *value) { char buf[BUFSIZ]; char output[BUFSIZ] = ""; char *console, *args; int is_console; if (verbose) { (void) printf("old:"); ! (void) print_bootadm_value(name, 0); } /* * For security, we single-quote whatever we run on the command line, * and we don't allow single quotes in the string. --- 521,540 ---- } (void) putc('\'', fp); } static void ! set_grubadm_var(char *name, char *value) { char buf[BUFSIZ]; char output[BUFSIZ] = ""; char *console, *args; int is_console; if (verbose) { (void) printf("old:"); ! (void) print_grubadm_value(name, 0); } /* * For security, we single-quote whatever we run on the command line, * and we don't allow single quotes in the string.
*** 545,597 **** return; } is_console = (strcmp(name, "console") == 0); if (strcmp(name, "boot-file") == 0) { ! (void) snprintf(buf, BUFSIZ, "/sbin/bootadm set-menu " ! "kernel='%s' 2>&1", value); } else if (is_console || (strcmp(name, "boot-args") == 0)) { if (is_console) { ! args = get_bootadm_value("boot-args", 1); console = value; } else { args = value; ! console = get_bootadm_value("console", 1); } if (((args == NULL) || (args[0] == '\0')) && ((console == NULL) || (console[0] == '\0'))) { ! (void) snprintf(buf, BUFSIZ, "/sbin/bootadm set-menu " ! "args= 2>&1"); } else if ((args == NULL) || (args[0] == '\0')) { ! (void) snprintf(buf, BUFSIZ, "/sbin/bootadm " ! "set-menu args='-B console=%s' 2>&1", console); } else if ((console == NULL) || (console[0] == '\0')) { ! (void) snprintf(buf, BUFSIZ, "/sbin/bootadm " ! "set-menu args='%s' 2>&1", args); } else if (strncmp(args, "-B ", 3) != 0) { ! (void) snprintf(buf, BUFSIZ, "/sbin/bootadm " ! "set-menu args='-B console=%s %s' 2>&1", console, args); } else { ! (void) snprintf(buf, BUFSIZ, "/sbin/bootadm " ! "set-menu args='-B console=%s,%s' 2>&1", console, args + 3); } } else { ! eeprom_error("Unknown value in set_bootadm_value: %s\n", name); return; } if (exec_cmd(buf, output, BUFSIZ) != 0) { output_error_msg(output); return; } if (verbose) { (void) printf("new:"); ! (void) print_bootadm_value(name, 0); } } /* * Returns 1 if bootenv.rc was modified, 0 otherwise. --- 545,597 ---- return; } is_console = (strcmp(name, "console") == 0); if (strcmp(name, "boot-file") == 0) { ! (void) snprintf(buf, BUFSIZ, "/sbin/grubadm --number -1 " ! "--set-kernel '%s' 2>&1", value); } else if (is_console || (strcmp(name, "boot-args") == 0)) { if (is_console) { ! args = get_grubadm_value("boot-args", 1); console = value; } else { args = value; ! console = get_grubadm_value("console", 1); } if (((args == NULL) || (args[0] == '\0')) && ((console == NULL) || (console[0] == '\0'))) { ! (void) snprintf(buf, BUFSIZ, "/sbin/grubadm --number -1 " ! "--set-opts '-B $ZFS_BOOTFS' 2>&1"); } else if ((args == NULL) || (args[0] == '\0')) { ! (void) snprintf(buf, BUFSIZ, "/sbin/grubadm --number -1 " ! "--set-opts '-B console=%s' 2>&1", console); } else if ((console == NULL) || (console[0] == '\0')) { ! (void) snprintf(buf, BUFSIZ, "/sbin/grubadm --number -1 " ! "--set-opts '%s' 2>&1", args); } else if (strncmp(args, "-B ", 3) != 0) { ! (void) snprintf(buf, BUFSIZ, "/sbin/grubadm --number -1 " ! "--set-opts '-B console=%s %s' 2>&1", console, args); } else { ! (void) snprintf(buf, BUFSIZ, "/sbin/grubadm --number -1 " ! "--set-opts '-B console=%s,%s' 2>&1", console, args + 3); } } else { ! eeprom_error("Unknown value in set_grubadm_value: %s\n", name); return; } if (exec_cmd(buf, output, BUFSIZ) != 0) { output_error_msg(output); return; } if (verbose) { (void) printf("new:"); ! (void) print_grubadm_value(name, 0); } } /* * Returns 1 if bootenv.rc was modified, 0 otherwise.
*** 605,626 **** if (strcmp(name, "bootcmd") == 0) return (0); if ((strcmp(name, "boot-file") == 0) || (strcmp(name, "boot-args") == 0)) { ! set_bootadm_var(name, val); return (0); } /* * The console property is kept in two places: menu.lst and bootenv.rc. * Update them both. We clear verbose to prevent duplicate messages. */ if (strcmp(name, "console") == 0) { old_verbose = verbose; verbose = 0; ! set_bootadm_var(name, val); verbose = old_verbose; } if (verbose) { (void) printf("old:"); --- 605,626 ---- if (strcmp(name, "bootcmd") == 0) return (0); if ((strcmp(name, "boot-file") == 0) || (strcmp(name, "boot-args") == 0)) { ! set_grubadm_var(name, val); return (0); } /* * The console property is kept in two places: menu.lst and bootenv.rc. * Update them both. We clear verbose to prevent duplicate messages. */ if (strcmp(name, "console") == 0) { old_verbose = verbose; verbose = 0; ! set_grubadm_var(name, val); verbose = old_verbose; } if (verbose) { (void) printf("old:");