Print this page


Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/zoneadmd/zoneadmd.c
          +++ new/usr/src/cmd/zoneadmd/zoneadmd.c
↓ open down ↓ 112 lines elided ↑ open up ↑
 113  113  zone_dochandle_t snap_hndl;     /* handle for snapshot created when ready */
 114  114  char zonepath[MAXNAMELEN];
 115  115  char pool_name[MAXNAMELEN];
 116  116  char default_brand[MAXNAMELEN];
 117  117  char brand_name[MAXNAMELEN];
 118  118  boolean_t zone_isnative;
 119  119  boolean_t zone_iscluster;
 120  120  boolean_t zone_islabeled;
 121  121  boolean_t shutdown_in_progress;
 122  122  static zoneid_t zone_id;
 123      -static zoneid_t zone_did = 0;
 124  123  dladm_handle_t dld_handle = NULL;
 125  124  
 126      -char pre_statechg_hook[2 * MAXPATHLEN];
 127      -char post_statechg_hook[2 * MAXPATHLEN];
      125 +static char pre_statechg_hook[2 * MAXPATHLEN];
      126 +static char post_statechg_hook[2 * MAXPATHLEN];
 128  127  char query_hook[2 * MAXPATHLEN];
 129  128  
 130  129  zlog_t logsys;
 131  130  
 132  131  mutex_t lock = DEFAULTMUTEX;    /* to serialize stuff */
 133  132  mutex_t msglock = DEFAULTMUTEX; /* for calling setlocale() */
 134  133  
 135  134  static sema_t scratch_sem;      /* for scratch zones */
 136  135  
 137  136  static char     zone_door_path[MAXPATHLEN];
