/*
- * "$Id: listen.c 177 2006-06-21 00:20:03Z jlovell $"
+ * "$Id: listen.c 7918 2008-09-08 22:03:01Z mike $"
*
* Server listening routines for the Common UNIX Printing System (CUPS)
* scheduler.
*
+ * Copyright 2007-2008 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* Contents:
*
if (cupsArrayCount(Clients) == MaxClients)
cupsdLogMessage(CUPSD_LOG_WARN,
"Max clients reached, holding new connections...");
+ else if (errno == ENFILE || errno == EMFILE)
+ cupsdLogMessage(CUPSD_LOG_WARN,
+ "Too many open files, holding new connections for "
+ "30 seconds...");
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdPauseListening: Clearing input bits...");
for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
lis;
lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
- if (lis->fd >= 0)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "cupsdPauseListening: Removing fd %d from InputSet...",
- lis->fd);
+ cupsdRemoveSelect(lis->fd);
- FD_CLR(lis->fd, InputSet);
- }
+ ListeningPaused = time(NULL) + 30;
}
if (cupsArrayCount(Listeners) < 1)
return;
- if (cupsArrayCount(Clients) >= (MaxClients - 1))
- cupsdLogMessage(CUPSD_LOG_WARN, "Resuming new connection processing...");
-
+ cupsdLogMessage(CUPSD_LOG_INFO, "Resuming new connection processing...");
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"cupsdResumeListening: Setting input bits...");
for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
lis;
lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
- if (lis->fd >= 0)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "cupsdResumeListening: Adding fd %d to InputSet...",
- lis->fd);
- FD_SET(lis->fd, InputSet);
- }
+ cupsdAddSelect(lis->fd, (cupsd_selfunc_t)cupsdAcceptClient, NULL, lis);
+
+ ListeningPaused = 0;
}
httpAddrFreeList(ServerAddrs);
if ((ServerAddrs = httpAddrGetList(ServerName, AF_UNSPEC, NULL)) == NULL)
+ {
cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to find IP address for server name \"%s\"!\n",
+ "Unable to find IP address for server name \"%s\"!",
ServerName);
+ if (FatalErrors & CUPSD_FATAL_LISTEN)
+ cupsdEndProcess(getpid(), 0);
+ }
+
/*
* Setup socket listeners...
*/
cupsdLogMessage(CUPSD_LOG_ERROR,
"Unable to open listen socket for address %s:%d - %s.",
s, p, strerror(errno));
+
+#ifdef AF_INET6
+ /*
+ * IPv6 is often disabled while DNS returns IPv6 addresses...
+ */
+
+ if (lis->address.addr.sa_family != AF_INET6 &&
+ (FatalErrors & CUPSD_FATAL_LISTEN))
+ cupsdEndProcess(getpid(), 0);
+#else
+ if (FatalErrors & CUPSD_FATAL_LISTEN)
+ cupsdEndProcess(getpid(), 0);
+#endif /* AF_INET6 */
+
continue;
}
s, p, strerror(errno));
close(lis->fd);
lis->fd = -1;
+
+ if (FatalErrors & CUPSD_FATAL_LISTEN)
+ cupsdEndProcess(getpid(), 0);
+
continue;
}
cupsdLogMessage(CUPSD_LOG_ERROR,
"Unable to listen for clients on address %s:%d - %s.",
s, p, strerror(errno));
- exit(errno);
+
+ close(lis->fd);
+ lis->fd = -1;
+
+ if (FatalErrors & CUPSD_FATAL_LISTEN)
+ cupsdEndProcess(getpid(), 0);
+
+ continue;
}
}
* "any" address...
*/
- if (!LocalPort && p > 0 &&
+ if ((!LocalPort || LocalEncryption == HTTP_ENCRYPT_ALWAYS) && p > 0 &&
(httpAddrLocalhost(&(lis->address)) ||
httpAddrAny(&(lis->address))))
{
if (!LocalPort && !have_domain)
{
cupsdLogMessage(CUPSD_LOG_EMERG,
- "No Listen or Port lines were found to allow access via localhost!");
-
- /*
- * Commit suicide...
- */
+ "No Listen or Port lines were found to allow access via "
+ "localhost!");
- cupsdEndProcess(getpid(), 0);
+ if (FatalErrors & (CUPSD_FATAL_CONFIG | CUPSD_FATAL_LISTEN))
+ cupsdEndProcess(getpid(), 0);
}
/*
*/
cupsdSetEnv("CUPS_SERVER", have_domain);
+
+ LocalEncryption = HTTP_ENCRYPT_IF_REQUESTED;
}
else
{
}
cupsdSetEnv("CUPS_ENCRYPTION", encryptions[LocalEncryption]);
- cupsdSetEnvf("IPP_PORT", "%d", LocalPort);
+
+ if (LocalPort)
+ cupsdSetEnvf("IPP_PORT", "%d", LocalPort);
/*
* Resume listening for connections...
/*
- * End of "$Id: listen.c 177 2006-06-21 00:20:03Z jlovell $".
+ * End of "$Id: listen.c 7918 2008-09-08 22:03:01Z mike $".
*/