Print this page




 109                     strerror(err));
 110                 return (err);
 111         }
 112         return (err);
 113 }
 114 
 115 static void
 116 dlmgmt_door_fini(void)
 117 {
 118         if (dlmgmt_door_fd == -1)
 119                 return;
 120 
 121         if (door_revoke(dlmgmt_door_fd) == -1) {
 122                 dlmgmt_log(LOG_WARNING, "door_revoke(%s) failed: %s",
 123                     DLMGMT_DOOR, strerror(errno));
 124         }
 125         (void) dlmgmt_set_doorfd(B_FALSE);
 126         dlmgmt_door_fd = -1;
 127 }
 128 
 129 static int
 130 dlmgmt_door_attach(zoneid_t zoneid, char *rootdir)
 131 {
 132         int     fd;
 133         int     err = 0;
 134         char    doorpath[MAXPATHLEN];
 135         struct stat statbuf;
 136 
 137         /* Handle running in a non-native branded zone (i.e. has /native) */
 138         (void) snprintf(doorpath, sizeof (doorpath), "%s/native%s",
 139             rootdir, DLMGMT_TMPFS_DIR);
 140         if (stat(doorpath, &statbuf) == 0) {
 141                 (void) snprintf(doorpath, sizeof (doorpath), "%s/native%s",
 142                     rootdir, DLMGMT_DOOR);
 143         } else {
 144                 (void) snprintf(doorpath, sizeof (doorpath), "%s%s",
 145                     rootdir, DLMGMT_DOOR);
 146         }
 147 
 148         /*
 149          * Create the door file for dlmgmtd.


 215         } else if ((statbuf.st_mode & S_IFMT) != S_IFDIR) {
 216                 return (ENOTDIR);
 217         }
 218 
 219         if ((chmod(tmpfsdir, 0755) < 0) ||
 220             (chown(tmpfsdir, UID_DLADM, GID_NETADM) < 0)) {
 221                 return (EPERM);
 222         }
 223 
 224         if ((err = dlmgmt_db_init(zoneid, rootdir)) != 0)
 225                 return (err);
 226         return (dlmgmt_door_attach(zoneid, rootdir));
 227 }
 228 
 229 /*
 230  * Initialize each running zone.
 231  */
 232 static int
 233 dlmgmt_allzones_init(void)
 234 {
 235         int             i;
 236         zoneid_t        *zids = NULL;
 237         uint_t          nzids, nzids_saved;
 238 
 239         if (zone_list(NULL, &nzids) != 0)
 240                 return (errno);
 241 again:
 242         nzids *= 2;
 243         if ((zids = malloc(nzids * sizeof (zoneid_t))) == NULL)
 244                 return (errno);
 245         nzids_saved = nzids;
 246         if (zone_list(zids, &nzids) != 0) {
 247                 free(zids);
 248                 return (errno);
 249         }
 250         if (nzids > nzids_saved) {
 251                 free(zids);
 252                 goto again;
 253         }
 254 
 255         for (i = 0; i < nzids; i++) {
 256                 int res;
 257                 zone_status_t status;
 258 
 259                 /*
 260                  * Skip over zones that have gone away or are going down
 261                  * since we got the list.  Process all zones in the list,
 262                  * logging errors for any that failed.
 263                  */
 264                 if (zone_getattr(zids[i], ZONE_ATTR_STATUS, &status,
 265                     sizeof (status)) < 0)
 266                         continue;
 267                 switch (status) {
 268                         case ZONE_IS_SHUTTING_DOWN:
 269                         case ZONE_IS_EMPTY:
 270                         case ZONE_IS_DOWN:
 271                         case ZONE_IS_DYING:
 272                         case ZONE_IS_DEAD:
 273                                 /* FALLTHRU */
 274                                 continue;
 275                         default:
 276                                 break;
 277                 }
 278                 if ((res = dlmgmt_zone_init(zids[i])) != 0) {
 279                         (void) fprintf(stderr, "zone (%ld) init error %s",
 280                             zids[i], strerror(res));
 281                         dlmgmt_log(LOG_ERR, "zone (%d) init error %s",
 282                             zids[i], strerror(res));
 283                 }
 284         }
 285         free(zids);
 286         return (0);
 287 }
 288 
 289 static int
 290 dlmgmt_init(void)
 291 {
 292         int     err;
 293         char    *fmri, *c;
 294         char    filename[MAXPATHLEN];
 295 
 296         if (dladm_open(&dld_handle) != DLADM_STATUS_OK) {
 297                 dlmgmt_log(LOG_ERR, "dladm_open() failed");
 298                 return (EPERM);
 299         }
 300 
 301         if (signal(SIGTERM, dlmgmtd_exit) == SIG_ERR ||
 302             signal(SIGINT, dlmgmtd_exit) == SIG_ERR) {
 303                 err = errno;
 304                 dlmgmt_log(LOG_ERR, "signal() for SIGTERM/INT failed: %s",
 305                     strerror(err));
 306                 return (err);




 109                     strerror(err));
 110                 return (err);
 111         }
 112         return (err);
 113 }
 114 
 115 static void
 116 dlmgmt_door_fini(void)
 117 {
 118         if (dlmgmt_door_fd == -1)
 119                 return;
 120 
 121         if (door_revoke(dlmgmt_door_fd) == -1) {
 122                 dlmgmt_log(LOG_WARNING, "door_revoke(%s) failed: %s",
 123                     DLMGMT_DOOR, strerror(errno));
 124         }
 125         (void) dlmgmt_set_doorfd(B_FALSE);
 126         dlmgmt_door_fd = -1;
 127 }
 128 
 129 int
 130 dlmgmt_door_attach(zoneid_t zoneid, char *rootdir)
 131 {
 132         int     fd;
 133         int     err = 0;
 134         char    doorpath[MAXPATHLEN];
 135         struct stat statbuf;
 136 
 137         /* Handle running in a non-native branded zone (i.e. has /native) */
 138         (void) snprintf(doorpath, sizeof (doorpath), "%s/native%s",
 139             rootdir, DLMGMT_TMPFS_DIR);
 140         if (stat(doorpath, &statbuf) == 0) {
 141                 (void) snprintf(doorpath, sizeof (doorpath), "%s/native%s",
 142                     rootdir, DLMGMT_DOOR);
 143         } else {
 144                 (void) snprintf(doorpath, sizeof (doorpath), "%s%s",
 145                     rootdir, DLMGMT_DOOR);
 146         }
 147 
 148         /*
 149          * Create the door file for dlmgmtd.


 215         } else if ((statbuf.st_mode & S_IFMT) != S_IFDIR) {
 216                 return (ENOTDIR);
 217         }
 218 
 219         if ((chmod(tmpfsdir, 0755) < 0) ||
 220             (chown(tmpfsdir, UID_DLADM, GID_NETADM) < 0)) {
 221                 return (EPERM);
 222         }
 223 
 224         if ((err = dlmgmt_db_init(zoneid, rootdir)) != 0)
 225                 return (err);
 226         return (dlmgmt_door_attach(zoneid, rootdir));
 227 }
 228 
 229 /*
 230  * Initialize each running zone.
 231  */
 232 static int
 233 dlmgmt_allzones_init(void)
 234 {
 235         int             err, i;
 236         zoneid_t        *zids = NULL;
 237         uint_t          nzids, nzids_saved;
 238 
 239         if (zone_list(NULL, &nzids) != 0)
 240                 return (errno);
 241 again:
 242         nzids *= 2;
 243         if ((zids = malloc(nzids * sizeof (zoneid_t))) == NULL)
 244                 return (errno);
 245         nzids_saved = nzids;
 246         if (zone_list(zids, &nzids) != 0) {
 247                 free(zids);
 248                 return (errno);
 249         }
 250         if (nzids > nzids_saved) {
 251                 free(zids);
 252                 goto again;
 253         }
 254 
 255         for (i = 0; i < nzids; i++) {
 256                 if ((err = dlmgmt_zone_init(zids[i])) != 0)



















 257                         break;
 258         }







 259         free(zids);
 260         return (err);
 261 }
 262 
 263 static int
 264 dlmgmt_init(void)
 265 {
 266         int     err;
 267         char    *fmri, *c;
 268         char    filename[MAXPATHLEN];
 269 
 270         if (dladm_open(&dld_handle) != DLADM_STATUS_OK) {
 271                 dlmgmt_log(LOG_ERR, "dladm_open() failed");
 272                 return (EPERM);
 273         }
 274 
 275         if (signal(SIGTERM, dlmgmtd_exit) == SIG_ERR ||
 276             signal(SIGINT, dlmgmtd_exit) == SIG_ERR) {
 277                 err = errno;
 278                 dlmgmt_log(LOG_ERR, "signal() for SIGTERM/INT failed: %s",
 279                     strerror(err));
 280                 return (err);