1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
/* Copyright 2025 Brad Lanam Pleasant Hill CA */
#include "config.h"
#if _hdr_stdlib
# include <stdlib.h>
#endif
#if _hdr_string
# include <string.h>
#endif
#if _hdr_strings
# include <strings.h>
#endif
#if _hdr_memory
# include <memory.h>
#endif
#if _hdr_errno
# include <errno.h>
#endif
#if _hdr_unistd
# include <unistd.h>
#endif
#if _hdr_zone
# include <zone.h>
#endif
#include "di.h"
#include "dizone.h"
#include "distrutils.h"
#include "dioptions.h"
di_zone_info_t *
di_initialize_zones (di_opt_t *diopts)
{
di_zone_info_t *zinfo;
zinfo = (di_zone_info_t *) malloc (sizeof (di_zone_info_t));
zinfo->zoneCount = 0;
zinfo->zones = (di_zone_summ_t *) NULL;
#if _lib_zone_list && _lib_getzoneid && _lib_zone_getattr
zinfo->uid = geteuid ();
{
int i;
zoneid_t *zids = (zoneid_t *) NULL;
char *rpp;
char *rpend;
zinfo->myzoneid = getzoneid ();
if (zone_list (zids, &zinfo->zoneCount) == 0) {
if (zinfo->zoneCount > 0) {
zids = (zoneid_t *) malloc (sizeof (zoneid_t) * zinfo->zoneCount);
if (zids == (zoneid_t *) NULL) {
fprintf (stderr, "malloc failed in main () (1). errno %d\n", errno);
return zinfo;
}
zone_list (zids, &zinfo->zoneCount);
zinfo->zones = (di_zone_summ_t *) malloc (sizeof (di_zone_summ_t) *
zinfo->zoneCount);
if (zinfo->zones == (di_zone_summ_t *) NULL) {
fprintf (stderr, "malloc failed in main () (2). errno %d\n", errno);
return zinfo;
}
}
}
zinfo->globalIdx = 0;
for (i = 0; i < (int) zinfo->zoneCount; ++i) {
int len;
zinfo->zones [i].zoneid = zids [i];
len = (int) zone_getattr (zids [i], ZONE_ATTR_ROOT,
zinfo->zones [i].rootpath, MAXPATHLEN);
/* solaris: the length returned includes the null byte */
if (len >= 0) {
len -= 1;
zinfo->zones [i].rootpathlen = (Size_t) len;
if (zinfo->zones [i].zoneid != 0) {
rpp = zinfo->zones [i].rootpath + len;
rpend = zinfo->zones [i].rootpath + MAXPATHLEN;
rpp = stpecpy (rpp, rpend, "/");
}
if (zinfo->zones [i].zoneid == 0) {
zinfo->globalIdx = i;
}
len = (int) zone_getattr (zids [i], ZONE_ATTR_NAME,
zinfo->zones [i].name, ZONENAME_MAX);
if (*diopts->zoneDisplay == '\0' &&
zinfo->myzoneid == zinfo->zones [i].zoneid) {
stpecpy (diopts->zoneDisplay,
diopts->zoneDisplay + MAXPATHLEN, zinfo->zones [i].name);
}
if (diopts->optval [DI_OPT_DEBUG] > 4) {
printf ("zone:%d:%s:%s:%d\n", (int) zinfo->zones [i].zoneid,
zinfo->zones [i].name, zinfo->zones [i].rootpath,
(int) zinfo->zones [i].rootpathlen);
}
}
}
free ((void *) zids);
}
if (diopts->optval [DI_OPT_DEBUG] > 4) {
printf ("zone:my:%d:%s:glob:%d:\n", (int) zinfo->myzoneid,
diopts->zoneDisplay, zinfo->globalIdx);
}
#endif
return zinfo;
}
void
di_free_zones (di_zone_info_t *zinfo)
{
if (zinfo == NULL) {
return;
}
if (zinfo->zones != (di_zone_summ_t *) NULL) {
free (zinfo->zones);
}
free (zinfo);
}
|