| 304 | */ |
| 305 | |
| 306 | void |
| 307 | cupsdStartSystemMonitor(void) |
| 308 | { |
| 309 | int flags; /* fcntl flags on pipe */ |
| 310 | |
| 311 | |
| 312 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartSystemMonitor()"); |
| 313 | |
| 314 | if (cupsdOpenPipe(SysEventPipes)) |
| 315 | { |
| 316 | cupsdLogMessage(CUPSD_LOG_ERROR, "System event monitor pipe() failed - %s!", |
| 317 | strerror(errno)); |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | cupsdAddSelect(SysEventPipes[0], (cupsd_selfunc_t)sysUpdate, NULL, NULL); |
| 322 | |
| 323 | /* |
| 324 | * Set non-blocking mode on the descriptor we will be receiving notification |
| 325 | * events on. |
| 326 | */ |
| 327 | |
| 328 | flags = fcntl(SysEventPipes[0], F_GETFL, 0); |
| 329 | fcntl(SysEventPipes[0], F_SETFL, flags | O_NONBLOCK); |
| 330 | |
| 331 | /* |
| 332 | * Start the thread that runs the runloop... |
| 333 | */ |
| 334 | |
| 335 | pthread_mutex_init(&SysEventThreadMutex, NULL); |
| 336 | pthread_cond_init(&SysEventThreadCond, NULL); |
| 337 | pthread_create(&SysEventThread, NULL, (void *(*)(void *))sysEventThreadEntry, NULL); |
| 338 | |
| 339 | /* |
| 340 | * Monitor for power source changes via dispatch queue... |
| 341 | */ |
| 342 | |
| 343 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartSystemMonitor: IOPSGetTimeRemainingEstimate=%f", IOPSGetTimeRemainingEstimate()); |
| 344 | ACPower = IOPSGetTimeRemainingEstimate() == kIOPSTimeRemainingUnlimited; |
| 345 | notify_register_dispatch(kIOPSNotifyPowerSource, &PSToken, dispatch_get_main_queue(), ^(int t) { (void)t; |
| 346 | ACPower = IOPSGetTimeRemainingEstimate() == kIOPSTimeRemainingUnlimited; }); |
| 347 | } |
| 348 | |
| 349 | |
| 350 | /* |
no test coverage detected