fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/utsname.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/param.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdarg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "libnsctl.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ncall/ncall.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Internal routine to fetch all the current nodes that are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * considered 'up'.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns the number of ncall_info structures that are valid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returned via the nodelist pointer, or -1 on an error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the call succeeds, then the memory returned via the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nodelist pointer needs to be freed by the caller.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_getcurrentnodes(ncall_node_t **nodelist)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_node_t *mynodelist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int save_errno = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlcmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodelist == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *nodelist = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open("/dev/ncall", O_RDONLY)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((size = ioctl(fd, NC_IOC_GETNETNODES, NULL)) < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlcmd = NC_IOC_GETNODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlcmd = NC_IOC_GETNETNODES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mynodelist = malloc(size * sizeof (*mynodelist));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mynodelist == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte save_errno = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ioctl(fd, ioctlcmd, mynodelist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte save_errno = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(mynodelist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fixup return value for single node ioctl */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlcmd == NC_IOC_GETNODE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *nodelist = mynodelist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = save_errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return the system id (the current value in the kernel
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * currently running).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on error return -1 and set errno.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_getsystemid(int *id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_node_t node;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int save_errno = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *id = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fd = open("/dev/ncall", O_RDONLY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fd < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&node, 0, sizeof (node));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = ioctl(fd, NC_IOC_GETNODE, &node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte save_errno = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *id = node.nc_nodeid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return 0, not the mirror node id as returned
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from the ioctl.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = save_errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Runtime Solaris release checking.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Compare the build release to the runtime release to check for an
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * acceptable match.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * build_ver - the string Solaris build release (e.g. "5.8")
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map - optional array of nsc_release_t defining
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * acceptable build release / runtime release
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * matches. If supplied, must end will a NULL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * array element. See src/head/nsctl.h for info.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reqd - used to return the required OS versions if the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return value is not -1. The returned string
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is readonly.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * TRUE - acceptable match
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FALSE - no match (component should not continue to run)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 - error (errno is set)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_check_release(const char *build_rel, nsc_release_t *map, char **reqd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct utsname uts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_release_t *mp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *sep = ", ";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *cp, *tofree, *last;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reqd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *reqd = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (build_rel == NULL || *build_rel == '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* assume that build_rel is the required release for now */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reqd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *reqd = (char *)build_rel;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uname(&uts) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* build release == runtime release is always acceptable */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(build_rel, uts.release) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tofree = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (mp = map; mp->build != NULL && mp->runtime != NULL; mp++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(mp->build, build_rel) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * found an entry for this build release
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - search for a match in the runtime releases
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reset reqd to this entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reqd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *reqd = (char *)mp->runtime;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * operate on a copy of the string since strtok
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is destructive.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tofree = cp = strdup(mp->runtime);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp = strtok_r(cp, sep, &last);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(cp, uts.release) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp = strtok_r(NULL, sep, &last);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tofree)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(tofree);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return the system id corresponding to name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on error return -1 and set errno.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_name_to_id(char *name, int *id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_node_t *nodes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nodecnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int slot;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *id = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodecnt = nsc_getcurrentnodes(&nodes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodecnt < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (slot = 0; slot < nodecnt; slot++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(name, nodes[slot].nc_nodename) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *id = nodes[slot].nc_nodeid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (slot >= nodecnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = ENOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(nodes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return the node name corresponding to system id
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on error return -1 and set errno.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The returned string has been strdup() and needs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to be freed by the caller.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_id_to_name(char **name, int id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_node_t *nodes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nodecnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int slot;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *foundname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *name = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte foundname = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodecnt = nsc_getcurrentnodes(&nodes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodecnt < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (slot = 0; slot < nodecnt; slot++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodes[slot].nc_nodeid == id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte foundname = strdup(nodes[slot].nc_nodename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (foundname) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *name = foundname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (slot >= nodecnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = ENOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(nodes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}