picld.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
c869993e79c1eafbec61a56bf6cea848fe754c71xy * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c869993e79c1eafbec61a56bf6cea848fe754c71xy * See the License for the specific language governing permissions
c869993e79c1eafbec61a56bf6cea848fe754c71xy * and limitations under the License.
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 * CDDL HEADER END
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Use is subject to license terms.
c869993e79c1eafbec61a56bf6cea848fe754c71xy#pragma ident "%Z%%M% %I% %E% SMI"
c869993e79c1eafbec61a56bf6cea848fe754c71xy * PICL daemon
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Log text messages
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define MUST_BE_ROOT gettext("this program must be run as root\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 * Constants
c869993e79c1eafbec61a56bf6cea848fe754c71xyextern char **environ;
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Module Variables
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic int doreinit = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic int service_requests = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic pthread_mutex_t dos_mutex = PTHREAD_MUTEX_INITIALIZER;
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl * This returns an error message to libpicl
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_return_error(picl_callnumber_t cnum, picl_errno_t err)
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret_error, sizeof (picl_reterror_t), NULL,
c869993e79c1eafbec61a56bf6cea848fe754c71xy * picld_init is called when a picl_initialize request is received
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy picld_return_error(req->req_init.cnum, PICL_NOTSUPPORTED);
c869993e79c1eafbec61a56bf6cea848fe754c71xy ret_init.rev = PICLD_VERSION(PICLD_MAJOR_REV, PICLD_MINOR_REV);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret_init, sizeof (picl_retinit_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * picld_fini is called when a picl_shutdown request is received
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retfini_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retping_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * picld_wait is called when a picl_wait request is received
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retwait_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the handle of the root node of the PICL tree
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retroot_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the value of the PICL property
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy vbufsize = MIN((size_t)in->req_attrval.bufsize, vbufsize);
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = xptree_get_propval_with_cred(ptreeh, ret->ret_buf, vbufsize,
c869993e79c1eafbec61a56bf6cea848fe754c71xy * adjust returned bytes for charstrings
c869993e79c1eafbec61a56bf6cea848fe754c71xy * convert handle values to picl handles
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)ret, sizeof (picl_retattrval_t) +
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the value of the PICL property specified by
c869993e79c1eafbec61a56bf6cea848fe754c71xy * its name.
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl err = cvt_picl2ptree(in->req_attrvalbyname.nodeh, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * allocate the minimum of piclinfo.size and input bufsize
c869993e79c1eafbec61a56bf6cea848fe754c71xy vbufsize = MIN((size_t)in->req_attrvalbyname.bufsize, vbufsize);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) strcpy(ret->propname, in->req_attrvalbyname.propname);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * adjust returned value size for charstrings
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)ret, sizeof (picl_retattrvalbyname_t) +
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function sets a property value
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy * For non-volatile prop, only super user can set its value.
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = xptree_update_propval_with_cred(ptreeh, in->req_setattrval.valbuf,
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retsetattrval_t), NULL,
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function sets the value of a property specified by its name.
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = cvt_picl2ptree(in->req_setattrvalbyname.nodeh, &ptreeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * For non-volatile prop, only super user can set its value.
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) strcpy(ret.propname, in->req_setattrvalbyname.propname);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retsetattrvalbyname_t),
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the property information
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retattrinfo_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the node's first property handle
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retfirstattr_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the next property handle in list
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retnextattr_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the handle of a property specified by its name
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) strcpy(ret.propname, in->req_attrbyname.propname);
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_prop_by_name(ptreeh, ret.propname, &ret.attr);
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retattrbyname_t), NULL,
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function gets the next property on the same row in the table
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retattrbyrow_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns the handle of the next property in the same column
c869993e79c1eafbec61a56bf6cea848fe754c71xy * of the table.
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void) door_return((char *)&ret, sizeof (picl_retattrbycol_t), NULL, 0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function finds the node in the PICLTREE that matches the given
c869993e79c1eafbec61a56bf6cea848fe754c71xy * criteria and returns its handle.
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl * This function finds the property/node that corresponds to the given path
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl * and returns its handle
8bb4b220fdb894543e41a5f9037898cf3c3f312bglstatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy err = ptree_get_node_by_path(in->req_nodebypath.pathbuf, &ret.nodeh);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function returns finds the frutree parent node for a given node
c869993e79c1eafbec61a56bf6cea848fe754c71xy * and returns its handle
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This function is called when an unknown client request is received.
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy/* ARGSUSED */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xypicld_door_handler(void *cookie, char *argp, size_t asize,
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*LINTED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy /*NOTREACHED*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy/* ARGSUSED */
c869993e79c1eafbec61a56bf6cea848fe754c71xystatic void
c869993e79c1eafbec61a56bf6cea848fe754c71xy * "ping" to see if a daemon is already running
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Create the picld door
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Create the door
c869993e79c1eafbec61a56bf6cea848fe754c71xy door_id = door_create(picld_door_handler, PICLD_DOOR_COOKIE,
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (-1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (-1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (-1);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Main function of picl daemon
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (getuid() != 0) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy return (0);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * parse arguments
c869993e79c1eafbec61a56bf6cea848fe754c71xy while ((c = getopt(argc, argv, "is:t:l:r:v:d:")) != EOF) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy switch (c) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy * is there a daemon already running?
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 * Ignore SIGHUP until all the initialization is done.
c869993e79c1eafbec61a56bf6cea848fe754c71xy /* parent */
c869993e79c1eafbec61a56bf6cea848fe754c71xy /* child */
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Initialize the PICL Tree
c869993e79c1eafbec61a56bf6cea848fe754c71xy * setup signal handlers for post-init
c869993e79c1eafbec61a56bf6cea848fe754c71xy * wait for requests
c869993e79c1eafbec61a56bf6cea848fe754c71xy for (;;) {
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.