/*
- * "$Id: listen.c 5053 2006-02-02 18:14:38Z mike $"
+ * "$Id: listen.c 5083 2006-02-06 02:57:43Z mike $"
*
* Server listening routines for the Common UNIX Printing System (CUPS)
* scheduler.
*
* Contents:
*
- * cupsdPauseListening() - Clear input polling on all listening sockets...
- * cupsdResumeListening() - Set input polling on all listening sockets...
- * cupsdStartListening() - Create all listening sockets...
- * cupsdStopListening() - Close all listening sockets...
+ * cupsdDeleteAllListeners() - Delete all listeners.
+ * cupsdPauseListening() - Clear input polling on all listening sockets...
+ * cupsdResumeListening() - Set input polling on all listening sockets...
+ * cupsdStartListening() - Create all listening sockets...
+ * cupsdStopListening() - Close all listening sockets...
*/
/*
#endif /* __linux && !IPV6_V6ONLY */
+/*
+ * 'cupsdDeleteAllListeners()' - Delete all listeners.
+ */
+
+void
+cupsdDeleteAllListeners(void)
+{
+ cupsd_listener_t *lis; /* Current listening socket */
+
+
+ for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
+ lis;
+ lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
+ free(lis);
+
+ cupsArrayDelete(Listeners);
+ Listeners = NULL;
+}
+
+
/*
* 'cupsdPauseListening()' - Clear input polling on all listening sockets...
*/
void
cupsdPauseListening(void)
{
- int i; /* Looping var */
cupsd_listener_t *lis; /* Current listening socket */
- if (NumListeners < 1)
+ if (cupsArrayCount(Listeners) < 1)
return;
- if (NumClients == MaxClients)
+ if (cupsArrayCount(Clients) == MaxClients)
cupsdLogMessage(CUPSD_LOG_WARN,
"Max clients reached, holding new connections...");
- cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdPauseListening: Clearing input bits...");
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdPauseListening: Clearing input bits...");
- for (i = NumListeners, lis = Listeners; i > 0; i --, lis ++)
+ for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
+ lis;
+ lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
if (lis->fd >= 0)
{
cupsdLogMessage(CUPSD_LOG_DEBUG2,
void
cupsdResumeListening(void)
{
- int i; /* Looping var */
cupsd_listener_t *lis; /* Current listening socket */
- if (NumListeners < 1)
+ if (cupsArrayCount(Listeners) < 1)
return;
- if (NumClients >= (MaxClients - 1))
+ if (cupsArrayCount(Clients) >= (MaxClients - 1))
cupsdLogMessage(CUPSD_LOG_WARN, "Resuming new connection processing...");
- cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdResumeListening: Setting input bits...");
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdResumeListening: Setting input bits...");
- for (i = NumListeners, lis = Listeners; i > 0; i --, lis ++)
+ for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
+ lis;
+ lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
if (lis->fd >= 0)
{
cupsdLogMessage(CUPSD_LOG_DEBUG2,
cupsdStartListening(void)
{
int status; /* Bind result */
- int i, /* Looping var */
- p, /* Port number */
+ int p, /* Port number */
val; /* Parameter value */
cupsd_listener_t *lis; /* Current listening socket */
char s[256]; /* String addresss */
};
- cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdStartListening: NumListeners=%d",
- NumListeners);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartListening: %d Listeners",
+ cupsArrayCount(Listeners));
/*
* Get the server's IP address...
if ((ServerAddrs = httpAddrGetList(ServerName, AF_UNSPEC, NULL)) == NULL)
cupsdLogMessage(CUPSD_LOG_ERROR,
- "cupsdStartListening: Unable to find IP address for "
- "server name \"%s\"!\n", ServerName);
+ "Unable to find IP address for server name \"%s\"!\n",
+ ServerName);
/*
* Setup socket listeners...
*/
- for (i = NumListeners, lis = Listeners, LocalPort = 0, have_domain = NULL;
- i > 0; i --, lis ++)
+ for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners), LocalPort = 0,
+ have_domain = NULL;
+ lis;
+ lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
{
httpAddrString(&(lis->address), s, sizeof(s));
/*
* Create a socket for listening...
*/
-
+
lis->fd = socket(lis->address.addr.sa_family, SOCK_STREAM, 0);
-
+
if (lis->fd == -1)
{
cupsdLogMessage(CUPSD_LOG_ERROR,
- "cupsdStartListening: Unable to open listen socket for address %s:%d - %s.",
+ "Unable to open listen socket for address %s:%d - %s.",
s, p, strerror(errno));
continue;
}
-
+
/*
* Set things up to reuse the local address for this port.
*/
-
+
val = 1;
#ifdef __sun
setsockopt(lis->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
#else
setsockopt(lis->fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
#endif /* __sun */
-
+
/*
* Bind to the port we found...
*/
-
+
#ifdef AF_INET6
if (lis->address.addr.sa_family == AF_INET6)
{
* potential security issues and to make all platforms behave
* the same.
*/
-
+
val = 1;
# ifdef __sun
setsockopt(lis->fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&val, sizeof(val));
setsockopt(lis->fd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val));
# endif /* __sun */
# endif /* IPV6_V6ONLY */
-
+
status = bind(lis->fd, (struct sockaddr *)&(lis->address),
httpAddrLength(&(lis->address)));
}
if (lis->address.addr.sa_family == AF_LOCAL)
{
mode_t mask; /* Umask setting */
-
-
+
+
/*
* Remove any existing domain socket file...
*/
-
+
unlink(lis->address.un.sun_path);
-
+
/*
* Save the curent umask and set it to 0...
*/
-
+
mask = umask(0);
-
+
/*
* Bind the domain socket...
*/
-
+
status = bind(lis->fd, (struct sockaddr *)&(lis->address),
httpAddrLength(&(lis->address)));
-
+
/*
* Restore the umask...
*/
-
+
umask(mask);
}
else
#endif /* AF_LOCAL */
status = bind(lis->fd, (struct sockaddr *)&(lis->address),
sizeof(lis->address.ipv4));
-
+
if (status < 0)
{
cupsdLogMessage(CUPSD_LOG_ERROR,
- "cupsdStartListening: Unable to bind socket for address %s:%d - %s.",
+ "Unable to bind socket for address %s:%d - %s.",
s, p, strerror(errno));
close(lis->fd);
lis->fd = -1;
continue;
}
-
+
/*
* Listen for new clients.
*/
-
+
if (listen(lis->fd, ListenBackLog) < 0)
{
cupsdLogMessage(CUPSD_LOG_ERROR,
- "cupsdStartListening: Unable to listen for clients on address %s:%d - %s.",
+ "Unable to listen for clients on address %s:%d - %s.",
s, p, strerror(errno));
exit(errno);
}
}
fcntl(lis->fd, F_SETFD, fcntl(lis->fd, F_GETFD) | FD_CLOEXEC);
-
if (p)
- cupsdLogMessage(CUPSD_LOG_INFO,
- "cupsdStartListening: Listening to %s:%d on fd %d...",
+ cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d on fd %d...",
s, p, lis->fd);
else
{
- cupsdLogMessage(CUPSD_LOG_INFO,
- "cupsdStartListening: Listening to %s on fd %d...",
+ cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s on fd %d...",
s, lis->fd);
if (chmod(s, 0140777))
cupsdLogMessage(CUPSD_LOG_ERROR,
- "cupsdStartListening: Unable to change permisssions on "
- "domain socket \"%s\" - %s", s, strerror(errno));
+ "Unable to change permisssions on domain socket "
+ "\"%s\" - %s", s, strerror(errno));
}
/*
void
cupsdStopListening(void)
{
- int i; /* Looping var */
cupsd_listener_t *lis; /* Current listening socket */
- cupsdLogMessage(CUPSD_LOG_DEBUG,
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
"cupsdStopListening: closing all listen sockets.");
cupsdPauseListening();
- for (i = NumListeners, lis = Listeners; i > 0; i --, lis ++)
+ for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
+ lis;
+ lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
{
if (lis->fd != -1)
{
/*
- * End of "$Id: listen.c 5053 2006-02-02 18:14:38Z mike $".
+ * End of "$Id: listen.c 5083 2006-02-06 02:57:43Z mike $".
*/