Print this page
8226 missing boot environments cause bootadm list-menu to segfault


   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2012 Milan Jurik. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  28  * Copyright 2016 Toomas Soome <tsoome@me.com>

  29  */
  30 
  31 /*
  32  * Loader menu management.
  33  */
  34 
  35 #include <stdio.h>
  36 #include <stdlib.h>
  37 #include <string.h>
  38 #include <wchar.h>
  39 #include <errno.h>
  40 #include <limits.h>
  41 #include <alloca.h>
  42 #include <unistd.h>
  43 #include <sys/types.h>
  44 #include <sys/stat.h>
  45 #include <sys/queue.h>
  46 #include <libbe.h>
  47 #include <ficl.h>
  48 #include <ficlplatform/emu.h>


 165         int i;
 166 
 167         for (i = 0; i < NUM_COLS; i++)
 168                 len[i] = hdr->cols[i].width + 1;
 169 
 170         STAILQ_FOREACH(entry, menu, next) {
 171                 size_t bootfs_len = strlen(entry->bootfs);
 172                 if (bootfs_len > len[2])
 173                         len[2] = bootfs_len + 1;
 174         }
 175 
 176         for (i = 0; i < NUM_COLS; i++)
 177                 hdr->cols[i].width = len[i];
 178 }
 179 
 180 static void
 181 print_menu_nodes(boolean_t parsable, struct hdr_info *hdr,
 182     struct menu_lst *menu)
 183 {
 184         struct menu_entry  *entry;
 185         int i = -1;
 186         int rv;
 187         be_node_list_t *be_nodes, *be_node;
 188 
 189         rv = be_list(NULL, &be_nodes);
 190         if (rv != BE_SUCCESS)
 191                 return;
 192 
 193         STAILQ_FOREACH(entry, menu, next) {
 194                 i++;

 195                 for (be_node = be_nodes; be_node;
 196                     be_node = be_node->be_next_node)
 197                         if (strcmp(be_node->be_root_ds, entry->bootfs) == 0)
 198                                 break;

 199 
 200                 if (parsable)
 201                         (void) printf("%d;%s;%s;%s\n", i,
 202                             be_node->be_active_on_boot == B_TRUE? "*" : "-",
 203                             entry->bootfs, entry->title);
 204                 else
 205                         (void) printf("%-*d %-*s %-*s %-*s\n",
 206                             hdr->cols[0].width, i,
 207                             hdr->cols[1].width,
 208                             be_node->be_active_on_boot == B_TRUE? "*" : "-",
 209                             hdr->cols[2].width, entry->bootfs,
 210                             hdr->cols[3].width, entry->title);


 211         }
 212         be_free_list(be_nodes);
 213 }
 214 
 215 static void
 216 print_nodes(boolean_t parsable, struct menu_lst *menu)
 217 {
 218         struct hdr_info hdr;
 219 
 220         if (!parsable) {
 221                 init_hdr_cols(&hdr);
 222                 count_widths(&hdr, menu);
 223                 print_hdr(&hdr);
 224         }
 225 
 226         print_menu_nodes(parsable, &hdr, menu);
 227 }
 228 
 229 error_t
 230 menu_read(struct menu_lst *menu, char *menu_path)




   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2012 Milan Jurik. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  28  * Copyright 2016 Toomas Soome <tsoome@me.com>
  29  * Copyright 2017 RackTop Systems.
  30  */
  31 
  32 /*
  33  * Loader menu management.
  34  */
  35 
  36 #include <stdio.h>
  37 #include <stdlib.h>
  38 #include <string.h>
  39 #include <wchar.h>
  40 #include <errno.h>
  41 #include <limits.h>
  42 #include <alloca.h>
  43 #include <unistd.h>
  44 #include <sys/types.h>
  45 #include <sys/stat.h>
  46 #include <sys/queue.h>
  47 #include <libbe.h>
  48 #include <ficl.h>
  49 #include <ficlplatform/emu.h>


 166         int i;
 167 
 168         for (i = 0; i < NUM_COLS; i++)
 169                 len[i] = hdr->cols[i].width + 1;
 170 
 171         STAILQ_FOREACH(entry, menu, next) {
 172                 size_t bootfs_len = strlen(entry->bootfs);
 173                 if (bootfs_len > len[2])
 174                         len[2] = bootfs_len + 1;
 175         }
 176 
 177         for (i = 0; i < NUM_COLS; i++)
 178                 hdr->cols[i].width = len[i];
 179 }
 180 
 181 static void
 182 print_menu_nodes(boolean_t parsable, struct hdr_info *hdr,
 183     struct menu_lst *menu)
 184 {
 185         struct menu_entry  *entry;
 186         int i = 0;
 187         int rv;
 188         be_node_list_t *be_nodes, *be_node;
 189 
 190         rv = be_list(NULL, &be_nodes);
 191         if (rv != BE_SUCCESS)
 192                 return;
 193 
 194         STAILQ_FOREACH(entry, menu, next) {
 195                 boolean_t active = B_FALSE;
 196 
 197                 for (be_node = be_nodes; be_node;
 198                     be_node = be_node->be_next_node)
 199                         if (strcmp(be_node->be_root_ds, entry->bootfs) == 0)
 200                                 if (be_node->be_active_on_boot)
 201                                         active = B_TRUE;
 202 
 203                 if (parsable)
 204                         (void) printf("%d;%s;%s;%s\n", i,
 205                             active == B_TRUE ? "*" : "-",
 206                             entry->bootfs, entry->title);
 207                 else
 208                         (void) printf("%-*d %-*s %-*s %-*s\n",
 209                             hdr->cols[0].width, i,
 210                             hdr->cols[1].width,
 211                             active == B_TRUE ? "*" : "-",
 212                             hdr->cols[2].width, entry->bootfs,
 213                             hdr->cols[3].width, entry->title);
 214 
 215                 i++;
 216         }
 217         be_free_list(be_nodes);
 218 }
 219 
 220 static void
 221 print_nodes(boolean_t parsable, struct menu_lst *menu)
 222 {
 223         struct hdr_info hdr;
 224 
 225         if (!parsable) {
 226                 init_hdr_cols(&hdr);
 227                 count_widths(&hdr, menu);
 228                 print_hdr(&hdr);
 229         }
 230 
 231         print_menu_nodes(parsable, &hdr, menu);
 232 }
 233 
 234 error_t
 235 menu_read(struct menu_lst *menu, char *menu_path)