sysevent_reg_mod.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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <limits.h>
#include <thread.h>
#include <wait.h>
#include <synch.h>
#include <errno.h>
#include <locale.h>
#include <sys/sysevent.h>
#include <sys/sysevent_impl.h>
#include <libsysevent.h>
#include "message_reg_mod.h"
/*
* SLM for sysevent event subscribers
*/
extern char *root_dir;
extern void syseventd_err_print(char *format, ...);
typedef struct ev_queue {
} ev_queue_t;
static int cleanup;
static thread_t deliver_thr_id;
static int
{
/*
* This functionality is not supported in the mini-root
* environment, ie install. If root_dir is set, implying
* install, we quietly fail.
*/
return (EACCES);
}
/*
* Initialize the private sysevent handle
*/
if (sysevent_hp == NULL) {
"sysevent_open_channel failed with %s init "
return (errno);
} else {
return (errno);
}
}
if (sysevent_bind_publisher(sysevent_hp) != 0) {
/*
* Only one publisher allowed on the syseventd channel,
* cleanup previously allocated syseventd channel publishers
*/
if (sysevent_bind_publisher(sysevent_hp) == 0)
return (0);
}
sysevent_hp = NULL;
return (errno);
}
return (0);
}
static int
{
/* Not initialized */
if (sysevent_hp == NULL) {
ret = init_channel();
if (ret != 0) {
return (EAGAIN);
return (0);
} else {
return (0);
}
}
/* Check for stale syseventd subscribers */
}
/* Queue event for delivery to all subscribers */
return (EAGAIN);
}
return (EAGAIN);
}
(void) mutex_lock(&evq_lock);
} else {
}
(void) cond_signal(&evq_cv);
(void) mutex_unlock(&evq_lock);
return (0);
}
void
{
(void) mutex_lock(&evq_lock);
for (;;) {
}
/* Send events on to all current subscribers */
while (evqp) {
(void) mutex_unlock(&evq_lock);
"failed to send event\n");
}
(void) mutex_lock(&evq_lock);
}
if (cleanup) {
"thread exiting\n");
(void) mutex_unlock(&evq_lock);
/* NOTREACHED */
}
}
/* NOTREACHED */
}
static struct slm_mod_ops sysevent_reg_mod_ops = {
struct slm_mod_ops *
slm_init()
{
cleanup = 0;
sysevent_hp = NULL;
(void) init_channel();
NULL, 0, &deliver_thr_id) != 0) {
return (NULL);
}
return (&sysevent_reg_mod_ops);
}
void
slm_fini()
{
(void) mutex_lock(&evq_lock);
cleanup = 1;
(void) cond_signal(&evq_cv);
(void) mutex_unlock(&evq_lock);
/* Wait for delivery threads to exit */
(void) mutex_destroy(&evq_lock);
(void) cond_destroy(&evq_cv);
sysevent_hp = NULL;
}