↓ open down ↓ 149 lines elided ↑ open up ↑
 287  286   * indicates to the kernel which program should be launched as 'init'.
 288  287   *
 289  288   * Except for Z_OK, all other return values are treated as fatal.
 290  289   */
 291  290  static int
 292  291  filter_bootargs(zlog_t *zlogp, const char *inargs, char *outargs,
 293  292      char *init_file)
 294  293  {
 295  294          int argc = 0, argc_save;
 296  295          int i;
 297      -        int err = Z_OK;
      296 +        int err;
 298  297          char *arg, *lasts, **argv = NULL, **argv_save;
 299  298          char zonecfg_args[BOOTARGS_MAX];
 300  299          char scratchargs[BOOTARGS_MAX], *sargs;
 301  300          char scratchopt[3];
 302  301          char c;
 303  302  
 304  303          bzero(outargs, BOOTARGS_MAX);
 305  304  
 306  305          /*
 307  306           * If the user didn't specify transient boot arguments, check
 308  307           * to see if there were any specified in the zone configuration,
 309  308           * and use them if applicable.
 310  309           */
 311  310          if (inargs == NULL || inargs[0] == '\0')  {
      311 +                zone_dochandle_t handle;
      312 +                if ((handle = zonecfg_init_handle()) == NULL) {
      313 +                        zerror(zlogp, B_TRUE,
      314 +                            "getting zone configuration handle");
      315 +                        return (Z_BAD_HANDLE);
      316 +                }
      317 +                err = zonecfg_get_snapshot_handle(zone_name, handle);
      318 +                if (err != Z_OK) {
      319 +                        zerror(zlogp, B_FALSE,
      320 +                            "invalid configuration snapshot");
      321 +                        zonecfg_fini_handle(handle);
      322 +                        return (Z_BAD_HANDLE);
      323 +                }
      324 +
 312  325                  bzero(zonecfg_args, sizeof (zonecfg_args));
 313      -                (void) zonecfg_get_bootargs(snap_hndl, zonecfg_args,
      326 +                (void) zonecfg_get_bootargs(handle, zonecfg_args,
 314  327                      sizeof (zonecfg_args));
 315  328                  inargs = zonecfg_args;
      329 +                zonecfg_fini_handle(handle);
 316  330          }
 317  331  
 318  332          if (strlen(inargs) >= BOOTARGS_MAX) {
 319  333                  zerror(zlogp, B_FALSE, "boot argument string too long");
 320  334                  return (Z_INVAL);
 321  335          }
 322  336  
 323  337          (void) strlcpy(scratchargs, inargs, sizeof (scratchargs));
 324  338          sargs = scratchargs;
 325  339          while ((arg = strtok_r(sargs, " \t", &lasts)) != NULL) {
↓ open down ↓ 129 lines elided ↑ open up ↑
 455  469                  return (-1);
 456  470          }
 457  471          (void) chmod(ZONES_TMPDIR, S_IRWXU);
 458  472          return (0);
 459  473  }
 460  474  
 461  475  /*
 462  476   * Run the brand's pre-state change callback, if it exists.
 463  477   */
 464  478  static int
 465      -brand_prestatechg(zlog_t *zlogp, int state, int cmd, boolean_t debug)
      479 +brand_prestatechg(zlog_t *zlogp, int state, int cmd)
 466  480  {
 467  481          char cmdbuf[2 * MAXPATHLEN];
 468  482          const char *altroot;
 469  483  
 470  484          if (pre_statechg_hook[0] == '\0')
 471  485                  return (0);
 472  486  
 473  487          altroot = zonecfg_get_root();
 474  488          if (snprintf(cmdbuf, sizeof (cmdbuf), "%s %d %d %s", pre_statechg_hook,
 475  489              state, cmd, altroot) > sizeof (cmdbuf))
 476  490                  return (-1);
 477  491  
 478      -        if (do_subproc(zlogp, cmdbuf, NULL, debug) != 0)
      492 +        if (do_subproc(zlogp, cmdbuf, NULL) != 0)
 479  493                  return (-1);
 480  494  
 481  495          return (0);
 482  496  }
 483  497  
 484  498  /*
 485  499   * Run the brand's post-state change callback, if it exists.
 486  500   */
 487  501  static int
 488      -brand_poststatechg(zlog_t *zlogp, int state, int cmd, boolean_t debug)
      502 +brand_poststatechg(zlog_t *zlogp, int state, int cmd)
 489  503  {
 490  504          char cmdbuf[2 * MAXPATHLEN];
 491  505          const char *altroot;
 492  506  
 493  507          if (post_statechg_hook[0] == '\0')
 494  508                  return (0);
 495  509  
 496  510          altroot = zonecfg_get_root();
 497  511          if (snprintf(cmdbuf, sizeof (cmdbuf), "%s %d %d %s", post_statechg_hook,
 498  512              state, cmd, altroot) > sizeof (cmdbuf))
 499  513                  return (-1);
 500  514  
 501      -        if (do_subproc(zlogp, cmdbuf, NULL, debug) != 0)
      515 +        if (do_subproc(zlogp, cmdbuf, NULL) != 0)
 502  516                  return (-1);
 503  517  
 504  518          return (0);
 505  519  }
 506  520  
 507  521  /*
 508  522   * Notify zonestatd of the new zone.  If zonestatd is not running, this
 509  523   * will do nothing.
 510  524   */
 511  525  static void
↓ open down ↓ 16 lines elided ↑ open up ↑
 528  542          params.rbuf = NULL;
 529  543          params.rsize = NULL;
 530  544          (void) door_call(fd, &params);
 531  545          (void) close(fd);
 532  546  }
 533  547  
 534  548  /*
 535  549   * Bring a zone up to the pre-boot "ready" stage.  The mount_cmd argument is
 536  550   * 'true' if this is being invoked as part of the processing for the "mount"
 537  551   * subcommand.
 538      - *
 539      - * If a scratch zone mount (ALT_MOUNT) is being performed then do not
 540      - * call the state change hooks.
 541  552   */
 542  553  static int
 543      -zone_ready(zlog_t *zlogp, zone_mnt_t mount_cmd, int zstate, boolean_t debug)
      554 +zone_ready(zlog_t *zlogp, zone_mnt_t mount_cmd, int zstate)
 544  555  {
 545  556          int err;
 546      -        boolean_t snapped = B_FALSE;
 547  557  
 548      -        if ((snap_hndl = zonecfg_init_handle()) == NULL) {
 549      -                zerror(zlogp, B_TRUE, "getting zone configuration handle");
 550      -                goto bad;
 551      -        }
      558 +        if (!ALT_MOUNT(mount_cmd) &&
      559 +            brand_prestatechg(zlogp, zstate, Z_READY) != 0)
      560 +                return (-1);
      561 +
 552  562          if ((err = zonecfg_create_snapshot(zone_name)) != Z_OK) {
 553  563                  zerror(zlogp, B_FALSE, "unable to create snapshot: %s",
 554  564                      zonecfg_strerror(err));
 555  565                  goto bad;
 556  566          }
 557      -        snapped = B_TRUE;
 558  567  
 559      -        if (zonecfg_get_snapshot_handle(zone_name, snap_hndl) != Z_OK) {
 560      -                zerror(zlogp, B_FALSE, "invalid configuration snapshot");
      568 +        if ((zone_id = vplat_create(zlogp, mount_cmd)) == -1) {
      569 +                if ((err = zonecfg_destroy_snapshot(zone_name)) != Z_OK)
      570 +                        zerror(zlogp, B_FALSE, "destroying snapshot: %s",
      571 +                            zonecfg_strerror(err));
 561  572                  goto bad;
 562  573          }
 563      -
 564      -        if (zone_did == 0)
 565      -                zone_did = zone_get_did(zone_name);
 566      -
 567      -        if (!ALT_MOUNT(mount_cmd) &&
 568      -            brand_prestatechg(zlogp, zstate, Z_READY, debug) != 0)
 569      -                goto bad;
 570      -
 571      -        if ((zone_id = vplat_create(zlogp, mount_cmd, zone_did)) == -1)
 572      -                goto bad;
 573      -
 574  574          if (vplat_bringup(zlogp, mount_cmd, zone_id) != 0) {
 575  575                  bringup_failure_recovery = B_TRUE;
 576      -                (void) vplat_teardown(NULL, (mount_cmd != Z_MNT_BOOT), B_FALSE,
 577      -                    debug);
      576 +                (void) vplat_teardown(NULL, (mount_cmd != Z_MNT_BOOT), B_FALSE);
      577 +                if ((err = zonecfg_destroy_snapshot(zone_name)) != Z_OK)
      578 +                        zerror(zlogp, B_FALSE, "destroying snapshot: %s",
      579 +                            zonecfg_strerror(err));
 578  580                  goto bad;
 579  581          }
 580  582  
 581  583          if (!ALT_MOUNT(mount_cmd) &&
 582      -            brand_poststatechg(zlogp, zstate, Z_READY, debug) != 0)
      584 +            brand_poststatechg(zlogp, zstate, Z_READY) != 0)
 583  585                  goto bad;
 584  586  
 585  587          return (0);
 586  588  
 587  589  bad:
 588  590          /*
 589  591           * If something goes wrong, we up the zones's state to the target
 590  592           * state, READY, and then invoke the hook as if we're halting.
 591  593           */
 592  594          if (!ALT_MOUNT(mount_cmd))
 593      -                (void) brand_poststatechg(zlogp, ZONE_STATE_READY, Z_HALT,
 594      -                    debug);
 595      -
 596      -        if (snapped)
 597      -                if ((err = zonecfg_destroy_snapshot(zone_name)) != Z_OK)
 598      -                        zerror(zlogp, B_FALSE, "destroying snapshot: %s",
 599      -                            zonecfg_strerror(err));
 600      -        zonecfg_fini_handle(snap_hndl);
 601      -        snap_hndl = NULL;
      595 +                (void) brand_poststatechg(zlogp, ZONE_STATE_READY, Z_HALT);
 602  596          return (-1);
 603  597  }
 604  598  
 605  599  int
 606  600  init_template(void)
 607  601  {
 608  602          int fd;
 609  603          int err = 0;
 610  604  
 611  605          fd = open64(CTFS_ROOT "/process/template", O_RDWR);
↓ open down ↓ 160 lines elided ↑ open up ↑
 772  766                  errno = WEXITSTATUS(child_status);
 773  767                  zerror(zlogp, B_TRUE, "mount of %s failed", dir);
 774  768                  return (-1);
 775  769          }
 776  770  
 777  771          return (0);
 778  772  }
 779  773  
 780  774  /*
 781  775   * env variable name format
 782      - *      _ZONECFG_{resource name}_{identifying attr. name}_{property name}
 783      - * Any dashes (-) in the property names are replaced with underscore (_).
      776 + *      _ZONECFG;{resource name};{identifying attr. name};{property name}
 784  777   */
 785  778  static void
 786  779  set_zonecfg_env(char *rsrc, char *attr, char *name, char *val)
 787  780  {
 788  781          char *p;
 789  782          /* Enough for maximal name, rsrc + attr, & slop for ZONECFG & _'s */
 790  783          char nm[2 * MAXNAMELEN + 32];
 791  784  
 792  785          if (attr == NULL)
 793  786                  (void) snprintf(nm, sizeof (nm), "_ZONECFG_%s_%s", rsrc,
↓ open down ↓ 10 lines elided ↑ open up ↑
 804  797  }
 805  798  
 806  799  /*
 807  800   * Export zonecfg network and device properties into environment for the boot
 808  801   * and state change hooks.
 809  802   * If debug is true, export the brand hook debug env. variable as well.
 810  803   *
 811  804   * We could export more of the config in the future, as necessary.
 812  805   */
 813  806  static int
 814      -setup_subproc_env(boolean_t debug)
      807 +setup_subproc_env()
 815  808  {
 816  809          int res;
      810 +        zone_dochandle_t handle;
 817  811          struct zone_nwiftab ntab;
 818  812          struct zone_devtab dtab;
 819      -        struct zone_attrtab atab;
 820  813          char net_resources[MAXNAMELEN * 2];
 821  814          char dev_resources[MAXNAMELEN * 2];
 822  815  
 823      -        /* snap_hndl is null when called through the set_brand_env code path */
 824      -        if (snap_hndl == NULL)
 825      -                return (Z_OK);
      816 +        if ((handle = zonecfg_init_handle()) == NULL)
      817 +                exit(Z_NOMEM);
 826  818  
 827      -        net_resources[0] = '\0';
 828      -        if ((res = zonecfg_setnwifent(snap_hndl)) != Z_OK)
      819 +        if ((res = zonecfg_get_handle(zone_name, handle)) != Z_OK)
 829  820                  goto done;
 830  821  
 831      -        while (zonecfg_getnwifent(snap_hndl, &ntab) == Z_OK) {
      822 +        if ((res = zonecfg_setnwifent(handle)) != Z_OK)
      823 +                goto done;
      824 +
      825 +        while (zonecfg_getnwifent(handle, &ntab) == Z_OK) {
 832  826                  struct zone_res_attrtab *rap;
 833  827                  char *phys;
 834  828  
 835  829                  phys = ntab.zone_nwif_physical;
 836  830  
 837  831                  (void) strlcat(net_resources, phys, sizeof (net_resources));
 838  832                  (void) strlcat(net_resources, " ", sizeof (net_resources));
 839  833  
 840  834                  set_zonecfg_env(RSRC_NET, phys, "physical", phys);
 841  835  
↓ open down ↓ 6 lines elided ↑ open up ↑
 848  842                  set_zonecfg_env(RSRC_NET, phys, "global-nic",
 849  843                      ntab.zone_nwif_gnic);
 850  844                  set_zonecfg_env(RSRC_NET, phys, "mac-addr", ntab.zone_nwif_mac);
 851  845                  set_zonecfg_env(RSRC_NET, phys, "vlan-id",
 852  846                      ntab.zone_nwif_vlan_id);
 853  847  
 854  848                  for (rap = ntab.zone_nwif_attrp; rap != NULL;
 855  849                      rap = rap->zone_res_attr_next)
 856  850                          set_zonecfg_env(RSRC_NET, phys, rap->zone_res_attr_name,
 857  851                              rap->zone_res_attr_value);
 858      -                nwifent_free_attrs(&ntab);
 859  852          }
 860  853  
 861      -        (void) setenv("_ZONECFG_net_resources", net_resources, 1);
      854 +        (void) zonecfg_endnwifent(handle);
 862  855  
 863      -        (void) zonecfg_endnwifent(snap_hndl);
 864      -
 865      -        if ((res = zonecfg_setdevent(snap_hndl)) != Z_OK)
      856 +        if ((res = zonecfg_setdevent(handle)) != Z_OK)
 866  857                  goto done;
 867  858  
 868      -        while (zonecfg_getdevent(snap_hndl, &dtab) == Z_OK) {
      859 +        while (zonecfg_getdevent(handle, &dtab) == Z_OK) {
 869  860                  struct zone_res_attrtab *rap;
 870  861                  char *match;
 871  862  
 872  863                  match = dtab.zone_dev_match;
 873  864  
 874  865                  (void) strlcat(dev_resources, match, sizeof (dev_resources));
 875  866                  (void) strlcat(dev_resources, " ", sizeof (dev_resources));
 876  867  
 877  868                  for (rap = dtab.zone_dev_attrp; rap != NULL;
 878  869                      rap = rap->zone_res_attr_next)
 879  870                          set_zonecfg_env(RSRC_DEV, match,
 880  871                              rap->zone_res_attr_name, rap->zone_res_attr_value);
 881  872          }
 882  873  
 883      -        (void) zonecfg_enddevent(snap_hndl);
      874 +        (void) zonecfg_enddevent(handle);
 884  875  
 885      -        if ((res = zonecfg_setattrent(snap_hndl)) != Z_OK)
 886      -                goto done;
 887      -
 888      -        while (zonecfg_getattrent(snap_hndl, &atab) == Z_OK) {
 889      -                set_zonecfg_env("attr", NULL, atab.zone_attr_name,
 890      -                    atab.zone_attr_value);
 891      -        }
 892      -
 893      -        (void) zonecfg_endattrent(snap_hndl);
 894      -
 895      -        if (debug)
 896      -                (void) setenv("_ZONEADMD_brand_debug", "1", 1);
 897      -        else
 898      -                (void) setenv("_ZONEADMD_brand_debug", "", 1);
 899      -
 900  876          res = Z_OK;
 901  877  
 902  878  done:
      879 +        zonecfg_fini_handle(handle);
 903  880          return (res);
 904  881  }
 905  882  
 906      -void
 907      -nwifent_free_attrs(struct zone_nwiftab *np)
 908      -{
 909      -        struct zone_res_attrtab *rap;
 910      -
 911      -        for (rap = np->zone_nwif_attrp; rap != NULL; ) {
 912      -                struct zone_res_attrtab *tp = rap;
 913      -
 914      -                rap = rap->zone_res_attr_next;
 915      -                free(tp);
 916      -        }
 917      -}
 918      -
 919  883  /*
 920  884   * If retstr is not NULL, the output of the subproc is returned in the str,
 921  885   * otherwise it is output using zerror().  Any memory allocated for retstr
 922  886   * should be freed by the caller.
 923  887   */
 924  888  int
 925      -do_subproc(zlog_t *zlogp, char *cmdbuf, char **retstr, boolean_t debug)
      889 +do_subproc(zlog_t *zlogp, char *cmdbuf, char **retstr)
 926  890  {
 927  891          char buf[1024];         /* arbitrary large amount */
 928  892          char *inbuf;
 929  893          FILE *file;
 930  894          int status;
 931  895          int rd_cnt;
 932  896  
 933  897          if (retstr != NULL) {
 934  898                  if ((*retstr = malloc(1024)) == NULL) {
 935  899                          zerror(zlogp, B_FALSE, "out of memory");
 936  900                          return (-1);
 937  901                  }
 938  902                  inbuf = *retstr;
 939  903                  rd_cnt = 0;
 940  904          } else {
 941  905                  inbuf = buf;
 942  906          }
 943  907  
 944      -        if (setup_subproc_env(debug) != Z_OK) {
      908 +        if (setup_subproc_env() != Z_OK) {
 945  909                  zerror(zlogp, B_FALSE, "failed to setup environment");
 946  910                  return (-1);
 947  911          }
 948  912  
 949  913          file = popen(cmdbuf, "r");
 950  914          if (file == NULL) {
 951  915                  zerror(zlogp, B_TRUE, "could not launch: %s", cmdbuf);
 952  916                  return (-1);
 953  917          }
 954  918  
 955  919          while (fgets(inbuf, 1024, file) != NULL) {
 956  920                  if (retstr == NULL) {
 957      -                        if (zlogp != &logsys) {
 958      -                                int last = strlen(inbuf) - 1;
 959      -
 960      -                                if (inbuf[last] == '\n')
 961      -                                        inbuf[last] = '\0';
      921 +                        if (zlogp != &logsys)
 962  922                                  zerror(zlogp, B_FALSE, "%s", inbuf);
 963      -                        }
 964  923                  } else {
 965  924                          char *p;
 966  925  
 967  926                          rd_cnt += 1024 - 1;
 968  927                          if ((p = realloc(*retstr, rd_cnt + 1024)) == NULL) {
 969  928                                  zerror(zlogp, B_FALSE, "out of memory");
 970  929                                  (void) pclose(file);
 971  930                                  return (-1);
 972  931                          }
 973  932  
↓ open down ↓ 10 lines elided ↑ open up ↑
 984  943          }
 985  944          assert(WIFEXITED(status));
 986  945          if (WEXITSTATUS(status) == ZEXIT_EXEC) {
 987  946                  zerror(zlogp, B_FALSE, "failed to exec %s", cmdbuf);
 988  947                  return (-1);
 989  948          }
 990  949          return (WEXITSTATUS(status));
 991  950  }
 992  951  
 993  952  /*
 994      - * Get the path for this zone's init(1M) (or equivalent) process. First look
 995      - * for a zone-specific init-name attr, then get it from the brand.
 996      - */
 997      -static int
 998      -get_initname(brand_handle_t bh, char *initname, int len)
 999      -{
1000      -        struct zone_attrtab a;
1001      -
1002      -        bzero(&a, sizeof (a));
1003      -        (void) strlcpy(a.zone_attr_name, "init-name",
1004      -            sizeof (a.zone_attr_name));
1005      -
1006      -        if (zonecfg_lookup_attr(snap_hndl, &a) == Z_OK) {
1007      -                (void) strlcpy(initname, a.zone_attr_value, len);
1008      -                return (0);
1009      -        }
1010      -
1011      -        return (brand_get_initname(bh, initname, len));
1012      -}
1013      -
1014      -/*
1015      - * Get the restart-init flag for this zone's init(1M) (or equivalent) process.
1016      - * First look for a zone-specific restart-init attr, then get it from the brand.
1017      - */
1018      -static boolean_t
1019      -restartinit(brand_handle_t bh)
1020      -{
1021      -        struct zone_attrtab a;
1022      -
1023      -        bzero(&a, sizeof (a));
1024      -        (void) strlcpy(a.zone_attr_name, "restart-init",
1025      -            sizeof (a.zone_attr_name));
1026      -
1027      -        if (zonecfg_lookup_attr(snap_hndl, &a) == Z_OK) {
1028      -                if (strcmp(a.zone_attr_value, "false") == 0)
1029      -                        return (B_FALSE);
1030      -                return (B_TRUE);
1031      -        }
1032      -
1033      -        return (brand_restartinit(bh));
1034      -}
1035      -
1036      -/*
1037  953   * Get the app-svc-dependent flag for this zone's init process. This is a
1038  954   * zone-specific attr which controls the type of contract we create for the
1039  955   * zone's init. When true, the contract will include CT_PR_EV_EXIT in the fatal
1040  956   * set, so that when any service which is in the same contract exits, the init
1041  957   * application will be terminated.
      958 + *
      959 + * We use the global "snap_hndl", so no parameters get passed here.
1042  960   */
1043  961  static boolean_t
1044      -is_app_svc_dep(brand_handle_t bh)
      962 +is_app_svc_dep(void)
1045  963  {
1046  964          struct zone_attrtab a;
1047  965  
1048  966          bzero(&a, sizeof (a));
1049  967          (void) strlcpy(a.zone_attr_name, "app-svc-dependent",
1050  968              sizeof (a.zone_attr_name));
1051  969  
1052  970          if (zonecfg_lookup_attr(snap_hndl, &a) == Z_OK &&
1053  971              strcmp(a.zone_attr_value, "true") == 0) {
1054  972                  return (B_TRUE);
1055  973          }
1056  974  
1057  975          return (B_FALSE);
1058  976  }
1059  977  
1060  978  static int
1061      -zone_bootup(zlog_t *zlogp, const char *bootargs, int zstate, boolean_t debug)
      979 +zone_bootup(zlog_t *zlogp, const char *bootargs, int zstate)
1062  980  {
1063  981          zoneid_t zoneid;
1064  982          struct stat st;
1065  983          char rpath[MAXPATHLEN], initpath[MAXPATHLEN], init_file[MAXPATHLEN];
1066  984          char nbootargs[BOOTARGS_MAX];
1067  985          char cmdbuf[MAXPATHLEN];
1068  986          fs_callback_t cb;
1069  987          brand_handle_t bh;
1070  988          zone_iptype_t iptype;
1071  989          dladm_status_t status;
1072  990          char errmsg[DLADM_STRSIZE];
1073  991          int err;
1074  992          boolean_t restart_init;
1075  993          boolean_t app_svc_dep;
1076  994  
1077      -        if (brand_prestatechg(zlogp, zstate, Z_BOOT, debug) != 0)
      995 +        if (brand_prestatechg(zlogp, zstate, Z_BOOT) != 0)
1078  996                  return (-1);
1079  997  
1080  998          if ((zoneid = getzoneidbyname(zone_name)) == -1) {
1081  999                  zerror(zlogp, B_TRUE, "unable to get zoneid");
1082 1000                  goto bad;
1083 1001          }
1084 1002  
1085 1003          cb.zlogp = zlogp;
1086 1004          cb.zoneid = zoneid;
1087 1005          cb.mount_cmd = B_FALSE;
↓ open down ↓ 22 lines elided ↑ open up ↑
1110 1028          (void) strcpy(cmdbuf, EXEC_PREFIX);
1111 1029          if (brand_get_boot(bh, zone_name, zonepath, cmdbuf + EXEC_LEN,
1112 1030              sizeof (cmdbuf) - EXEC_LEN) != 0) {
1113 1031                  zerror(zlogp, B_FALSE,
1114 1032                      "unable to determine branded zone's boot callback");
1115 1033                  brand_close(bh);
1116 1034                  goto bad;
1117 1035          }
1118 1036  
1119 1037          /* Get the path for this zone's init(1M) (or equivalent) process.  */
1120      -        if (get_initname(bh, init_file, MAXPATHLEN) != 0) {
     1038 +        if (brand_get_initname(bh, init_file, MAXPATHLEN) != 0) {
1121 1039                  zerror(zlogp, B_FALSE,
1122 1040                      "unable to determine zone's init(1M) location");
1123 1041                  brand_close(bh);
1124 1042                  goto bad;
1125 1043          }
1126 1044  
1127      -        /* See if we should restart init if it dies. */
1128      -        restart_init = restartinit(bh);
     1045 +        /* See if this zone's brand should restart init if it dies. */
     1046 +        restart_init = brand_restartinit(bh);
1129 1047  
1130 1048          /*
1131 1049           * See if we need to setup contract dependencies between the zone's
1132 1050           * primary application and any of its services.
1133 1051           */
1134      -        app_svc_dep = is_app_svc_dep(bh);
     1052 +        app_svc_dep = is_app_svc_dep();
1135 1053  
1136 1054          brand_close(bh);
1137 1055  
1138 1056          err = filter_bootargs(zlogp, bootargs, nbootargs, init_file);
1139 1057          if (err != Z_OK)
1140 1058                  goto bad;
1141 1059  
1142 1060          assert(init_file[0] != '\0');
1143 1061  
1144 1062          /*
↓ open down ↓ 5 lines elided ↑ open up ↑
1150 1068                  goto bad;
1151 1069          }
1152 1070  
1153 1071          (void) snprintf(initpath, sizeof (initpath), "%s%s", rpath, init_file);
1154 1072  
1155 1073          if (lstat(initpath, &st) == -1) {
1156 1074                  zerror(zlogp, B_TRUE, "could not stat %s", initpath);
1157 1075                  goto bad;
1158 1076          }
1159 1077  
1160      -        if ((st.st_mode & S_IFMT) == S_IFLNK) {
1161      -                /* symlink, we'll have to wait and resolve when we boot */
1162      -        } else if ((st.st_mode & S_IXUSR) == 0) {
     1078 +        /*
     1079 +         * If a symlink, we'll have to wait and resolve when we boot,
     1080 +         * otherwise check the executable bits now.
     1081 +         */
     1082 +        if ((st.st_mode & S_IFMT) != S_IFLNK && (st.st_mode & S_IXUSR) == 0) {
1163 1083                  zerror(zlogp, B_FALSE, "%s is not executable", initpath);
1164 1084                  goto bad;
1165 1085          }
1166 1086  
1167 1087          /*
1168 1088           * Exclusive stack zones interact with the dlmgmtd running in the
1169 1089           * global zone.  dladm_zone_boot() tells dlmgmtd that this zone is
1170 1090           * booting, and loads its datalinks from the zone's datalink
1171 1091           * configuration file.
1172 1092           */
↓ open down ↓ 5 lines elided ↑ open up ↑
1178 1098                          goto bad;
1179 1099                  }
1180 1100          }
1181 1101  
1182 1102          /*
1183 1103           * If there is a brand 'boot' callback, execute it now to give the
1184 1104           * brand one last chance to do any additional setup before the zone
1185 1105           * is booted.
1186 1106           */
1187 1107          if ((strlen(cmdbuf) > EXEC_LEN) &&
1188      -            (do_subproc(zlogp, cmdbuf, NULL, debug) != Z_OK)) {
     1108 +            (do_subproc(zlogp, cmdbuf, NULL) != Z_OK)) {
1189 1109                  zerror(zlogp, B_FALSE, "%s failed", cmdbuf);
1190 1110                  goto bad;
1191 1111          }
1192 1112  
1193 1113          if (zone_setattr(zoneid, ZONE_ATTR_INITNAME, init_file, 0) == -1) {
1194 1114                  zerror(zlogp, B_TRUE, "could not set zone boot file");
1195 1115                  goto bad;
1196 1116          }
1197 1117  
1198 1118          if (zone_setattr(zoneid, ZONE_ATTR_BOOTARGS, nbootargs, 0) == -1) {
↓ open down ↓ 17 lines elided ↑ open up ↑
1216 1136           * Inform zonestatd of a new zone so that it can install a door for
1217 1137           * the zone to contact it.
1218 1138           */
1219 1139          notify_zonestatd(zone_id);
1220 1140  
1221 1141          if (zone_boot(zoneid) == -1) {
1222 1142                  zerror(zlogp, B_TRUE, "unable to boot zone");
1223 1143                  goto bad;
1224 1144          }
1225 1145  
1226      -        if (brand_poststatechg(zlogp, zstate, Z_BOOT, debug) != 0)
     1146 +        if (brand_poststatechg(zlogp, zstate, Z_BOOT) != 0)
1227 1147                  goto bad;
1228 1148  
1229 1149          /* Startup a thread to perform zfd logging/tty svc for the zone. */
1230 1150          create_log_thread(zlogp, zone_id);
1231 1151  
1232 1152          /* Startup a thread to perform memory capping for the zone. */
1233 1153          create_mcap_thread(zlogp, zone_id);
1234 1154  
1235 1155          return (0);
1236 1156  
1237 1157  bad:
1238 1158          /*
1239 1159           * If something goes wrong, we up the zones's state to the target
1240 1160           * state, RUNNING, and then invoke the hook as if we're halting.
1241 1161           */
1242      -        (void) brand_poststatechg(zlogp, ZONE_STATE_RUNNING, Z_HALT, debug);
     1162 +        (void) brand_poststatechg(zlogp, ZONE_STATE_RUNNING, Z_HALT);
1243 1163  
1244 1164          return (-1);
1245 1165  }
1246 1166  
1247 1167  static int
1248      -zone_halt(zlog_t *zlogp, boolean_t unmount_cmd, boolean_t rebooting, int zstate,
1249      -    boolean_t debug)
     1168 +zone_halt(zlog_t *zlogp, boolean_t unmount_cmd, boolean_t rebooting, int zstate)
1250 1169  {
1251 1170          int err;
1252 1171  
1253      -        /*
1254      -         * If performing a scratch zone unmount then do not call the
1255      -         * state change hooks.
1256      -         */
1257 1172          if (unmount_cmd == B_FALSE &&
1258      -            brand_prestatechg(zlogp, zstate, Z_HALT, debug) != 0)
     1173 +            brand_prestatechg(zlogp, zstate, Z_HALT) != 0)
1259 1174                  return (-1);
1260 1175  
1261 1176          /* Shutting down, stop the memcap thread */
1262 1177          destroy_mcap_thread();
1263 1178  
1264      -        if (vplat_teardown(zlogp, unmount_cmd, rebooting, debug) != 0) {
     1179 +        if (vplat_teardown(zlogp, unmount_cmd, rebooting) != 0) {
1265 1180                  if (!bringup_failure_recovery)
1266 1181                          zerror(zlogp, B_FALSE, "unable to destroy zone");
1267 1182                  destroy_log_thread();
1268 1183                  return (-1);
1269 1184          }
1270 1185  
1271 1186          /* Shut down is done, stop the log thread */
1272 1187          destroy_log_thread();
1273 1188  
1274 1189          if (unmount_cmd == B_FALSE &&
1275      -            brand_poststatechg(zlogp, zstate, Z_HALT, debug) != 0)
     1190 +            brand_poststatechg(zlogp, zstate, Z_HALT) != 0)
1276 1191                  return (-1);
1277 1192  
1278 1193          if ((err = zonecfg_destroy_snapshot(zone_name)) != Z_OK)
1279 1194                  zerror(zlogp, B_FALSE, "destroying snapshot: %s",
1280 1195                      zonecfg_strerror(err));
1281 1196  
1282      -        zonecfg_fini_handle(snap_hndl);
1283      -        snap_hndl = NULL;
1284      -
1285 1197          return (0);
1286 1198  }
1287 1199  
1288 1200  static int
1289 1201  zone_graceful_shutdown(zlog_t *zlogp)
1290 1202  {
1291 1203          zoneid_t zoneid;
1292 1204          pid_t child;
1293 1205          char cmdbuf[MAXPATHLEN];
1294 1206          brand_handle_t bh = NULL;
↓ open down ↓ 195 lines elided ↑ open up ↑
1490 1402  /* ARGSUSED */
1491 1403  static void
1492 1404  server(void *cookie, char *args, size_t alen, door_desc_t *dp,
1493 1405      uint_t n_desc)
1494 1406  {
1495 1407          ucred_t *uc = NULL;
1496 1408          const priv_set_t *eset;
1497 1409  
1498 1410          zone_state_t zstate;
1499 1411          zone_cmd_t cmd;
1500      -        boolean_t debug;
1501 1412          int init_status;
1502 1413          zone_cmd_arg_t *zargp;
1503 1414  
1504      -        boolean_t kernelcall = B_TRUE;
     1415 +        boolean_t kernelcall;
1505 1416  
1506 1417          int rval = -1;
1507 1418          uint64_t uniqid;
1508 1419          zoneid_t zoneid = -1;
1509 1420          zlog_t zlog;
1510 1421          zlog_t *zlogp;
1511 1422          zone_cmd_rval_t *rvalp;
1512 1423          size_t rlen = getpagesize(); /* conservative */
1513 1424          fs_callback_t cb;
1514 1425          brand_handle_t bh;
↓ open down ↓ 29 lines elided ↑ open up ↑
1544 1455          if (alen != sizeof (zone_cmd_arg_t)) {
1545 1456                  /*
1546 1457                   * This really shouldn't be happening.
1547 1458                   */
1548 1459                  zerror(&logsys, B_FALSE, "argument size (%d bytes) "
1549 1460                      "unexpected (expected %d bytes)", alen,
1550 1461                      sizeof (zone_cmd_arg_t));
1551 1462                  goto out;
1552 1463          }
1553 1464          cmd = zargp->cmd;
1554      -        debug = zargp->debug;
1555 1465          init_status = zargp->status;
1556 1466  
1557 1467          if (door_ucred(&uc) != 0) {
1558 1468                  zerror(&logsys, B_TRUE, "door_ucred");
1559 1469                  goto out;
1560 1470          }
1561 1471          eset = ucred_getprivset(uc, PRIV_EFFECTIVE);
1562 1472          if (ucred_getzoneid(uc) != GLOBAL_ZONEID ||
1563 1473              (eset != NULL ? !priv_ismember(eset, PRIV_SYS_CONFIG) :
1564 1474              ucred_geteuid(uc) != 0)) {
↓ open down ↓ 87 lines elided ↑ open up ↑
1652 1562                   * and die off.
1653 1563                   */
1654 1564                  zerror(zlogp, B_FALSE,
1655 1565                      "%s operation is invalid for zones in state '%s'",
1656 1566                      z_cmd_name(cmd), zone_state_str(zstate));
1657 1567                  break;
1658 1568  
1659 1569          case ZONE_STATE_INSTALLED:
1660 1570                  switch (cmd) {
1661 1571                  case Z_READY:
1662      -                        rval = zone_ready(zlogp, Z_MNT_BOOT, zstate, debug);
     1572 +                        rval = zone_ready(zlogp, Z_MNT_BOOT, zstate);
1663 1573                          if (rval == 0)
1664 1574                                  eventstream_write(Z_EVT_ZONE_READIED);
1665 1575                          zcons_statechanged();
1666 1576                          break;
1667 1577                  case Z_BOOT:
1668 1578                  case Z_FORCEBOOT:
1669 1579                          eventstream_write(Z_EVT_ZONE_BOOTING);
1670      -                        if ((rval = zone_ready(zlogp, Z_MNT_BOOT, zstate,
1671      -                            debug)) == 0) {
     1580 +                        if ((rval = zone_ready(zlogp, Z_MNT_BOOT, zstate))
     1581 +                            == 0) {
1672 1582                                  rval = zone_bootup(zlogp, zargp->bootbuf,
1673      -                                    zstate, debug);
     1583 +                                    zstate);
1674 1584                          }
1675 1585                          audit_put_record(zlogp, uc, rval, "boot");
1676 1586                          zcons_statechanged();
1677 1587                          if (rval != 0) {
1678 1588                                  bringup_failure_recovery = B_TRUE;
1679 1589                                  (void) zone_halt(zlogp, B_FALSE, B_FALSE,
1680      -                                    zstate, debug);
     1590 +                                    zstate);
1681 1591                                  eventstream_write(Z_EVT_ZONE_BOOTFAILED);
1682 1592                          }
1683 1593                          break;
1684 1594                  case Z_SHUTDOWN:
1685 1595                  case Z_HALT:
1686 1596                          if (kernelcall) /* Invalid; can't happen */
1687 1597                                  abort();
1688 1598                          /*
1689 1599                           * We could have two clients racing to halt this
1690 1600                           * zone; the second client loses, but his request
↓ open down ↓ 31 lines elided ↑ open up ↑
1722 1632                                   * zone file systems back into the scratch
1723 1633                                   * zone.  This is required when mounting
1724 1634                                   * non-native branded zones.
1725 1635                                   */
1726 1636                                  (void) strlcpy(zargp->bootbuf, "-U",
1727 1637                                      BOOTARGS_MAX);
1728 1638                          }
1729 1639  
1730 1640                          rval = zone_ready(zlogp,
1731 1641                              strcmp(zargp->bootbuf, "-U") == 0 ?
1732      -                            Z_MNT_UPDATE : Z_MNT_SCRATCH, zstate, debug);
     1642 +                            Z_MNT_UPDATE : Z_MNT_SCRATCH, zstate);
1733 1643                          if (rval != 0)
1734 1644                                  break;
1735 1645  
1736 1646                          eventstream_write(Z_EVT_ZONE_READIED);
1737 1647  
1738 1648                          /*
1739 1649                           * Get a handle to the default brand info.
1740 1650                           * We must always use the default brand file system
1741 1651                           * list when mounting the zone.
1742 1652                           */
↓ open down ↓ 41 lines elided ↑ open up ↑
1784 1694                          /*
1785 1695                           * We could have two clients racing to ready this
1786 1696                           * zone; the second client loses, but his request
1787 1697                           * doesn't fail, since the zone is now in the desired
1788 1698                           * state.
1789 1699                           */
1790 1700                          zerror(zlogp, B_FALSE, "zone is already ready");
1791 1701                          rval = 0;
1792 1702                          break;
1793 1703                  case Z_BOOT:
1794      -                case Z_FORCEBOOT:
1795 1704                          (void) strlcpy(boot_args, zargp->bootbuf,
1796 1705                              sizeof (boot_args));
1797 1706                          eventstream_write(Z_EVT_ZONE_BOOTING);
1798      -                        rval = zone_bootup(zlogp, zargp->bootbuf, zstate,
1799      -                            debug);
     1707 +                        rval = zone_bootup(zlogp, zargp->bootbuf, zstate);
1800 1708                          audit_put_record(zlogp, uc, rval, "boot");
1801 1709                          zcons_statechanged();
1802 1710                          if (rval != 0) {
1803 1711                                  bringup_failure_recovery = B_TRUE;
1804 1712                                  (void) zone_halt(zlogp, B_FALSE, B_TRUE,
1805      -                                    zstate, debug);
     1713 +                                    zstate);
1806 1714                                  eventstream_write(Z_EVT_ZONE_BOOTFAILED);
1807 1715                          }
1808 1716                          boot_args[0] = '\0';
1809 1717                          break;
1810 1718                  case Z_HALT:
1811 1719                          if (kernelcall) /* Invalid; can't happen */
1812 1720                                  abort();
1813      -                        if ((rval = zone_halt(zlogp, B_FALSE, B_FALSE, zstate,
1814      -                            debug)) != 0)
     1721 +                        if ((rval = zone_halt(zlogp, B_FALSE, B_FALSE, zstate))
     1722 +                            != 0)
1815 1723                                  break;
1816 1724                          zcons_statechanged();
1817 1725                          eventstream_write(Z_EVT_ZONE_HALTED);
1818 1726                          break;
1819 1727                  case Z_SHUTDOWN:
1820 1728                  case Z_REBOOT:
1821 1729                  case Z_NOTE_UNINSTALLING:
1822 1730                  case Z_MOUNT:
1823      -                case Z_FORCEMOUNT:
1824 1731                  case Z_UNMOUNT:
1825 1732                          if (kernelcall) /* Invalid; can't happen */
1826 1733                                  abort();
1827 1734                          zerror(zlogp, B_FALSE, "%s operation is invalid "
1828 1735                              "for zones in state '%s'", z_cmd_name(cmd),
1829 1736                              zone_state_str(zstate));
1830 1737                          rval = -1;
1831 1738                          break;
1832 1739                  }
1833 1740                  break;
1834 1741  
1835 1742          case ZONE_STATE_MOUNTED:
1836 1743                  switch (cmd) {
1837 1744                  case Z_UNMOUNT:
1838 1745                          if (kernelcall) /* Invalid; can't happen */
1839 1746                                  abort();
1840      -                        rval = zone_halt(zlogp, B_TRUE, B_FALSE, zstate, debug);
     1747 +                        rval = zone_halt(zlogp, B_TRUE, B_FALSE, zstate);
1841 1748                          if (rval == 0) {
1842 1749                                  eventstream_write(Z_EVT_ZONE_HALTED);
1843 1750                                  (void) sema_post(&scratch_sem);
1844 1751                          }
1845 1752                          break;
1846 1753                  default:
1847 1754                          if (kernelcall) /* Invalid; can't happen */
1848 1755                                  abort();
1849 1756                          zerror(zlogp, B_FALSE, "%s operation is invalid "
1850 1757                              "for zones in state '%s'", z_cmd_name(cmd),
↓ open down ↓ 1 lines elided ↑ open up ↑
1852 1759                          rval = -1;
1853 1760                          break;
1854 1761                  }
1855 1762                  break;
1856 1763  
1857 1764          case ZONE_STATE_RUNNING:
1858 1765          case ZONE_STATE_SHUTTING_DOWN:
1859 1766          case ZONE_STATE_DOWN:
1860 1767                  switch (cmd) {
1861 1768                  case Z_READY:
1862      -                        if ((rval = zone_halt(zlogp, B_FALSE, B_TRUE, zstate,
1863      -                            debug)) != 0)
     1769 +                        if ((rval = zone_halt(zlogp, B_FALSE, B_TRUE, zstate))
     1770 +                            != 0)
1864 1771                                  break;
1865 1772                          zcons_statechanged();
1866      -                        if ((rval = zone_ready(zlogp, Z_MNT_BOOT, zstate,
1867      -                            debug)) == 0)
     1773 +                        if ((rval = zone_ready(zlogp, Z_MNT_BOOT, zstate)) == 0)
1868 1774                                  eventstream_write(Z_EVT_ZONE_READIED);
1869 1775                          else
1870 1776                                  eventstream_write(Z_EVT_ZONE_HALTED);
1871 1777                          break;
1872 1778                  case Z_BOOT:
1873      -                case Z_FORCEBOOT:
1874 1779                          /*
1875 1780                           * We could have two clients racing to boot this
1876 1781                           * zone; the second client loses, but his request
1877 1782                           * doesn't fail, since the zone is now in the desired
1878 1783                           * state.
1879 1784                           */
1880 1785                          zerror(zlogp, B_FALSE, "zone is already booted");
1881 1786                          rval = 0;
1882 1787                          break;
1883 1788                  case Z_HALT:
1884 1789                          if (kernelcall) {
1885 1790                                  log_init_exit(init_status);
1886 1791                          } else {
1887 1792                                  log_init_exit(-1);
1888 1793                          }
1889      -                        if ((rval = zone_halt(zlogp, B_FALSE, B_FALSE, zstate,
1890      -                            debug)) != 0)
     1794 +                        if ((rval = zone_halt(zlogp, B_FALSE, B_FALSE, zstate))
     1795 +                            != 0)
1891 1796                                  break;
1892 1797                          eventstream_write(Z_EVT_ZONE_HALTED);
1893 1798                          zcons_statechanged();
1894 1799                          break;
1895 1800                  case Z_REBOOT:
1896 1801                          (void) strlcpy(boot_args, zargp->bootbuf,
1897 1802                              sizeof (boot_args));
1898 1803                          eventstream_write(Z_EVT_ZONE_REBOOTING);
1899      -                        if ((rval = zone_halt(zlogp, B_FALSE, B_TRUE, zstate,
1900      -                            debug)) != 0) {
     1804 +                        if ((rval = zone_halt(zlogp, B_FALSE, B_TRUE, zstate))
     1805 +                            != 0) {
1901 1806                                  eventstream_write(Z_EVT_ZONE_BOOTFAILED);
1902 1807                                  boot_args[0] = '\0';
1903 1808                                  break;
1904 1809                          }
1905 1810                          zcons_statechanged();
1906      -                        if ((rval = zone_ready(zlogp, Z_MNT_BOOT, zstate,
1907      -                            debug)) != 0) {
     1811 +                        if ((rval = zone_ready(zlogp, Z_MNT_BOOT, zstate)) !=
     1812 +                            0) {
1908 1813                                  eventstream_write(Z_EVT_ZONE_BOOTFAILED);
1909 1814                                  boot_args[0] = '\0';
1910 1815                                  break;
1911 1816                          }
1912      -                        rval = zone_bootup(zlogp, zargp->bootbuf, zstate,
1913      -                            debug);
     1817 +                        rval = zone_bootup(zlogp, zargp->bootbuf, zstate);
1914 1818                          audit_put_record(zlogp, uc, rval, "reboot");
1915 1819                          if (rval != 0) {
1916 1820                                  (void) zone_halt(zlogp, B_FALSE, B_TRUE,
1917      -                                    zstate, debug);
     1821 +                                    zstate);
1918 1822                                  eventstream_write(Z_EVT_ZONE_BOOTFAILED);
1919 1823                          }
1920 1824                          boot_args[0] = '\0';
1921 1825                          break;
1922 1826                  case Z_SHUTDOWN:
1923 1827                          if ((rval = zone_graceful_shutdown(zlogp)) == 0) {
1924 1828                                  wait_shut = B_TRUE;
1925 1829                          }
1926 1830                          break;
1927 1831                  case Z_NOTE_UNINSTALLING:
1928 1832                  case Z_MOUNT:
1929      -                case Z_FORCEMOUNT:
1930 1833                  case Z_UNMOUNT:
1931 1834                          zerror(zlogp, B_FALSE, "%s operation is invalid "
1932 1835                              "for zones in state '%s'", z_cmd_name(cmd),
1933 1836                              zone_state_str(zstate));
1934 1837                          rval = -1;
1935 1838                          break;
1936 1839                  }
1937 1840                  break;
1938 1841          default:
1939 1842                  abort();
↓ open down ↓ 188 lines elided ↑ open up ↑
2128 2031                  (void) close(doorfd);
2129 2032                  goto top;
2130 2033          }
2131 2034          ret = 0;
2132 2035  out:
2133 2036          (void) close(doorfd);
2134 2037          return (ret);
2135 2038  }
2136 2039  
2137 2040  /*
2138      - * Run the query hook with the 'env' parameter.  It should return a
2139      - * string of tab-delimited key-value pairs, each of which should be set
2140      - * in the environment.
2141      - *
2142      - * Because the env_vars string values become part of the environment, the
2143      - * string is static and we don't free it.
2144      - *
2145      - * This function is always called before zoneadmd forks and makes itself
2146      - * exclusive, so it is possible there could more than one instance of zoneadmd
2147      - * running in parallel at this point. Thus, we have no zonecfg snapshot and
2148      - * shouldn't take one yet (i.e. snap_hndl is NULL). Thats ok, since we don't
2149      - * need any zonecfg info to query for a brand-specific env value.
2150      - */
2151      -static int
2152      -set_brand_env(zlog_t *zlogp)
2153      -{
2154      -        int ret = 0;
2155      -        static char *env_vars = NULL;
2156      -        char buf[2 * MAXPATHLEN];
2157      -
2158      -        if (query_hook[0] == '\0' || env_vars != NULL)
2159      -                return (0);
2160      -
2161      -        if (snprintf(buf, sizeof (buf), "%s env", query_hook) > sizeof (buf))
2162      -                return (-1);
2163      -
2164      -        if (do_subproc(zlogp, buf, &env_vars, B_FALSE) != 0)
2165      -                return (-1);
2166      -
2167      -        if (env_vars != NULL) {
2168      -                char *sp;
2169      -
2170      -                sp = strtok(env_vars, "\t");
2171      -                while (sp != NULL) {
2172      -                        if (putenv(sp) != 0) {
2173      -                                ret = -1;
2174      -                                break;
2175      -                        }
2176      -                        sp = strtok(NULL, "\t");
2177      -                }
2178      -        }
2179      -
2180      -        return (ret);
2181      -}
2182      -
2183      -/*
2184 2041   * Setup the brand's pre and post state change callbacks, as well as the
2185 2042   * query callback, if any of these exist.
2186 2043   */
2187 2044  static int
2188 2045  brand_callback_init(brand_handle_t bh, char *zone_name)
2189 2046  {
2190 2047          (void) strlcpy(pre_statechg_hook, EXEC_PREFIX,
2191 2048              sizeof (pre_statechg_hook));
2192 2049  
2193 2050          if (brand_get_prestatechange(bh, zone_name, zonepath,
↓ open down ↓ 215 lines elided ↑ open up ↑
2409 2266          }
2410 2267  
2411 2268          if (priv_isfullset(privset) == B_FALSE) {
2412 2269                  zerror(zlogp, B_FALSE, "You lack sufficient privilege to "
2413 2270                      "run this command (all privs required)");
2414 2271                  priv_freeset(privset);
2415 2272                  return (1);
2416 2273          }
2417 2274          priv_freeset(privset);
2418 2275  
2419      -        if (set_brand_env(zlogp) != 0) {
2420      -                zerror(zlogp, B_FALSE, "Unable to setup brand's environment");
2421      -                return (1);
2422      -        }
2423      -
2424 2276          if (mkzonedir(zlogp) != 0)
2425 2277                  return (1);
2426 2278  
2427 2279          /*
2428 2280           * Pre-fork: setup shared state
2429 2281           */
2430 2282          if ((shstate = (void *)mmap(NULL, shstatelen,
2431 2283              PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, (off_t)0)) ==
2432 2284              MAP_FAILED) {
2433 2285                  zerror(zlogp, B_TRUE, "%s failed", "mmap");
↓ open down ↓ 274 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX