Print this page
10117 libbe needs smatch fixes


   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   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 /*
  23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  25  * Copyright 2016 Toomas Soome <tsoome@me.com>
  26  * Copyright (c) 2015 by Delphix. All rights reserved.
  27  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.

  28  */
  29 
  30 
  31 /*
  32  * System includes
  33  */
  34 #include <assert.h>
  35 #include <errno.h>
  36 #include <libgen.h>
  37 #include <libintl.h>
  38 #include <libnvpair.h>
  39 #include <libzfs.h>
  40 #include <libgen.h>
  41 #include <stdio.h>
  42 #include <stdlib.h>
  43 #include <string.h>
  44 #include <sys/stat.h>
  45 #include <sys/types.h>
  46 #include <sys/vfstab.h>
  47 #include <sys/param.h>


 253                 zpool_close(zph);
 254                 if (ret != 0) {
 255                         be_print_err(gettext("be_get_boot_args: failed to "
 256                             "get physpath\n"));
 257                         goto cleanup;
 258                 }
 259 
 260                 /* zpool_get_physpath() can return space separated list */
 261                 tmp = buf;
 262                 tmp = strsep(&tmp, " ");
 263 
 264                 if (kernel_options == NULL || *kernel_options == '\0')
 265                         (void) asprintf(fbarg, "/ %s "
 266                             "-B zfs-bootfs=%s,bootpath=\"%s\"\n", kernel,
 267                             node->be_root_ds, tmp);
 268                 else
 269                         (void) asprintf(fbarg, "/ %s %s "
 270                             "-B zfs-bootfs=%s,bootpath=\"%s\"\n", kernel,
 271                             kernel_options, node->be_root_ds, tmp);
 272 
 273                 if (fbarg == NULL)
 274                         ret = BE_ERR_NOMEM;
 275                 else
 276                         ret = 0;
 277         } else
 278                 ret = BE_ERR_NOMEM;
 279 cleanup:
 280         if (be_mounted == B_TRUE)
 281                 (void) _be_unmount(node->be_node_name, BE_UNMOUNT_FLAG_FORCE);
 282         be_free_list(be_nodes);
 283 done:
 284         free(mountpoint);
 285         free(bt.obe_name);
 286         free(bt.obe_root_ds);
 287         free(bt.obe_zpool);
 288         free(bt.obe_snap_name);
 289         free(bt.obe_altroot);
 290         be_zfs_fini();
 291         return (ret);
 292 }
 293 


3891         char *be_rpool = NULL;
3892         char *be_name = NULL;
3893         char *console = NULL;
3894         errno = 0;
3895 
3896         if (menu_file == NULL || menu_fp == NULL || mode == NULL)
3897                 return (BE_ERR_INVAL);
3898 
3899         menu_path = strdup(menu_file);
3900         if (menu_path == NULL)
3901                 return (BE_ERR_NOMEM);
3902 
3903         (void) dirname(menu_path);
3904         if (*menu_path == '.') {
3905                 free(menu_path);
3906                 return (BE_ERR_BAD_MENU_PATH);
3907         }
3908         if (mkdirp(menu_path,
3909             S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1 &&
3910             errno != EEXIST) {
3911                 free(menu_path);
3912                 be_print_err(gettext("be_create_menu: Failed to create the %s "
3913                     "directory: %s\n"), menu_path, strerror(errno));

3914                 return (errno_to_be_err(errno));
3915         }
3916         free(menu_path);
3917 
3918         /*
3919          * Check to see if this system supports grub
3920          */
3921         if (be_has_grub()) {
3922                 /*
3923                  * The grub menu is missing so we need to create it
3924                  * and fill in the first few lines.
3925                  */
3926                 FILE *temp_fp = fopen(menu_file, "a+");
3927                 if (temp_fp == NULL) {
3928                         *menu_fp = NULL;
3929                         return (errno_to_be_err(errno));
3930                 }
3931 
3932                 if ((console = be_get_console_prop()) != NULL) {
3933 




   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   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 /*
  23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  25  * Copyright 2016 Toomas Soome <tsoome@me.com>
  26  * Copyright (c) 2015 by Delphix. All rights reserved.
  27  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
  28  * Copyright (c) 2018, Joyent, Inc.
  29  */
  30 
  31 
  32 /*
  33  * System includes
  34  */
  35 #include <assert.h>
  36 #include <errno.h>
  37 #include <libgen.h>
  38 #include <libintl.h>
  39 #include <libnvpair.h>
  40 #include <libzfs.h>
  41 #include <libgen.h>
  42 #include <stdio.h>
  43 #include <stdlib.h>
  44 #include <string.h>
  45 #include <sys/stat.h>
  46 #include <sys/types.h>
  47 #include <sys/vfstab.h>
  48 #include <sys/param.h>


 254                 zpool_close(zph);
 255                 if (ret != 0) {
 256                         be_print_err(gettext("be_get_boot_args: failed to "
 257                             "get physpath\n"));
 258                         goto cleanup;
 259                 }
 260 
 261                 /* zpool_get_physpath() can return space separated list */
 262                 tmp = buf;
 263                 tmp = strsep(&tmp, " ");
 264 
 265                 if (kernel_options == NULL || *kernel_options == '\0')
 266                         (void) asprintf(fbarg, "/ %s "
 267                             "-B zfs-bootfs=%s,bootpath=\"%s\"\n", kernel,
 268                             node->be_root_ds, tmp);
 269                 else
 270                         (void) asprintf(fbarg, "/ %s %s "
 271                             "-B zfs-bootfs=%s,bootpath=\"%s\"\n", kernel,
 272                             kernel_options, node->be_root_ds, tmp);
 273 
 274                 if (*fbarg == NULL)
 275                         ret = BE_ERR_NOMEM;
 276                 else
 277                         ret = 0;
 278         } else
 279                 ret = BE_ERR_NOMEM;
 280 cleanup:
 281         if (be_mounted == B_TRUE)
 282                 (void) _be_unmount(node->be_node_name, BE_UNMOUNT_FLAG_FORCE);
 283         be_free_list(be_nodes);
 284 done:
 285         free(mountpoint);
 286         free(bt.obe_name);
 287         free(bt.obe_root_ds);
 288         free(bt.obe_zpool);
 289         free(bt.obe_snap_name);
 290         free(bt.obe_altroot);
 291         be_zfs_fini();
 292         return (ret);
 293 }
 294 


3892         char *be_rpool = NULL;
3893         char *be_name = NULL;
3894         char *console = NULL;
3895         errno = 0;
3896 
3897         if (menu_file == NULL || menu_fp == NULL || mode == NULL)
3898                 return (BE_ERR_INVAL);
3899 
3900         menu_path = strdup(menu_file);
3901         if (menu_path == NULL)
3902                 return (BE_ERR_NOMEM);
3903 
3904         (void) dirname(menu_path);
3905         if (*menu_path == '.') {
3906                 free(menu_path);
3907                 return (BE_ERR_BAD_MENU_PATH);
3908         }
3909         if (mkdirp(menu_path,
3910             S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1 &&
3911             errno != EEXIST) {

3912                 be_print_err(gettext("be_create_menu: Failed to create the %s "
3913                     "directory: %s\n"), menu_path, strerror(errno));
3914                 free(menu_path);
3915                 return (errno_to_be_err(errno));
3916         }
3917         free(menu_path);
3918 
3919         /*
3920          * Check to see if this system supports grub
3921          */
3922         if (be_has_grub()) {
3923                 /*
3924                  * The grub menu is missing so we need to create it
3925                  * and fill in the first few lines.
3926                  */
3927                 FILE *temp_fp = fopen(menu_file, "a+");
3928                 if (temp_fp == NULL) {
3929                         *menu_fp = NULL;
3930                         return (errno_to_be_err(errno));
3931                 }
3932 
3933                 if ((console = be_get_console_prop()) != NULL) {
3934