4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/types.h>
27 #include <sys/utsname.h>
29 #include <sys/param.h>
39 #include <sys/ncall/ncall.h>
44 * Internal routine to fetch all the current nodes that are
46 * Returns the number of ncall_info structures that are valid
47 * returned via the nodelist pointer, or -1 on an error.
48 * If the call succeeds, then the memory returned via the
49 * nodelist pointer needs to be freed by the caller.
53 nsc_getcurrentnodes(ncall_node_t
**nodelist
)
55 ncall_node_t
*mynodelist
;
62 if (nodelist
== NULL
) {
67 if ((fd
= open("/dev/ncall", O_RDONLY
)) < 0) {
70 if ((size
= ioctl(fd
, NC_IOC_GETNETNODES
, NULL
)) < 1) {
72 ioctlcmd
= NC_IOC_GETNODE
;
74 ioctlcmd
= NC_IOC_GETNETNODES
;
77 mynodelist
= malloc(size
* sizeof (*mynodelist
));
78 if (mynodelist
== NULL
) {
81 rc
= ioctl(fd
, ioctlcmd
, mynodelist
);
86 /* fixup return value for single node ioctl */
87 if (ioctlcmd
== NC_IOC_GETNODE
)
89 *nodelist
= mynodelist
;
99 * return the system id (the current value in the kernel
100 * currently running).
102 * on error return -1 and set errno.
105 nsc_getsystemid(int *id
)
114 fd
= open("/dev/ncall", O_RDONLY
);
118 memset(&node
, 0, sizeof (node
));
120 rval
= ioctl(fd
, NC_IOC_GETNODE
, &node
);
124 *id
= node
.nc_nodeid
;
126 * Return 0, not the mirror node id as returned
140 * Runtime Solaris release checking.
142 * Compare the build release to the runtime release to check for an
146 * build_ver - the string Solaris build release (e.g. "5.8")
147 * map - optional array of nsc_release_t defining
148 * acceptable build release / runtime release
149 * matches. If supplied, must end will a NULL
150 * array element. See src/head/nsctl.h for info.
151 * reqd - used to return the required OS versions if the
152 * return value is not -1. The returned string
156 * TRUE - acceptable match
157 * FALSE - no match (component should not continue to run)
158 * -1 - error (errno is set)
162 nsc_check_release(const char *build_rel
, nsc_release_t
*map
, char **reqd
)
166 const char *sep
= ", ";
167 char *cp
, *tofree
, *last
;
173 if (build_rel
== NULL
|| *build_rel
== '\0') {
178 /* assume that build_rel is the required release for now */
180 *reqd
= (char *)build_rel
;
185 /* build release == runtime release is always acceptable */
186 if (strcmp(build_rel
, uts
.release
) == 0)
195 for (mp
= map
; mp
->build
!= NULL
&& mp
->runtime
!= NULL
; mp
++) {
196 if (strcmp(mp
->build
, build_rel
) == 0) {
198 * found an entry for this build release
199 * - search for a match in the runtime releases
202 /* reset reqd to this entry */
204 *reqd
= (char *)mp
->runtime
;
207 * operate on a copy of the string since strtok
210 tofree
= cp
= strdup(mp
->runtime
);
217 cp
= strtok_r(cp
, sep
, &last
);
219 if (strcmp(cp
, uts
.release
) == 0) {
224 cp
= strtok_r(NULL
, sep
, &last
);
239 * return the system id corresponding to name
241 * on error return -1 and set errno.
244 nsc_name_to_id(char *name
, int *id
)
253 nodecnt
= nsc_getcurrentnodes(&nodes
);
257 for (slot
= 0; slot
< nodecnt
; slot
++) {
258 if (strcmp(name
, nodes
[slot
].nc_nodename
) == 0) {
259 *id
= nodes
[slot
].nc_nodeid
;
263 if (slot
>= nodecnt
) {
273 * return the node name corresponding to system id
275 * on error return -1 and set errno.
276 * The returned string has been strdup() and needs
277 * to be freed by the caller.
280 nsc_id_to_name(char **name
, int id
)
291 nodecnt
= nsc_getcurrentnodes(&nodes
);
295 for (slot
= 0; slot
< nodecnt
; slot
++) {
296 if (nodes
[slot
].nc_nodeid
== id
) {
297 foundname
= strdup(nodes
[slot
].nc_nodename
);
307 if (slot
>= nodecnt
) {