71 - sizeof(zone_path_t), offsetof(zone_path_t, avl_link_next)); |
60 - sizeof(zone_path_t), offsetof(zone_path_t, avl_link_next)); |
72 - while ((name = getzoneent(cookie)) != NULL) { |
61 - while ((name = getzoneent(cookie)) != NULL) { |
73 - if (strcmp(name, "global") == 0) |
62 - if (strcmp(name, "global") == 0) |
74 - continue; |
63 - continue; |
75 - if (zone_get_state(name, &state_num) != Z_OK) { |
64 - if (zone_get_state(name, &state_num) != Z_OK) { |
76 - dE("Could not get zone state for %s\n", name); |
65 - dE("Could not get zone state for %s", name); |
77 - continue; |
66 - continue; |
78 - } else if (state_num > ZONE_STATE_CONFIGURED) { |
67 - } else if (state_num > ZONE_STATE_CONFIGURED) { |
79 - temp = malloc(sizeof(zone_path_t)); |
68 - temp = malloc(sizeof(zone_path_t)); |
80 - if (temp == NULL) { |
69 - if (temp == NULL) { |
81 - dE("Memory alloc failed\n"); |
70 - dE("Memory alloc failed"); |
82 - return(1); |
71 - return(1); |
83 - } |
72 - } |
84 - if (zone_get_zonepath(name, rpath, |
73 - if (zone_get_zonepath(name, rpath, |
85 - sizeof(rpath)) != Z_OK) { |
74 - sizeof(rpath)) != Z_OK) { |
86 - dE("Could not get zone path for %s\n", |
75 - dE("Could not get zone path for %s", |
87 - name); |
76 - name); |
88 - continue; |
77 - continue; |
89 + rc_conn_t *conn; |
78 - } |
90 + rc_err_t status; |
|
91 + rc_instance_t *zone_inst; |
|
92 + adr_name_t **name_list; |
|
93 + int name_count, i, prop_count; |
|
94 + char *zone_name; |
|
95 + char *zone_state; |
|
96 + zonemgr_Resource_t global = { .zr_type = "global" }; |
|
97 + zonemgr_Property_t **result; |
|
98 + zonemgr_Result_t *error; |
|
99 + const char *prop[] = {"zonepath"}; |
|
100 + char *zonepath; |
|
101 + char *p; |
|
102 + char rpath[PATH_MAX]; |
|
103 + |
|
104 + /* Connect to rad */ |
|
105 + conn = rc_connect_unix(NULL, NULL); |
|
106 + if (conn == NULL) { |
|
107 + dE("Unable to connect to rad.\n"); |
|
108 + return (1); |
|
109 + } |
|
110 + status = zonemgr_Zone__rad_list(conn, _B_TRUE, NS_GLOB, &name_list, |
|
111 + &name_count, 0); |
|
112 + if (status != RCE_OK) { |
|
113 + dE("Zonemgr lookup failed.\n"); |
|
114 + goto error; |
|
115 + } |
|
116 + if (name_count > 0) { |
|
117 + top = calloc(name_count + 1, PATH_MAX); |
|
118 + if (top == NULL) { |
|
119 + dE("Memory error.\n"); |
|
120 + return (1); |
|
121 + } |
|
122 + } |
|
123 + for (i = 0; i < name_count; i++) { |
|
124 + int rc; |
|
125 + status = rc_lookup(conn, name_list[i], NULL, _B_TRUE, |
|
126 + &zone_inst); |
|
127 + if (status != RCE_OK) { |
|
128 + goto error; |
|
129 + } |
|
130 + status = zonemgr_Zone_get_name(zone_inst, &zone_name); |
|
131 + if (status != RCE_OK) { |
|
132 + goto error; |
|
133 + } |
|
134 + dE("zone name:%s\n", zone_name); |
|
135 + status = zonemgr_Zone_get_state(zone_inst, &zone_state); |
|
136 + if (status != RCE_OK) { |
|
137 + dE("Failed to get state\n"); |
|
138 + return(1); |
|
139 + } |
|
140 + dE("zone state:%s\n", zone_state); |
|
141 + if (strcmp(zone_state, "incomplete") != 0 && |
|
142 + strcmp(zone_state, "running") != 0 && |
|
143 + strcmp(zone_state, "installed") != 0) { |
|
144 + free(zone_name); |
|
145 + free(zone_state); |
|
146 + continue; |
|
147 + } |
|
148 + status = zonemgr_Zone_getResourceProperties(zone_inst, &global, |
|
149 + prop, 1, &result, &prop_count, &error); |
|
150 + if (status == RCE_SERVER_OBJECT) { |
|
151 + dE("error code:%d: %s\n", |
|
152 + error->zr_code ? *error->zr_code : 0, |
|
153 + error->zr_str ? error->zr_str : ""); |
|
154 + } else if (status != RCE_OK) { |
|
155 + dE("Internal RAD error: %s\n", rc_err_string(status)); |
|
156 + } |
|
157 + zonepath = strdup(result[0]->zp_value); |
|
158 + dE("zonepath :%s\n", zonepath); |
|
159 + assert(prop_count == 1); |
|
160 + rpath[0] = '\0'; |
|
161 + if (zonepath != NULL && strlen(zonepath) > 0 ) { |
|
162 + if ((p = strstr(zonepath, "%{zonename}")) != NULL) { |
|
163 + *p = '\0'; |
|
164 + snprintf(rpath, sizeof(rpath), "%s%s",zonepath, |
|
165 + strdup(zone_name)); |
|
166 + } else { |
|
167 + snprintf(rpath, sizeof(rpath), "%s", zonepath); |
|
168 } |
|
169 - if (realpath(rpath, temp->zpath) != NULL) |
79 - if (realpath(rpath, temp->zpath) != NULL) |
170 - avl_add(&avl_tree_list, temp); |
80 - avl_add(&avl_tree_list, temp); |
171 + resolvepath(rpath, &(top[i*PATH_MAX]), ((size_t) PATH_MAX -1)); |
81 - } |
172 + dE("zonepath after resolvepath:%s\n", &(top[i*PATH_MAX])); |
82 - } |
|
83 - endzoneent(cookie); |
|
84 - return (0); |
|
85 + rc_conn_t *conn; |
|
86 + rc_err_t status; |
|
87 + rc_instance_t *zone_inst; |
|
88 + adr_name_t **name_list; |
|
89 + int name_count, i, prop_count; |
|
90 + char *zone_name; |
|
91 + char *zone_state; |
|
92 + zonemgr_Resource_t global = { .zr_type = "global" }; |
|
93 + zonemgr_Property_t **result; |
|
94 + zonemgr_Result_t *error; |
|
95 + const char *prop[] = {"zonepath"}; |
|
96 + char *zonepath; |
|
97 + char *p; |
|
98 + char rpath[PATH_MAX]; |
173 + |
99 + |
174 } |
100 + /* Connect to rad */ |
175 + zonemgr_Result_free(error); |
101 + conn = rc_connect_unix(NULL, NULL); |
176 + zonemgr_Property_array_free(result, prop_count); |
102 + if (conn == NULL) { |
177 + free(zone_name); |
103 + dE("Unable to connect to rad.\n"); |
178 + free(zone_state); |
104 + return (1); |
179 } |
105 + } |
180 - endzoneent(cookie); |
106 + status = zonemgr_Zone__rad_list(conn, _B_TRUE, NS_GLOB, &name_list, |
181 return (0); |
107 + &name_count, 0); |
|
108 + if (status != RCE_OK) { |
|
109 + dE("Zonemgr lookup failed.\n"); |
|
110 + goto error; |
|
111 + } |
|
112 + if (name_count > 0) { |
|
113 + top = calloc(name_count + 1, PATH_MAX); |
|
114 + if (top == NULL) { |
|
115 + dE("Memory error.\n"); |
|
116 + return (1); |
|
117 + } |
|
118 + } |
|
119 + for (i = 0; i < name_count; i++) { |
|
120 + int rc; |
|
121 + status = rc_lookup(conn, name_list[i], NULL, _B_TRUE, |
|
122 + &zone_inst); |
|
123 + if (status != RCE_OK) { |
|
124 + goto error; |
|
125 + } |
|
126 + status = zonemgr_Zone_get_name(zone_inst, &zone_name); |
|
127 + if (status != RCE_OK) { |
|
128 + goto error; |
|
129 + } |
|
130 + dE("zone name:%s\n", zone_name); |
|
131 + status = zonemgr_Zone_get_state(zone_inst, &zone_state); |
|
132 + if (status != RCE_OK) { |
|
133 + dE("Failed to get state\n"); |
|
134 + return(1); |
|
135 + } |
|
136 + dE("zone state:%s\n", zone_state); |
|
137 + if (strcmp(zone_state, "incomplete") != 0 && |
|
138 + strcmp(zone_state, "running") != 0 && |
|
139 + strcmp(zone_state, "installed") != 0) { |
|
140 + free(zone_name); |
|
141 + free(zone_state); |
|
142 + continue; |
|
143 + } |
|
144 + status = zonemgr_Zone_getResourceProperties(zone_inst, &global, |
|
145 + prop, 1, &result, &prop_count, &error); |
|
146 + if (status == RCE_SERVER_OBJECT) { |
|
147 + dE("error code:%d: %s\n", |
|
148 + error->zr_code ? *error->zr_code : 0, |
|
149 + error->zr_str ? error->zr_str : ""); |
|
150 + } else if (status != RCE_OK) { |
|
151 + dE("Internal RAD error: %s\n", rc_err_string(status)); |
|
152 + } |
|
153 + zonepath = strdup(result[0]->zp_value); |
|
154 + dE("zonepath :%s\n", zonepath); |
|
155 + assert(prop_count == 1); |
|
156 + rpath[0] = '\0'; |
|
157 + if (zonepath != NULL && strlen(zonepath) > 0 ) { |
|
158 + if ((p = strstr(zonepath, "%{zonename}")) != NULL) { |
|
159 + *p = '\0'; |
|
160 + snprintf(rpath, sizeof(rpath), "%s%s",zonepath, |
|
161 + strdup(zone_name)); |
|
162 + } else { |
|
163 + snprintf(rpath, sizeof(rpath), "%s", zonepath); |
|
164 + } |
|
165 + resolvepath(rpath, &(top[i*PATH_MAX]), ((size_t) PATH_MAX -1)); |
|
166 + dE("zonepath after resolvepath:%s\n", &(top[i*PATH_MAX])); |
|
167 + } |
|
168 + zonemgr_Result_free(error); |
|
169 + zonemgr_Property_array_free(result, prop_count); |
|
170 + free(zone_name); |
|
171 + free(zone_state); |
|
172 + } |
|
173 + return (0); |
182 +error: |
174 +error: |
183 + /* disconnect from rad */ |
175 + /* disconnect from rad */ |
184 + rc_disconnect(conn); |
176 + rc_disconnect(conn); |
185 + return (1); |
177 + return(1); |
186 } |
178 } |
187 |
179 |
188 static void free_zones_path_list() |
180 static void free_zones_path_list() |
189 { |
181 { |
190 - zone_path_t *temp; |
182 - zone_path_t *temp; |