From: Brian Norris Date: Fri, 27 May 2016 20:06:58 +0000 (-0700) Subject: Factor out generic 'HAVE_ONDEMAND' macro flag X-Git-Tag: v2.2b2~8^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c187d9abe735d867f1dc47db5646495250394bc9;p=thirdparty%2Fcups.git Factor out generic 'HAVE_ONDEMAND' macro flag HAVE_SYSTEMD and HAVE_LAUNCHD use very similar code for on-demand launching of cupsd, and if we want to add one more (e.g., upstart) it's easier to just use a single common flag: HAVE_ONDEMAND. --- diff --git a/config.h.in b/config.h.in index e242d56118..526f91a5eb 100644 --- a/config.h.in +++ b/config.h.in @@ -717,4 +717,10 @@ static __inline int _cups_abs(int i) { return (i < 0 ? -i : i); } # endif /* __GNUC__ || __STDC_VERSION__ */ #endif /* !HAVE_ABS && !abs */ +#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +# define HAVE_ONDEMAND +#else +# undef HAVE_ONDEMAND +#endif + #endif /* !_CUPS_CONFIG_H_ */ diff --git a/scheduler/client.h b/scheduler/client.h index a7811fa781..174b7271e7 100644 --- a/scheduler/client.h +++ b/scheduler/client.h @@ -79,9 +79,9 @@ typedef struct int fd; /* File descriptor for this server */ http_addr_t address; /* Bind address of socket */ http_encryption_t encryption; /* To encrypt or not to encrypt... */ -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) int on_demand; /* Is this a socket from launchd/systemd? */ -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ } cupsd_listener_t; diff --git a/scheduler/conf.c b/scheduler/conf.c index 5f97fa3b8e..7695f56f4a 100644 --- a/scheduler/conf.c +++ b/scheduler/conf.c @@ -89,9 +89,9 @@ static const cupsd_var_t cupsd_vars[] = #ifdef HAVE_GSSAPI { "GSSServiceName", &GSSServiceName, CUPSD_VARTYPE_STRING }, #endif /* HAVE_GSSAPI */ -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) { "IdleExitTimeout", &IdleExitTimeout, CUPSD_VARTYPE_TIME }, -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ { "JobKillDelay", &JobKillDelay, CUPSD_VARTYPE_TIME }, { "JobRetryLimit", &JobRetryLimit, CUPSD_VARTYPE_INTEGER }, { "JobRetryInterval", &JobRetryInterval, CUPSD_VARTYPE_TIME }, @@ -810,9 +810,9 @@ cupsdReadConfiguration(void) DefaultLeaseDuration = 86400; MaxLeaseDuration = 0; -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) IdleExitTimeout = 60; -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ /* * Setup environment variables... @@ -3149,9 +3149,9 @@ read_cupsd_conf(cups_file_t *fp) /* I - File to read from */ if (lis) { -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) if (!lis->on_demand) -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ { httpAddrString(&lis->address, temp, sizeof(temp)); cupsdLogMessage(CUPSD_LOG_WARN, diff --git a/scheduler/conf.h b/scheduler/conf.h index 076d63db03..ff18b77500 100644 --- a/scheduler/conf.h +++ b/scheduler/conf.h @@ -244,10 +244,10 @@ VAR char *ServerKeychain VALUE(NULL); /* Keychain holding cert + key */ #endif /* HAVE_SSL */ -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) VAR int IdleExitTimeout VALUE(60); /* Time after which an idle cupsd will exit */ -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ #ifdef HAVE_AUTHORIZATION_H VAR char *SystemGroupAuthKey VALUE(NULL); diff --git a/scheduler/cupsd.h b/scheduler/cupsd.h index a36ae88d1d..669560c15b 100644 --- a/scheduler/cupsd.h +++ b/scheduler/cupsd.h @@ -157,10 +157,10 @@ VAR int NeedReload VALUE(RELOAD_ALL), VAR void *DefaultProfile VALUE(0); /* Default security profile */ -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) VAR int OnDemand VALUE(0); /* Launched on demand */ -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ /* diff --git a/scheduler/listen.c b/scheduler/listen.c index 06e2ed6aac..7cfe8dbd1b 100644 --- a/scheduler/listen.c +++ b/scheduler/listen.c @@ -41,9 +41,9 @@ cupsdDeleteAllListeners(void) for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners); lis; lis = (cupsd_listener_t *)cupsArrayNext(Listeners)) -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) if (!lis->on_demand) -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ { cupsArrayRemove(Listeners, lis); free(lis); @@ -281,7 +281,7 @@ cupsdStopListening(void) lis; lis = (cupsd_listener_t *)cupsArrayNext(Listeners)) { -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) if (!lis->on_demand && lis->fd != -1) { httpAddrClose(&(lis->address), lis->fd); @@ -294,6 +294,6 @@ cupsdStopListening(void) httpAddrClose(&(lis->address), lis->fd); lis->fd = -1; } -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ } } diff --git a/scheduler/main.c b/scheduler/main.c index f9b46bad6e..8b65ae1e43 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -71,10 +71,10 @@ static void sigchld_handler(int sig); static void sighup_handler(int sig); static void sigterm_handler(int sig); static long select_timeout(int fds); -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) static void service_checkin(void); static void service_checkout(void); -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ static void usage(int status) __attribute__((noreturn)); @@ -131,10 +131,10 @@ main(int argc, /* I - Number of command-line args */ #else time_t netif_time = 0; /* Time since last network update */ #endif /* __APPLE__ */ -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) int service_idle_exit; /* Idle exit on select timeout? */ -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ #ifdef HAVE_GETEUID @@ -243,7 +243,7 @@ main(int argc, /* I - Number of command-line args */ break; case 'l' : /* Started by launchd/systemd... */ -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) OnDemand = 1; fg = 1; close_all = 0; @@ -254,7 +254,7 @@ main(int argc, /* I - Number of command-line args */ fg = 0; disconnect = 1; close_all = 1; -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ break; case 'p' : /* Stop immediately for profiling */ @@ -584,7 +584,7 @@ main(int argc, /* I - Number of command-line args */ cupsdCleanFiles(CacheDir, "*.ipp"); -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) if (OnDemand) { /* @@ -595,7 +595,7 @@ main(int argc, /* I - Number of command-line args */ service_checkin(); service_checkout(); } -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ /* * Startup the server... @@ -682,11 +682,11 @@ main(int argc, /* I - Number of command-line args */ * Send server-started event... */ -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) if (OnDemand) cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED, NULL, NULL, "Scheduler started on demand."); else -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ if (fg) cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED, NULL, NULL, "Scheduler started in foreground."); else @@ -809,7 +809,7 @@ main(int argc, /* I - Number of command-line args */ if ((timeout = select_timeout(fds)) > 1 && LastEvent) timeout = 1; -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) /* * If no other work is scheduled and we're being controlled by * launchd then timeout after 'LaunchdTimeout' seconds of @@ -828,7 +828,7 @@ main(int argc, /* I - Number of command-line args */ } else service_idle_exit = 0; -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ if ((fds = cupsdDoSelect(timeout)) < 0) { @@ -925,7 +925,7 @@ main(int argc, /* I - Number of command-line args */ } #endif /* !__APPLE__ */ -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) /* * If no other work was scheduled and we're being controlled by launchd * then timeout after 'LaunchdTimeout' seconds of inactivity... @@ -939,7 +939,7 @@ main(int argc, /* I - Number of command-line args */ stop_scheduler = 1; break; } -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ /* * Resume listening for new connections as needed... @@ -1143,14 +1143,14 @@ main(int argc, /* I - Number of command-line args */ cupsdStopServer(); -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) /* * Update the keep-alive file as needed... */ if (OnDemand) service_checkout(); -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ /* * Stop all jobs... @@ -1822,7 +1822,7 @@ sigterm_handler(int sig) /* I - Signal number */ } -#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +#if defined(HAVE_ONDEMAND) /* * 'service_checkin()' - Check-in with launchd and collect the listening fds. */ @@ -2174,7 +2174,7 @@ service_checkout(void) unlink(CUPS_KEEPALIVE); } } -#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ +#endif /* HAVE_ONDEMAND */ /* diff --git a/vcnet/config.h b/vcnet/config.h index e8e73f6b13..0f1291cc59 100644 --- a/vcnet/config.h +++ b/vcnet/config.h @@ -777,4 +777,10 @@ static __inline int _cups_abs(int i) { return (i < 0 ? -i : i); } # endif /* __GNUC__ || __STDC_VERSION__ */ #endif /* !HAVE_ABS && !abs */ +#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +# define HAVE_ONDEMAND +#else +# undef HAVE_ONDEMAND +#endif + #endif /* !_CUPS_CONFIG_H_ */ diff --git a/xcode/config.h b/xcode/config.h index e16c6667cb..a0c5c9b3d4 100644 --- a/xcode/config.h +++ b/xcode/config.h @@ -733,4 +733,10 @@ static __inline int _cups_abs(int i) { return (i < 0 ? -i : i); } # endif /* __GNUC__ || __STDC_VERSION__ */ #endif /* !HAVE_ABS && !abs */ +#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) +# define HAVE_ONDEMAND +#else +# undef HAVE_ONDEMAND +#endif + #endif /* !_CUPS_CONFIG_H_ */