Print this page
Style cleanups, use nvlist_empty, variable renames, early variable initialisation.

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/zhack/zhack.c
          +++ new/usr/src/cmd/zhack/zhack.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2012 by Delphix. All rights reserved.
       24 + * Copyright (c) 2013 Steven Hartland. All rights reserved.
  24   25   */
  25   26  
  26   27  /*
  27   28   * zhack is a debugging tool that can write changes to ZFS pool using libzpool
  28   29   * for testing purposes. Altering pools with zhack is unsupported and may
  29   30   * result in corrupted pools.
  30   31   */
  31   32  
  32   33  #include <stdio.h>
  33   34  #include <stdlib.h>
↓ open down ↓ 112 lines elided ↑ open up ↑
 146  147          }
 147  148  
 148  149          g_importargs.unique = B_TRUE;
 149  150          g_importargs.can_be_active = readonly;
 150  151          g_pool = strdup(target);
 151  152          if ((sepp = strpbrk(g_pool, "/@")) != NULL)
 152  153                  *sepp = '\0';
 153  154          g_importargs.poolname = g_pool;
 154  155          pools = zpool_search_import(g_zfs, &g_importargs);
 155  156  
 156      -        if (pools == NULL || nvlist_next_nvpair(pools, NULL) == NULL) {
      157 +        if (nvlist_empty(pools)) {
 157  158                  if (!g_importargs.can_be_active) {
 158  159                          g_importargs.can_be_active = B_TRUE;
 159  160                          if (zpool_search_import(g_zfs, &g_importargs) != NULL ||
 160  161                              spa_open(target, &spa, FTAG) == 0) {
 161  162                                  fatal("cannot import '%s': pool is active; run "
 162  163                                      "\"zpool export %s\" first\n",
 163  164                                      g_pool, g_pool);
 164  165                          }
 165  166                  }
 166  167  
↓ open down ↓ 375 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX