| 810 | */ |
| 811 | |
| 812 | static void |
| 813 | sysUpdate(void) |
| 814 | { |
| 815 | int i; /* Looping var */ |
| 816 | cupsd_sysevent_t sysevent; /* The system event */ |
| 817 | cupsd_printer_t *p; /* Printer information */ |
| 818 | |
| 819 | |
| 820 | /* |
| 821 | * Drain the event pipe... |
| 822 | */ |
| 823 | |
| 824 | while (read(SysEventPipes[0], &sysevent, sizeof(sysevent)) |
| 825 | == sizeof(sysevent)) |
| 826 | { |
| 827 | if (sysevent.event & SYSEVENT_CANSLEEP) |
| 828 | { |
| 829 | /* |
| 830 | * If there are active printers that don't have the connecting-to-device |
| 831 | * or cups-waiting-for-job-completed printer-state-reason then cancel the |
| 832 | * sleep request, i.e., these reasons indicate a job that is not actively |
| 833 | * doing anything... |
| 834 | */ |
| 835 | |
| 836 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); |
| 837 | p; |
| 838 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) |
| 839 | { |
| 840 | if (p->job) |
| 841 | { |
| 842 | for (i = 0; i < p->num_reasons; i ++) |
| 843 | if (!strcmp(p->reasons[i], "connecting-to-device") || |
| 844 | !strcmp(p->reasons[i], "cups-waiting-for-job-completed")) |
| 845 | break; |
| 846 | |
| 847 | if (!p->num_reasons || i >= p->num_reasons) |
| 848 | break; |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | if (p) |
| 853 | { |
| 854 | cupsdLogMessage(CUPSD_LOG_INFO, |
| 855 | "System sleep canceled because printer %s is active.", |
| 856 | p->name); |
| 857 | IOCancelPowerChange(sysevent.powerKernelPort, |
| 858 | sysevent.powerNotificationID); |
| 859 | } |
| 860 | else |
| 861 | { |
| 862 | cupsdLogMessage(CUPSD_LOG_DEBUG, "System wants to sleep."); |
| 863 | IOAllowPowerChange(sysevent.powerKernelPort, |
| 864 | sysevent.powerNotificationID); |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | if (sysevent.event & SYSEVENT_WILLSLEEP) |
| 869 | { |
nothing calls this directly
no test coverage detected