picld.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * CDDL HEADER START
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * The contents of this file are subject to the terms of the
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Common Development and Distribution License, Version 1.0 only
c869993e79c1eafbec61a56bf6cea848fe754c71xy * (the "License"). You may not use this file except in compliance
c869993e79c1eafbec61a56bf6cea848fe754c71xy * with the License.
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c869993e79c1eafbec61a56bf6cea848fe754c71xy * or http://www.opensolaris.org/os/licensing.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * See the License for the specific language governing permissions
c869993e79c1eafbec61a56bf6cea848fe754c71xy * and limitations under the License.
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * When distributing Covered Code, include this CDDL HEADER in each
c869993e79c1eafbec61a56bf6cea848fe754c71xy * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * If applicable, add the following below this CDDL HEADER, with the
c869993e79c1eafbec61a56bf6cea848fe754c71xy * fields enclosed by brackets "[]" replaced with your own identifying
c869993e79c1eafbec61a56bf6cea848fe754c71xy * information: Portions Copyright [yyyy] [name of copyright owner]
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * CDDL HEADER END
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Use is subject to license terms.
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy#pragma ident "%Z%%M% %I% %E% SMI"
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * PICL daemon
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy
fa25784ca4b51c206177d891a654f1d36a25d41fxy#include <stdio.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <stdlib.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <stdarg.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <string.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <libintl.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <locale.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <alloca.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <errno.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <assert.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <stropts.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <unistd.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <signal.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <pthread.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <synch.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <door.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <sys/door.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <fcntl.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <dlfcn.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <time.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <sys/utsname.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <sys/systeminfo.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <sys/stat.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <sys/wait.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <dirent.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <syslog.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <poll.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <limits.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <picl.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include "picl2door.h"
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <picltree.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include "ptree_impl.h"
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Log text messages
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define MUST_BE_ROOT gettext("this program must be run as root\n")
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define CD_ROOT_FAILED gettext("chdir to root failed\n")
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define INIT_FAILED gettext("ptree initialization failed\n")
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define DAEMON_RUNNING gettext("PICL daemon already running\n")
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define DOOR_FAILED gettext("Failed creating picld door\n")
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define SIGACT_FAILED \
c869993e79c1eafbec61a56bf6cea848fe754c71xy gettext("Failed to install signal handler for %s: %s\n")
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Constants
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define PICLD "picld"
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define DOS_PICL_REQUESTS_LIMIT 10000
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define SLIDING_INTERVAL_MILLISECONDS 1000
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define PICLD_MAJOR_REV 0x1
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define PICLD_MINOR_REV 0x0
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define DOS_SLEEPTIME_MS 1000
fa25784ca4b51c206177d891a654f1d36a25d41fxy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Macros
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define PICLD_VERSION(x, y) ((x << 8) | y)
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define PICL_CLIENT_REV(x) (x & 0xff)
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define MILLI_TO_NANO(x) (x * 1000000)
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyextern char **environ;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Module Variables
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic int logflag = 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic int doreinit = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic int door_id = -1;
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic int service_requests = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic hrtime_t orig_time;
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic hrtime_t sliding_interval_ms;
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic uint32_t dos_req_limit;
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic uint32_t dos_ms;
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic pthread_mutex_t dos_mutex = PTHREAD_MUTEX_INITIALIZER;
8bb4b220fdb894543e41a5f9037898cf3c3f312bglstatic rwlock_t init_lk;
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl/*
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl * This returns an error message to libpicl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_return_error(picl_callnumber_t cnum, picl_errno_t err)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_reterror_t ret_error;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret_error.cnum = PICL_CNUM_ERROR;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret_error.in_cnum = cnum;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret_error.errnum = err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret_error, sizeof (picl_reterror_t), NULL,
c869993e79c1eafbec61a56bf6cea848fe754c71xy 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * picld_init is called when a picl_initialize request is received
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_init(picl_service_t *req)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retinit_t ret_init;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int clmajrev;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy clmajrev = PICL_CLIENT_REV(req->req_init.clrev);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (clmajrev < PICL_VERSION_1)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(req->req_init.cnum, PICL_NOTSUPPORTED);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret_init.cnum = req->req_init.cnum;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret_init.rev = PICLD_VERSION(PICLD_MAJOR_REV, PICLD_MINOR_REV);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret_init, sizeof (picl_retinit_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * picld_fini is called when a picl_shutdown request is received
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_fini(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retfini_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = in->req_fini.cnum;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retfini_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_ping(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl picl_retping_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = in->req_ping.cnum;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retping_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * picld_wait is called when a picl_wait request is received
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_wait(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retwait_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = in->req_wait.cnum;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = xptree_refresh_notify(in->req_wait.secs);
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.retcode = err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retwait_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the handle of the root node of the PICL tree
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_getroot(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retroot_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = PICL_CNUM_GETROOT;
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_root(&ret.rnode);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy cvt_ptree2picl(&ret.rnode);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retroot_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the value of the PICL property
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_get_attrval(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retattrval_t *ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy size_t vbufsize;
c869993e79c1eafbec61a56bf6cea848fe754c71xy size_t len;
c869993e79c1eafbec61a56bf6cea848fe754c71xy door_cred_t cred;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_prophdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ptree_propinfo_t pinfo;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (door_cred(&cred) < 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, PICL_FAILURE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_attrval.attr, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_propinfo(ptreeh, &pinfo);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (!(pinfo.piclinfo.accessmode & PICL_READ))
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, PICL_NOTREADABLE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy vbufsize = pinfo.piclinfo.size;
c869993e79c1eafbec61a56bf6cea848fe754c71xy vbufsize = MIN((size_t)in->req_attrval.bufsize, vbufsize);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy len = sizeof (picl_retattrval_t) + vbufsize;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret = alloca(len);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (ret == NULL)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, PICL_FAILURE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret->cnum = PICL_CNUM_GETATTRVAL;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret->attr = in->req_attrval.attr;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret->nbytes = (uint32_t)vbufsize;
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = xptree_get_propval_with_cred(ptreeh, ret->ret_buf, vbufsize,
c869993e79c1eafbec61a56bf6cea848fe754c71xy cred);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * adjust returned bytes for charstrings
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (pinfo.piclinfo.type == PICL_PTYPE_CHARSTRING)
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret->nbytes = (uint32_t)strlen(ret->ret_buf) + 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * convert handle values to picl handles
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ((pinfo.piclinfo.type == PICL_PTYPE_TABLE) ||
c869993e79c1eafbec61a56bf6cea848fe754c71xy (pinfo.piclinfo.type == PICL_PTYPE_REFERENCE))
c869993e79c1eafbec61a56bf6cea848fe754c71xy cvt_ptree2picl(&ret->ret_nodeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)ret, sizeof (picl_retattrval_t) +
c869993e79c1eafbec61a56bf6cea848fe754c71xy (size_t)ret->nbytes, NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the value of the PICL property specified by
c869993e79c1eafbec61a56bf6cea848fe754c71xy * its name.
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_get_attrval_by_name(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retattrvalbyname_t *ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy size_t vbufsize;
c869993e79c1eafbec61a56bf6cea848fe754c71xy size_t len;
c869993e79c1eafbec61a56bf6cea848fe754c71xy door_cred_t cred;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_nodehdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ptree_propinfo_t pinfo;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl if (door_cred(&cred) < 0)
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl picld_return_error(in->in.cnum, PICL_FAILURE);
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl err = cvt_picl2ptree(in->req_attrvalbyname.nodeh, &ptreeh);
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl if (err != PICL_SUCCESS)
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl picld_return_error(in->in.cnum, err);
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl err = xptree_get_propinfo_by_name(ptreeh,
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl in->req_attrvalbyname.propname, &pinfo);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (!(pinfo.piclinfo.accessmode & PICL_READ))
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, PICL_NOTREADABLE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * allocate the minimum of piclinfo.size and input bufsize
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy vbufsize = pinfo.piclinfo.size;
c869993e79c1eafbec61a56bf6cea848fe754c71xy vbufsize = MIN((size_t)in->req_attrvalbyname.bufsize, vbufsize);
c869993e79c1eafbec61a56bf6cea848fe754c71xy len = sizeof (picl_retattrvalbyname_t) + vbufsize;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret = alloca(len);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (ret == NULL)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, PICL_FAILURE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret->cnum = PICL_CNUM_GETATTRVALBYNAME;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret->nodeh = in->req_attrvalbyname.nodeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) strcpy(ret->propname, in->req_attrvalbyname.propname);
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret->nbytes = (uint32_t)vbufsize;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = xptree_get_propval_by_name_with_cred(ptreeh,
c869993e79c1eafbec61a56bf6cea848fe754c71xy in->req_attrvalbyname.propname, ret->ret_buf, vbufsize,
c869993e79c1eafbec61a56bf6cea848fe754c71xy cred);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * adjust returned value size for charstrings
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (pinfo.piclinfo.type == PICL_PTYPE_CHARSTRING)
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret->nbytes = (uint32_t)strlen(ret->ret_buf) + 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ((pinfo.piclinfo.type == PICL_PTYPE_TABLE) ||
c869993e79c1eafbec61a56bf6cea848fe754c71xy (pinfo.piclinfo.type == PICL_PTYPE_REFERENCE))
c869993e79c1eafbec61a56bf6cea848fe754c71xy cvt_ptree2picl(&ret->ret_nodeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)ret, sizeof (picl_retattrvalbyname_t) +
c869993e79c1eafbec61a56bf6cea848fe754c71xy (size_t)ret->nbytes, NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function sets a property value
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_set_attrval(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retsetattrval_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy door_cred_t cred;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_prophdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ptree_propinfo_t pinfo;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (door_cred(&cred) < 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, PICL_FAILURE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_setattrval.attr, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_propinfo(ptreeh, &pinfo);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (!(pinfo.piclinfo.accessmode & PICL_WRITE))
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, PICL_NOTWRITABLE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * For non-volatile prop, only super user can set its value.
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (!(pinfo.piclinfo.accessmode & PICL_VOLATILE) &&
c869993e79c1eafbec61a56bf6cea848fe754c71xy (cred.dc_euid != SUPER_USER))
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl picld_return_error(in->in.cnum, PICL_PERMDENIED);
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl ret.cnum = PICL_CNUM_SETATTRVAL;
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl ret.attr = in->req_setattrval.attr;
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = xptree_update_propval_with_cred(ptreeh, in->req_setattrval.valbuf,
c869993e79c1eafbec61a56bf6cea848fe754c71xy (size_t)in->req_setattrval.bufsize, cred);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retsetattrval_t), NULL,
c869993e79c1eafbec61a56bf6cea848fe754c71xy 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function sets the value of a property specified by its name.
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_set_attrval_by_name(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retsetattrvalbyname_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy door_cred_t cred;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_prophdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ptree_propinfo_t pinfo;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (door_cred(&cred) < 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, PICL_FAILURE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_setattrvalbyname.nodeh, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = xptree_get_propinfo_by_name(ptreeh,
c869993e79c1eafbec61a56bf6cea848fe754c71xy in->req_setattrvalbyname.propname, &pinfo);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (!(pinfo.piclinfo.accessmode & PICL_WRITE))
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, PICL_NOTWRITABLE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * For non-volatile prop, only super user can set its value.
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (!(pinfo.piclinfo.accessmode & PICL_VOLATILE) &&
c869993e79c1eafbec61a56bf6cea848fe754c71xy (cred.dc_euid != SUPER_USER))
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, PICL_PERMDENIED);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = PICL_CNUM_SETATTRVALBYNAME;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.nodeh = in->req_setattrvalbyname.nodeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) strcpy(ret.propname, in->req_setattrvalbyname.propname);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = xptree_update_propval_by_name_with_cred(ptreeh,
c869993e79c1eafbec61a56bf6cea848fe754c71xy in->req_setattrvalbyname.propname,
c869993e79c1eafbec61a56bf6cea848fe754c71xy in->req_setattrvalbyname.valbuf,
c869993e79c1eafbec61a56bf6cea848fe754c71xy (size_t)in->req_setattrvalbyname.bufsize,
c869993e79c1eafbec61a56bf6cea848fe754c71xy cred);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retsetattrvalbyname_t),
c869993e79c1eafbec61a56bf6cea848fe754c71xy NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the property information
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_get_attrinfo(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retattrinfo_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ptree_propinfo_t pinfo;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_prophdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_attrinfo.attr, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = PICL_CNUM_GETATTRINFO;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.attr = in->req_attrinfo.attr;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_propinfo(ptreeh, &pinfo);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.type = pinfo.piclinfo.type;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.accessmode = pinfo.piclinfo.accessmode;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.size = (uint32_t)pinfo.piclinfo.size;
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) strcpy(ret.name, pinfo.piclinfo.name);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retattrinfo_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the node's first property handle
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_get_first_attr(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retfirstattr_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_prophdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_firstattr.nodeh, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = PICL_CNUM_GETFIRSTATTR;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.nodeh = in->req_firstattr.nodeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_first_prop(ptreeh, &ret.attr);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy cvt_ptree2picl(&ret.attr);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retfirstattr_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the next property handle in list
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_get_next_attr(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retnextattr_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_prophdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_nextattr.attr, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = PICL_CNUM_GETNEXTATTR;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.attr = in->req_nextattr.attr;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_next_prop(ptreeh, &ret.nextattr);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy cvt_ptree2picl(&ret.nextattr);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retnextattr_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the handle of a property specified by its name
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_get_attr_by_name(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retattrbyname_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_prophdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_attrbyname.nodeh, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = PICL_CNUM_GETATTRBYNAME;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.nodeh = in->req_attrbyname.nodeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) strcpy(ret.propname, in->req_attrbyname.propname);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_prop_by_name(ptreeh, ret.propname, &ret.attr);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy cvt_ptree2picl(&ret.attr);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retattrbyname_t), NULL,
c869993e79c1eafbec61a56bf6cea848fe754c71xy 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function gets the next property on the same row in the table
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_get_attr_by_row(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retattrbyrow_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_prophdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_attrbyrow.attr, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = PICL_CNUM_GETATTRBYROW;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.attr = in->req_attrbyrow.attr;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_next_by_row(ptreeh, &ret.rowattr);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy cvt_ptree2picl(&ret.rowattr);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retattrbyrow_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the handle of the next property in the same column
c869993e79c1eafbec61a56bf6cea848fe754c71xy * of the table.
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_get_attr_by_col(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retattrbycol_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_prophdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_attrbycol.attr, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = PICL_CNUM_GETATTRBYCOL;
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.attr = in->req_attrbycol.attr;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_next_by_col(ptreeh, &ret.colattr);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl cvt_ptree2picl(&ret.colattr);
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retattrbycol_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function finds the node in the PICLTREE that matches the given
c869993e79c1eafbec61a56bf6cea848fe754c71xy * criteria and returns its handle.
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_find_node(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retfindnode_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_nodehdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_findnode.nodeh, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = PICL_CNUM_FINDNODE;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_find_node(ptreeh, in->req_findnode.propname,
c869993e79c1eafbec61a56bf6cea848fe754c71xy in->req_findnode.ptype, in->req_findnode.valbuf,
c869993e79c1eafbec61a56bf6cea848fe754c71xy in->req_findnode.valsize, &ret.rnodeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy cvt_ptree2picl(&ret.rnodeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (ret), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl/*
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl * This function finds the property/node that corresponds to the given path
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl * and returns its handle
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl */
8bb4b220fdb894543e41a5f9037898cf3c3f312bglstatic void
8bb4b220fdb894543e41a5f9037898cf3c3f312bglpicld_get_node_by_path(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retnodebypath_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = PICL_CNUM_NODEBYPATH;
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_node_by_path(in->req_nodebypath.pathbuf, &ret.nodeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy cvt_ptree2picl(&ret.nodeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (ret), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns finds the frutree parent node for a given node
c869993e79c1eafbec61a56bf6cea848fe754c71xy * and returns its handle
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_get_frutree_parent(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retfruparent_t ret;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int err;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_nodehdl_t ptreeh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_fruparent.devh, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret.cnum = PICL_CNUM_FRUTREEPARENT;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_frutree_parent(ptreeh, &ret.fruh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (err != PICL_SUCCESS)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, err);
c869993e79c1eafbec61a56bf6cea848fe754c71xy cvt_ptree2picl(&ret.fruh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
d62bc4badc1c1f1549c961cfb8b420e650e1272byz (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (ret), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function is called when an unknown client request is received.
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_unknown_service(picl_service_t *in)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(in->in.cnum, PICL_UNKNOWNSERVICE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xycheck_denial_of_service(int cnum)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy hrtime_t window;
c869993e79c1eafbec61a56bf6cea848fe754c71xy hrtime_t current;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int dos_flag;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy current = gethrtime();
c869993e79c1eafbec61a56bf6cea848fe754c71xy dos_flag = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (pthread_mutex_lock(&dos_mutex) != 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(cnum, PICL_FAILURE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy ++service_requests;
c869993e79c1eafbec61a56bf6cea848fe754c71xy window = current - orig_time;
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (window > MILLI_TO_NANO(sliding_interval_ms)) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy orig_time = current;
c869993e79c1eafbec61a56bf6cea848fe754c71xy service_requests = 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (service_requests > dos_req_limit)
c869993e79c1eafbec61a56bf6cea848fe754c71xy dos_flag = 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (pthread_mutex_unlock(&dos_mutex) != 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(cnum, PICL_FAILURE);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (dos_flag)
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) poll(NULL, 0, dos_ms);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/* ARGSUSED */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_door_handler(void *cookie, char *argp, size_t asize,
c869993e79c1eafbec61a56bf6cea848fe754c71xy door_desc_t *dp, uint_t n_desc)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_service_t *req;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy req = (picl_service_t *)argp;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (req == NULL)
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)req, 0, NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy check_denial_of_service(req->in.cnum);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_rdlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy switch (req->in.cnum) { /* client call number */
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_INIT:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_init((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_FINI:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_fini((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_GETROOT:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_getroot((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_GETATTRVAL:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_get_attrval((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_GETATTRVALBYNAME:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_get_attrval_by_name((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_GETATTRINFO:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_get_attrinfo((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_GETFIRSTATTR:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_get_first_attr((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_GETNEXTATTR:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_get_next_attr((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_GETATTRBYNAME:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_get_attr_by_name((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_GETATTRBYROW:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_get_attr_by_row((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_GETATTRBYCOL:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_get_attr_by_col((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_SETATTRVAL:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_set_attrval((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_SETATTRVALBYNAME:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_set_attrval_by_name((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_PING:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_ping((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_WAIT:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_wait((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_FINDNODE:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_find_node((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_NODEBYPATH:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_get_node_by_path((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case PICL_CNUM_FRUTREEPARENT:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_get_frutree_parent((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy default:
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_unknown_service((picl_service_t *)argp);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy };
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*NOTREACHED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/* ARGSUSED */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xyhup_handler(int sig, siginfo_t *siginfo, void *sigctx)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy doreinit = 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * "ping" to see if a daemon is already running
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic int
c869993e79c1eafbec61a56bf6cea848fe754c71xydaemon_exists(void)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy door_arg_t darg;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_reqping_t req_ping;
c869993e79c1eafbec61a56bf6cea848fe754c71xy picl_retping_t ret_ping;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int doorh;
c869993e79c1eafbec61a56bf6cea848fe754c71xy door_info_t dinfo;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy doorh = open(PICLD_DOOR, O_RDONLY);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (doorh < 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (door_info(doorh, &dinfo) < 0) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) close(doorh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ((dinfo.di_attributes & DOOR_REVOKED) ||
c869993e79c1eafbec61a56bf6cea848fe754c71xy (dinfo.di_data != (door_ptr_t)PICLD_DOOR_COOKIE)) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) close(doorh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (dinfo.di_target != getpid()) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) close(doorh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy req_ping.cnum = PICL_CNUM_PING;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy darg.data_ptr = (char *)&req_ping;
c869993e79c1eafbec61a56bf6cea848fe754c71xy darg.data_size = sizeof (picl_reqping_t);
c869993e79c1eafbec61a56bf6cea848fe754c71xy darg.desc_ptr = NULL;
c869993e79c1eafbec61a56bf6cea848fe754c71xy darg.desc_num = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy darg.rbuf = (char *)&ret_ping;
c869993e79c1eafbec61a56bf6cea848fe754c71xy darg.rsize = sizeof (picl_retping_t);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (door_call(doorh, &darg) < 0) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) close(doorh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) close(doorh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Create the picld door
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic int
c869993e79c1eafbec61a56bf6cea848fe754c71xysetup_door(void)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy struct stat stbuf;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Create the door
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy door_id = door_create(picld_door_handler, PICLD_DOOR_COOKIE,
c869993e79c1eafbec61a56bf6cea848fe754c71xy DOOR_UNREF | DOOR_REFUSE_DESC | DOOR_NO_CANCEL);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (door_id < 0) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (-1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (stat(PICLD_DOOR, &stbuf) < 0) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy int newfd;
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ((newfd = creat(PICLD_DOOR, 0444)) < 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (-1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) close(newfd);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (fattach(door_id, PICLD_DOOR) < 0) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ((errno != EBUSY) ||
c869993e79c1eafbec61a56bf6cea848fe754c71xy (fdetach(PICLD_DOOR) < 0) ||
c869993e79c1eafbec61a56bf6cea848fe754c71xy (fattach(door_id, PICLD_DOOR) < 0))
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (-1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Main function of picl daemon
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xyint
c869993e79c1eafbec61a56bf6cea848fe754c71xymain(int argc, char **argv)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy struct sigaction act;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int c;
c869993e79c1eafbec61a56bf6cea848fe754c71xy sigset_t ublk;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) setlocale(LC_ALL, "");
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) textdomain(TEXT_DOMAIN);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (getuid() != 0) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy syslog(LOG_CRIT, MUST_BE_ROOT);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rwlock_init(&init_lk, USYNC_THREAD, NULL);
c869993e79c1eafbec61a56bf6cea848fe754c71xy doreinit = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy logflag = 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy dos_req_limit = DOS_PICL_REQUESTS_LIMIT;
c869993e79c1eafbec61a56bf6cea848fe754c71xy sliding_interval_ms = SLIDING_INTERVAL_MILLISECONDS;
c869993e79c1eafbec61a56bf6cea848fe754c71xy dos_ms = DOS_SLEEPTIME_MS;
c869993e79c1eafbec61a56bf6cea848fe754c71xy verbose_level = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * parse arguments
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy while ((c = getopt(argc, argv, "is:t:l:r:v:d:")) != EOF) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy switch (c) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy case 'd':
c869993e79c1eafbec61a56bf6cea848fe754c71xy dos_ms = strtol(optarg, (char **)NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case 'i':
c869993e79c1eafbec61a56bf6cea848fe754c71xy logflag = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case 's':
c869993e79c1eafbec61a56bf6cea848fe754c71xy sliding_interval_ms = strtoll(optarg, (char **)NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case 't':
c869993e79c1eafbec61a56bf6cea848fe754c71xy dos_req_limit = strtol(optarg, (char **)NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy case 'v':
c869993e79c1eafbec61a56bf6cea848fe754c71xy verbose_level = strtol(optarg, (char **)NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy logflag = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy default:
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy orig_time = gethrtime();
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * is there a daemon already running?
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (daemon_exists()) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy syslog(LOG_CRIT, DAEMON_RUNNING);
c869993e79c1eafbec61a56bf6cea848fe754c71xy exit(1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Mask off/block SIGALRM signal so that the environmental plug-in
c869993e79c1eafbec61a56bf6cea848fe754c71xy * (piclenvd) can use it to simulate sleep() without being affected
c869993e79c1eafbec61a56bf6cea848fe754c71xy * by time being set back. No other PICL plug-in should use SIGALRM
c869993e79c1eafbec61a56bf6cea848fe754c71xy * or alarm() for now.
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) sigemptyset(&ublk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) sigaddset(&ublk, SIGALRM);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) sigprocmask(SIG_BLOCK, &ublk, NULL);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Ignore SIGHUP until all the initialization is done.
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy act.sa_handler = SIG_IGN;
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) sigemptyset(&act.sa_mask);
c869993e79c1eafbec61a56bf6cea848fe754c71xy act.sa_flags = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (sigaction(SIGHUP, &act, NULL) == -1)
c869993e79c1eafbec61a56bf6cea848fe754c71xy syslog(LOG_ERR, SIGACT_FAILED, strsignal(SIGHUP),
c869993e79c1eafbec61a56bf6cea848fe754c71xy strerror(errno));
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl if (logflag != 0) { /* daemonize */
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl pid_t pid;
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
c869993e79c1eafbec61a56bf6cea848fe754c71xy pid = fork();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (pid < 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy exit(1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (pid > 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy /* parent */
c869993e79c1eafbec61a56bf6cea848fe754c71xy exit(0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /* child */
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (chdir("/") == -1) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy syslog(LOG_CRIT, CD_ROOT_FAILED);
c869993e79c1eafbec61a56bf6cea848fe754c71xy exit(1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) setsid();
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl (void) close(STDIN_FILENO);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) close(STDOUT_FILENO);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) close(STDERR_FILENO);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) open("/dev/null", O_RDWR, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) dup2(STDIN_FILENO, STDOUT_FILENO);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) dup2(STDIN_FILENO, STDERR_FILENO);
c869993e79c1eafbec61a56bf6cea848fe754c71xy openlog(PICLD, LOG_PID, LOG_DAEMON);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Initialize the PICL Tree
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (xptree_initialize(NULL) != PICL_SUCCESS) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy syslog(LOG_CRIT, INIT_FAILED);
c869993e79c1eafbec61a56bf6cea848fe754c71xy exit(1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (setup_door()) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy syslog(LOG_CRIT, DOOR_FAILED);
c869993e79c1eafbec61a56bf6cea848fe754c71xy exit(1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * setup signal handlers for post-init
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy act.sa_sigaction = hup_handler;
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) sigemptyset(&act.sa_mask);
c869993e79c1eafbec61a56bf6cea848fe754c71xy act.sa_flags = SA_SIGINFO;
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (sigaction(SIGHUP, &act, NULL) == -1)
c869993e79c1eafbec61a56bf6cea848fe754c71xy syslog(LOG_ERR, SIGACT_FAILED, strsignal(SIGHUP),
c869993e79c1eafbec61a56bf6cea848fe754c71xy strerror(errno));
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * wait for requests
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy for (;;) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) pause();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (doreinit) {
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl /*
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl * Block SIGHUP during reinitialization.
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl * Also mask off/block SIGALRM signal so that the
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl * environmental plug-in (piclenvd) can use it to
c869993e79c1eafbec61a56bf6cea848fe754c71xy * simulate sleep() without being affected by time
c869993e79c1eafbec61a56bf6cea848fe754c71xy * being set back. No ohter PICL plug-in should use
c869993e79c1eafbec61a56bf6cea848fe754c71xy * SIGALRM or alarm() for now.
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) sigemptyset(&ublk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) sigaddset(&ublk, SIGHUP);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) sigaddset(&ublk, SIGALRM);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) sigprocmask(SIG_BLOCK, &ublk, NULL);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) sigdelset(&ublk, SIGALRM);
c869993e79c1eafbec61a56bf6cea848fe754c71xy doreinit = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_wrlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy xptree_destroy();
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) xptree_reinitialize();
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) rw_unlock(&init_lk);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) sigprocmask(SIG_UNBLOCK, &ublk, NULL);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy