libevchannel.c revision f6e214c7418f43af38bd8c3a557e3d0a1d311cfa
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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
*/
/*
*/
#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 <pthread.h>
#include <atomic.h>
#include <signal.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
*/
static void kill_door_servers(evchan_subscr_t *);
/*
* If the current thread is a door server thread servicing a door created
* for us in sysevent_evc_xsubscribe, then an attempt to unsubscribe from
* within door invocation context on the same channel will deadlock in the
* kernel waiting for our own invocation to complete. Such calls are
* forbidden, and we abort if they are encountered (better than hanging
* unkillably).
*
* We'd like to offer this detection to subscriptions established with
* sysevent_evc_subscribe, but we don't have control over the door service
* threads in that case. Perhaps the fix is to always use door_xcreate
* even for sysevent_evc_subscribe?
*/
static boolean_t
{
}
/*
* 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);
}
/*
*/
int
{
int errcp;
if (will_deadlock(scp))
/*
* Unsubscribe, if we are in the process which did the bind.
*/
/*
* The unsubscribe ioctl will block until all door upcalls have
* drained.
*/
}
}
/* If door_xcreate was applied we can clean up */
if (subp->evsub_attr)
}
/*
* 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.
*/
return (0);
}
/*
* 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;
/*
* If we've been invoked simply to kill the thread then
* exit now.
*/
/* Skip callback execution */
} else {
subp->evsub_cookie);
}
/*
* Fill in return values for door_return
*/
}
static pthread_attr_t xsub_thrattr;
static void
xsub_thrattr_init(void)
{
(void) pthread_attr_init(&xsub_thrattr);
(void) pthread_attr_setdetachstate(&xsub_thrattr,
}
/*
* Our door server create function is only called during initial
* door_xcreate since we specify DOOR_NO_DEPLETION_CB.
*/
int
{
int err;
return (0); /* shouldn't happen, but just in case */
/*
* If sysevent_evc_xsubscribe was called electing to use a
* different door server create function then let it take it
* from here.
*/
if (xsa->xs_thrcreate) {
}
thrattr = &xsub_thrattr;
} else {
}
}
void
xsub_door_server_setup(void *cookie)
{
}
if (xsa->xs_thrsetup)
}
/*
* Cause private door server threads to exit. We have already performed the
* unsubscribe ioctl which stops new invocations and waits until all
* existing invocations are complete. So all server threads should be
* blocked in door_return. The door has not yet been revoked. We will
* invoke repeatedly after setting the evsub_state to be noticed on
* wakeup; each invocation will result in the death of one server thread.
*
* You'd think it would be easier to kill these threads, such as through
* pthread_cancel. Unfortunately door_return is not a cancellation point,
* and if you do cancel a thread blocked in door_return the EINTR check in
* the door_return assembly logic causes us to loop with EINTR forever!
*/
static void
{
}
static int
{
int upcall_door;
int ec;
}
/* No inheritance of binding handles via fork() */
}
}
/* Check for printable characters */
if (!strisprint(sid)) {
}
if (event_handler == NULL) {
}
return (errno); /* ENOMEM or EAGAIN */
/* Create subscriber data */
return (errno);
}
return (ec);
}
/*
* EC_ALL string will not be copied to kernel - NULL is assumed
*/
class_len = 0;
}
/*
* Fill this in now for the xsub_door_server_setup dance
*/
} else {
/*
* Create a private door with exactly one thread to
* service the callbacks (the GPEC kernel implementation
* serializes deliveries for each subscriber id).
*/
(void *)subp, 1);
}
if (upcall_door == -1) {
return (ec);
}
/* Complete subscriber information */
if (xsa)
(void) door_revoke(upcall_door);
return (ec);
}
/* Attach to subscriber list */
return (0);
}
/*
* sysevent_evc_subscribe - subscribe to an existing event channel
* using a non-private door (which will create as many server threads
* as the apparent maximum concurrency requirements suggest).
*/
int
{
}
static void
{
}
static struct sysevent_subattr_impl dfltsa;
static void
init_dfltsa(void)
{
}
/*
* sysevent_evc_subscribe - subscribe to an existing event channel
* using a private door with control over thread creation.
*/
int
{
struct sysevent_subattr_impl *xsa;
} else {
}
}
sysevent_subattr_alloc(void)
{
}
void
{
struct sysevent_subattr_impl *xsa =
(struct sysevent_subattr_impl *)attr;
}
void
{
struct sysevent_subattr_impl *xsa =
(struct sysevent_subattr_impl *)attr;
}
void
{
struct sysevent_subattr_impl *xsa =
(struct sysevent_subattr_impl *)attr;
}
void
{
struct sysevent_subattr_impl *xsa =
(struct sysevent_subattr_impl *)attr;
if (set) {
} else {
}
}
void
{
struct sysevent_subattr_impl *xsa =
(struct sysevent_subattr_impl *)attr;
}
/*
* sysevent_evc_unsubscribe - Unsubscribe from an existing event channel
*/
int
{
int all_subscribers = 0;
int errcp;
int rc;
/* No inheritance of binding handles via fork() */
/* Indicates all subscriber id's for this channel */
} else {
}
if (will_deadlock(scp))
/*
* The unsubscribe ioctl will block until all door upcalls have drained.
*/
if (rc != 0) {
}
/*
* Search for the matching subscriber. If EVCH_ALLSUB was specified
* then the ioctl above will have returned 0 even if there are
* no subscriptions, so the initial EV_SUB_NEXT can be NULL.
*/
} else {
}
/* If door_xcreate was applied we can clean up */
if (tofree->evsub_attr)
/* Freed single subscriber already? */
if (all_subscribers == 0)
break;
} else {
}
}
return (0);
}
/*
* 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) {
}
}
int
{
int rc;
return (errno);
if (buf)
return (rc);
}
int
{
int rc;
/*
* If the packed nvlist is too big for the buffer size we offered
* then the ioctl returns EOVERFLOW and indicates in the 'len'
* the size required for the current property nvlist generation
* (itself returned in the generation member).
*/
return (E2BIG);
goto again;
}
/*
* The chan prop nvlist can be absent, in which case the ioctl
* returns success and uargs.packednvl.len of 0; we have already
* set *nvlp to NULL. Otherwise we must unpack the nvl.
*/
}