msgs.c revision 0a44ef6d9afbfe052a7e975f55ea0d2954b62a82
/*
* 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
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
# include <stdarg.h>
# include <limits.h>
# include <poll.h>
# include <stropts.h>
# include <unistd.h>
#include <syslog.h>
# include "lpsched.h"
static void conn_shutdown();
extern int Filter_Status;
extern void dispatch();
extern int Waitrequest;
void shutdown_messages();
static char *Message;
static int MaxClients = 0,
do_msg();
extern int Reserve_Fds;
extern int Shutdown;
/*
** take_message() - WAIT FOR INTERRUPT OR ONE MESSAGE FROM USER PROCESS
*/
void take_message(void)
{
int bytes;
int i;
for (EVER) { /* not really forever...returns are in the loop */
switch(errno) {
case EAGAIN:
case EINTR:
return;
case ENOMEM:
mallocfail();
/* NOTREACHED */
default:
}
/*
* Check for a dropped connection to a child.
* Normally a child should tell us that it is dying
* (with S_SHUTDOWN or S_SEND_CHILD), but it may have
* died a fast death. We'll simulate the message we
* wanted to get so we can use the same code to clean up.
*/
case MD_CHILD:
/*
* If the message descriptor is found in the
* exec table, it must be an interface pgm,
* notification, etc. Otherwise, it must be
* a network child.
*/
for (i = 0; Exec_Table[i] != NULL; i++)
break;
if (Exec_Table[i] != NULL) {
Exec_Table[i]->key, 0, 0);
} else {
}
bytes = 1;
break;
default:
bytes = -1;
break;
}
} else {
return;
}
}
switch (bytes) {
case -1:
return;
else
break;
case 0:
break;
default:
return;
break;
}
}
}
/*
** do_msg() - HANDLE AN INCOMING MESSAGE
*/
static int
{
/*
* The message may have caused the need to
* schedule something, so go back and check.
*/
return(1);
}
return(0);
}
/*
** calculate_nopen() - DETERMINE # FILE DESCRIPTORS AVAILABLE FOR QUEUES
*/
static void
calculate_nopen(void)
{
/*
* How many file descriptorss are currently being used?
*/
nopen++;
/*
* How many file descriptors are available for use
* as open FIFOs? Leave one spare as a way to tell
* clients we don't have any to spare (hmmm....) and
* one for the incoming fifo.
*/
MaxClients--; /* the requests log */
MaxClients--; /* HPI routines and lpsched log */
return;
}
static void conn_shutdown ( )
{
if (!Shutdown) {
lpshut(1);
}
}
/*
** init_messages() - INITIALIZE MAIN MESSAGE QUEUE
*/
void
init_messages(void)
{
char *cmd;
calculate_nopen ();
if (mlisteninit(md) != 0)
mallocfail();
else
return;
}
void
shutdown_messages(void)
{
md = mlistenreset();
}