void cupsdStartSystemMonitor(void) { int flags; /* fcntl flags on pipe */ if (cupsdOpenPipe(SysEventPipes)) { cupsdLogMessage(CUPSD_LOG_ERROR, "System event monitor pipe() failed - %s!", strerror(errno)); return; } cupsdAddSelect(SysEventPipes[0], (cupsd_selfunc_t)sysUpdate, NULL, NULL); /* * Set non-blocking mode on the descriptor we will be receiving notification * events on. */ flags = fcntl(SysEventPipes[0], F_GETFL, 0); fcntl(SysEventPipes[0], F_SETFL, flags | O_NONBLOCK); /* * Start the thread that runs the runloop... */ pthread_mutex_init(&SysEventThreadMutex, NULL); pthread_cond_init(&SysEventThreadCond, NULL); pthread_create(&SysEventThread, NULL, (void *(*)())sysEventThreadEntry, NULL); }
void cupsdStartServer(void) { /* * Start color management (as needed)... */ cupsdStartColor(); /* * Create the default security profile... */ DefaultProfile = cupsdCreateProfile(0, 1); /* * Startup all the networking stuff... */ cupsdStartListening(); cupsdStartBrowsing(); /* * Create a pipe for CGI processes... */ if (cupsdOpenPipe(CGIPipes)) cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdStartServer: Unable to create pipes for CGI status!"); else { CGIStatusBuffer = cupsdStatBufNew(CGIPipes[0], "[CGI]"); cupsdAddSelect(CGIPipes[0], (cupsd_selfunc_t)cupsdUpdateCGI, NULL, NULL); } /* * Mark that the server has started and printers and jobs may be changed... */ LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED | CUPSD_EVENT_SERVER_STARTED; started = 1; cupsdSetBusyState(); }
void cupsdStartSystemMonitor(void) { int flags; /* fcntl flags on pipe */ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartSystemMonitor()"); if (cupsdOpenPipe(SysEventPipes)) { cupsdLogMessage(CUPSD_LOG_ERROR, "System event monitor pipe() failed - %s!", strerror(errno)); return; } cupsdAddSelect(SysEventPipes[0], (cupsd_selfunc_t)sysUpdate, NULL, NULL); /* * Set non-blocking mode on the descriptor we will be receiving notification * events on. */ flags = fcntl(SysEventPipes[0], F_GETFL, 0); fcntl(SysEventPipes[0], F_SETFL, flags | O_NONBLOCK); /* * Start the thread that runs the runloop... */ pthread_mutex_init(&SysEventThreadMutex, NULL); pthread_cond_init(&SysEventThreadCond, NULL); pthread_create(&SysEventThread, NULL, (void *(*)())sysEventThreadEntry, NULL); /* * Monitor for power source changes via dispatch queue... */ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartSystemMonitor: IOPSGetTimeRemainingEstimate=%f", IOPSGetTimeRemainingEstimate()); ACPower = IOPSGetTimeRemainingEstimate() == kIOPSTimeRemainingUnlimited; notify_register_dispatch(kIOPSNotifyPowerSource, &PSToken, dispatch_get_main_queue(), ^(int t) { (void)t; ACPower = IOPSGetTimeRemainingEstimate() == kIOPSTimeRemainingUnlimited; });
static void cupsd_start_notifier( cupsd_subscription_t *sub) /* I - Subscription object */ { int pid; /* Notifier process ID */ int fds[2]; /* Pipe file descriptors */ char *argv[4], /* Command-line arguments */ *envp[MAX_ENV], /* Environment variables */ user_data[128], /* Base-64 encoded user data */ scheme[256], /* notify-recipient-uri scheme */ *ptr, /* Pointer into scheme */ command[1024]; /* Notifier command */ /* * Extract the scheme name from the recipient URI and point to the * notifier program... */ strlcpy(scheme, sub->recipient, sizeof(scheme)); if ((ptr = strchr(scheme, ':')) != NULL) *ptr = '\0'; snprintf(command, sizeof(command), "%s/notifier/%s", ServerBin, scheme); /* * Base-64 encode the user data... */ httpEncode64_2(user_data, sizeof(user_data), (char *)sub->user_data, sub->user_data_len); /* * Setup the argument array... */ argv[0] = command; argv[1] = sub->recipient; argv[2] = user_data; argv[3] = NULL; /* * Setup the environment... */ cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0]))); /* * Create pipes as needed... */ if (!NotifierStatusBuffer) { /* * Create the status pipe... */ if (cupsdOpenPipe(NotifierPipes)) { cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create pipes for notifier status - %s", strerror(errno)); return; } NotifierStatusBuffer = cupsdStatBufNew(NotifierPipes[0], "[Notifier]"); cupsdAddSelect(NotifierPipes[0], (cupsd_selfunc_t)cupsd_update_notifier, NULL, NULL); } if (cupsdOpenPipe(fds)) { cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create pipes for notifier %s - %s", scheme, strerror(errno)); return; } /* * Make sure the delivery pipe is non-blocking... */ fcntl(fds[1], F_SETFL, fcntl(fds[1], F_GETFL) | O_NONBLOCK); /* * Create the notifier process... */ if (cupsdStartProcess(command, argv, envp, fds[0], -1, NotifierPipes[1], -1, -1, 0, DefaultProfile, NULL, &pid) < 0) { /* * Error - can't fork! */ cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to fork for notifier %s - %s", scheme, strerror(errno)); cupsdClosePipe(fds); } else { /* * Fork successful - return the PID... */ cupsdLogMessage(CUPSD_LOG_DEBUG, "Notifier %s started - PID = %d", scheme, pid); sub->pid = pid; sub->pipe = fds[1]; sub->status = 0; close(fds[0]); } }
void cupsdStartServer(void) { #ifdef HAVE_LIBSSL int i; /* Looping var */ struct timeval curtime; /* Current time in microseconds */ unsigned char data[1024]; /* Seed data */ #endif /* HAVE_LIBSSL */ #ifdef HAVE_LIBSSL /* * Initialize the encryption libraries... */ printf("[server.c::cupsdStartServer()] initializing the SSL encryption libraries\n"); SSL_library_init(); SSL_load_error_strings(); /* * Using the current time is a dubious random seed, but on some systems * it is the best we can do (on others, this seed isn't even used...) */ gettimeofday(&curtime, NULL); srand(curtime.tv_sec + curtime.tv_usec); for (i = 0; i < sizeof(data); i ++) data[i] = rand(); /* Yes, this is a poor source of random data... */ RAND_seed(&data, sizeof(data)); printf("[server.c::cupsdStartServer()] seeding a lot of crap \n"); #elif defined(HAVE_GNUTLS) /* * Initialize the encryption libraries... */ printf("[server.c::cupsdStartServer()] initializing the gnutils libraries \n"); gnutls_global_init(); #endif /* HAVE_LIBSSL */ /* * Startup all the networking stuff... */ cupsdStartListening(); cupsdStartBrowsing(); cupsdStartPolling(); /* * Create a pipe for CGI processes... */ if (cupsdOpenPipe(CGIPipes)) cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdStartServer: Unable to create pipes for CGI status!"); else { CGIStatusBuffer = cupsdStatBufNew(CGIPipes[0], "[CGI]"); printf("[server.c::cupsdStartServer()] created a pipe for cgi processes, adding to polling engine \n"); cupsdAddSelect(CGIPipes[0], (cupsd_selfunc_t)cupsdUpdateCGI, NULL, NULL); } /* * Mark that the server has started and printers and jobs may be changed... */ LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED | CUPSD_EVENT_SERVER_STARTED; started = 1; printf("[server.c::cupsdStartServer()] done \n"); }