libevchannel.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <door.h>
#include <unistd.h>
#include <stddef.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/sysevent.h>
#include <sys/sysevent_impl.h>
#include "libsysevent.h"
#include "libsysevent_impl.h"
/*
* The functions below deal with the General Purpose Event Handling framework
*
* sysevent_evc_subscribe - subscribe to existing event channel
* sysevent_evc_unsubscribe - unsubscribe from existing event channel
* sysevent_evc_publish - generate a system event via an event channel
* sysevent_evc_control - various channel based control operation
*/
/*
* Check syntax of a channel name
*/
static int
sysevent_is_chan_name(const char *str)
{
if (!EVCH_ISCHANCHAR(*str))
return (0);
}
return (1);
}
/*
* Check for printable characters
*/
static int
strisprint(const char *s)
{
for (; *s != '\0'; s++) {
if (*s < ' ' || *s > '~')
return (0);
}
return (1);
}
/*
*/
int
{
int chanlen;
int ec;
}
/* Provide useful value in error case */
}
/* Check channel syntax */
if (!sysevent_is_chan_name(channel)) {
}
if (flags & ~EVCH_B_FLAGS) {
}
}
/*
* Enable sysevent driver. Fallback if the device link doesn't exist;
* this situation can arise if a channel is bound early in system
* startup, prior to devfsadm(1M) being invoked.
*/
}
}
}
/*
* Force to close the fd's when process is doing exec.
* The driver will then release stale binding handles.
* The driver will release also the associated subscriptions
* if EVCH_SUB_KEEP flag was not set.
*/
}
/* Needed to detect a fork() */
return (0);
}
/*
*/
void
{
return;
/*
* Unsubscribe, if we are in the process which did the bind.
*/
/*
* The unsubscribe ioctl will block until all door upcalls have
* drained.
*/
return;
}
}
}
/*
* The close of the driver will do the unsubscribe if a) it is the last
* close and b) we are in a child which inherited subscriptions.
*/
}
/*
* sysevent_evc_publish - Generate a system event via an event channel
*/
int
{
sysevent_t *ev;
int rc;
int ec;
}
/* No inheritance of binding handles via fork() */
}
return (errno);
}
if (rc != 0) {
return (ec);
}
return (0);
}
/*
* Generic callback which catches events from the kernel and calls
* subscribers call back routine.
*
* Kernel guarantees that door_upcalls are disabled when unsubscription
* was issued that's why cookie points always to a valid evchan_subscr_t *.
*
* Furthermore it's not necessary to lock subp because the sysevent
* framework guarantees no unsubscription until door_return.
*/
/*ARGSUSED3*/
static void
{
int rval = 0;
/* Skip callback execution */
} else {
subp->evsub_cookie);
}
/*
* Fill in return values for door_return
*/
}
/*
* sysevent_evc_subscribe - Subscribe to an existing event channel
*/
int
{
int upcall_door;
int ec;
}
/* No inheritance of binding handles via fork() */
}
}
/* Check for printable characters */
if (!strisprint(sid)) {
}
if (event_handler == NULL) {
}
/* Create subscriber data */
return (errno);
}
return (ec);
}
/*
* EC_ALL string will not be copied to kernel - NULL is assumed
*/
class_len = 0;
}
if (upcall_door == -1) {
return (ec);
}
/* Complete subscriber information */
(void) door_revoke(upcall_door);
return (ec);
}
/* Attach to subscriber list */
return (0);
}
/*
* sysevent_evc_unsubscribe - Unsubscribe from an existing event channel
*/
void
{
int all_subscribers = 0;
int rc;
return;
return;
/* No inheritance of binding handles via fork() */
return;
}
/* Indicates all subscriber id's for this channel */
} else {
}
/*
* The unsubscribe ioctl will block until all door upcalls have drained.
*/
if (rc != 0) {
return;
}
/* Search for the matching subscriber */
if (all_subscribers ||
/* Freed single subscriber already */
if (all_subscribers == 0) {
break;
}
} else
}
}
/*
* sysevent_evc_control - Various channel based control operation
*/
int
{
int rc = 0;
}
/* No inheritance of binding handles via fork() */
}
switch (cmd) {
case EVCH_GET_CHAN_LEN:
case EVCH_GET_CHAN_LEN_MAX:
break;
}
break;
case EVCH_SET_CHAN_LEN:
/* Range change will be handled in framework */
break;
default:
}
if (rc == -1) {
}
}