void cupsdPauseListening(void) { cupsd_listener_t *lis; /* Current listening socket */ if (cupsArrayCount(Listeners) < 1) return; 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)) cupsdRemoveSelect(lis->fd); ListeningPaused = time(NULL) + 30; }
static void dnssdStop(void) { cupsd_printer_t *p; /* Current printer */ /* * De-register the individual printers */ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers)) dnssdDeregisterPrinter(p, 1, 0); /* * Shutdown the rest of the service refs... */ dnssdDeregisterInstance(&WebIFSrv, 0); # ifdef HAVE_DNSSD cupsdRemoveSelect(DNSServiceRefSockFD(DNSSDMaster)); DNSServiceRefDeallocate(DNSSDMaster); DNSSDMaster = NULL; # else /* HAVE_AVAHI */ if (DNSSDMaster) avahi_threaded_poll_stop(DNSSDMaster); if (DNSSDClient) { avahi_client_free(DNSSDClient); DNSSDClient = NULL; } if (DNSSDMaster) { avahi_threaded_poll_free(DNSSDMaster); DNSSDMaster = NULL; } # endif /* HAVE_DNSSD */ cupsArrayDelete(DNSSDPrinters); DNSSDPrinters = NULL; DNSSDPort = 0; }
void cupsdStopAllNotifiers(void) { cupsd_subscription_t *sub; /* Current subscription */ /* * See if we have started any notifiers... */ if (!NotifierStatusBuffer) return; /* * Yes, kill any processes that are left... */ for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions); sub; sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions)) if (sub->pid) { cupsdEndProcess(sub->pid, 0); close(sub->pipe); sub->pipe = -1; } /* * Close the status pipes... */ if (NotifierPipes[0] >= 0) { cupsdRemoveSelect(NotifierPipes[0]); cupsdStatBufDelete(NotifierStatusBuffer); close(NotifierPipes[0]); close(NotifierPipes[1]); NotifierPipes[0] = -1; NotifierPipes[1] = -1; NotifierStatusBuffer = NULL; } }
void cupsdStopSystemMonitor(void) { CFRunLoopRef rl; /* The event handler runloop */ if (SysEventThread) { /* * Make sure the thread has completed it's initialization and * stored it's runloop reference in the shared global. */ pthread_mutex_lock(&SysEventThreadMutex); if (!SysEventRunloop) pthread_cond_wait(&SysEventThreadCond, &SysEventThreadMutex); rl = SysEventRunloop; SysEventRunloop = NULL; pthread_mutex_unlock(&SysEventThreadMutex); if (rl) CFRunLoopStop(rl); pthread_join(SysEventThread, NULL); pthread_mutex_destroy(&SysEventThreadMutex); pthread_cond_destroy(&SysEventThreadCond); } if (SysEventPipes[0] >= 0) { cupsdRemoveSelect(SysEventPipes[0]); cupsdClosePipe(SysEventPipes); } }
void cupsdStopServer(void) { if (!started) return; /* * Stop color management (as needed)... */ cupsdStopColor(); /* * Close all network clients... */ cupsdCloseAllClients(); cupsdStopListening(); cupsdStopBrowsing(); cupsdStopAllNotifiers(); cupsdDeleteAllCerts(); if (Clients) { cupsArrayDelete(Clients); Clients = NULL; } /* * Close the pipe for CGI processes... */ if (CGIPipes[0] >= 0) { cupsdRemoveSelect(CGIPipes[0]); cupsdStatBufDelete(CGIStatusBuffer); close(CGIPipes[1]); CGIPipes[0] = -1; CGIPipes[1] = -1; } /* * Close all log files... */ if (AccessFile != NULL) { cupsFileClose(AccessFile); AccessFile = NULL; } if (ErrorFile != NULL) { cupsFileClose(ErrorFile); ErrorFile = NULL; } if (PageFile != NULL) { cupsFileClose(PageFile); PageFile = NULL; } /* * Delete the default security profile... */ cupsdDestroyProfile(DefaultProfile); DefaultProfile = NULL; /* * Write out any dirty files... */ if (DirtyFiles) cupsdCleanDirty(); started = 0; }
void cupsdStopServer(void) { if (!started) return; /* * Close all network clients and stop all jobs... */ cupsdCloseAllClients(); cupsdStopListening(); cupsdStopPolling(); cupsdStopBrowsing(); cupsdStopAllNotifiers(); cupsdSaveRemoteCache(); cupsdDeleteAllCerts(); if (Clients) { cupsArrayDelete(Clients); Clients = NULL; } /* * Close the pipe for CGI processes... */ if (CGIPipes[0] >= 0) { cupsdRemoveSelect(CGIPipes[0]); cupsdStatBufDelete(CGIStatusBuffer); close(CGIPipes[1]); CGIPipes[0] = -1; CGIPipes[1] = -1; } /* * Close all log files... */ if (AccessFile != NULL) { cupsFileClose(AccessFile); AccessFile = NULL; } if (ErrorFile != NULL) { cupsFileClose(ErrorFile); ErrorFile = NULL; } if (PageFile != NULL) { cupsFileClose(PageFile); PageFile = NULL; } #ifdef HAVE_NOTIFY_POST /* * Send one last notification as the server shuts down. */ cupsdLogMessage(CUPSD_LOG_DEBUG, "notify_post(\"com.apple.printerListChange\") last"); notify_post("com.apple.printerListChange"); #endif /* HAVE_NOTIFY_POST */ started = 0; }