/*
* 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 <assert.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include "libnwam_impl.h"
#include <libnwam_priv.h>
#include <libnwam.h>
/*
* Implementation of event notification mechanism used by the GUI and
* netadm. Clients register for events via nwam_events_init() and
* unregister via nwam_events_fini(). nwamd sends events via nwam_event_send()
* and applications block waiting for a new event to be delivered in
* nwam_event_wait(). Events are implemented as System V message queues,
* one per event client. The event mechanism has to be resilient to
* nwamd restarts so that clients do not lose the event connection.
*/
(NWAMD_MAX_NUM_WLANS * sizeof (nwam_wlan_t)))
/*
* This is protecting simultaneous access to the msqid and its configuration.
*/
static nwam_error_t
{
return (NWAM_NO_MEMORY);
return (NWAM_SUCCESS);
}
void
{
}
/*
* Get next event in queue.
*/
{
return (err);
0, 0) == -1) {
switch (errno) {
case EAGAIN:
case EBUSY:
/*
* We see this errno eventhough it isn't
* documented. Try again. If this causes
* a busy loop then grab a trace otherwise
* it's a brace 'til we can figure out why it
* happens.
*/
continue;
default:
return (nwam_errno_to_nwam_error(errno));
}
}
/* Resize event down from maximum size */
return (NWAM_NO_MEMORY);
return (NWAM_SUCCESS);
}
/*
* Register for receipt of events from nwamd. Event delivery is
* done via a System V message queue.
*/
nwam_events_init(void)
{
(void) pthread_mutex_lock(&event_mutex);
if (event_msqid != -1) {
goto exit;
}
goto exit;
}
goto exit;
}
/* Get system-wide message queue ID */
goto exit;
}
exit:
(void) pthread_mutex_unlock(&event_mutex);
return (rc);
}
/*
* Un-register for receipt of events from nwamd. Make a request to nwamd
* to destroy the message queue.
*/
void
nwam_events_fini(void)
{
(void) pthread_mutex_lock(&event_mutex);
event_msqid = -1;
(void) pthread_mutex_unlock(&event_mutex);
}
/*
* Create an event queue. Called by nwamd to create System V message queues
* for clients to listen for events.
*/
{
int fd;
return (nwam_errno_to_nwam_error(errno));
return (nwam_errno_to_nwam_error(errno));
return (nwam_errno_to_nwam_error(errno));
return (NWAM_SUCCESS);
}
/*
* Send event to registered listeners via the set of registered System V
* message queues.
*/
{
int msqid;
return (nwam_errno_to_nwam_error(errno));
}
/*
* For each file matching our event message queue file prefix,
* check the queue is still being read, and if so send the message.
*/
strlen(NWAM_EVENT_MSG_FILE)) != 0)
continue;
continue;
}
continue;
}
/* Retrieve stats to analyse queue activity */
continue;
}
/*
* If buf.msg_qnum > NWAM_EVENT_MAX_NUM_PENDING
* _and_ msg_stime is more than 10s after msg_rtime -
* indicating message(s) have been hanging around unclaimed -
* we destroy the queue as the client has most likely gone
* away. This can happen if a registered client hits Ctrl^C.
*/
continue;
}
/*
* This shouldn't ever block. If it does then log an error and
* clean up the queue.
*/
IPC_NOWAIT) == -1) {
continue;
}
}
return (err);
}
/*
* Destroy an event queue. Called by nwamd to destroy the associated message
* queue.
*/
void
{
int msqid;
(void) unlink(eventmsgfile);
}
/*
* Stop sending events. Called by nwamd to destroy each System V message queue
* registered.
*/
void
nwam_event_send_fini(void)
{
(void) pthread_mutex_lock(&event_mutex);
(void) pthread_mutex_unlock(&event_mutex);
return;
}
/*
* For each file matching our event message queue file prefix,
* destroy the queue and message file.
*/
strlen(NWAM_EVENT_MSG_FILE)) != 0)
continue;
}
(void) pthread_mutex_unlock(&event_mutex);
}