+static void spoolss_manage_pool(struct tevent_context *ev_ctx,
+ struct messaging_context *msg_ctx)
+{
+ time_t now = time(NULL);
+ int active, total;
+ int ret, n;
+
+ if ((spoolss_prefork_status & SPOOLSS_NEW_MAX) &&
+ !(spoolss_prefork_status & SPOLLSS_ENOSPC)) {
+ ret = prefork_expand_pool(spoolss_pool, spoolss_max_children);
+ if (ret == ENOSPC) {
+ spoolss_prefork_status |= SPOLLSS_ENOSPC;
+ }
+ spoolss_prefork_status &= ~SPOOLSS_NEW_MAX;
+ }
+
+ active = prefork_count_active_children(spoolss_pool, &total);
+
+ if ((total < spoolss_max_children) &&
+ ((total < spoolss_min_children) ||
+ (total - active < spoolss_spawn_rate))) {
+ n = prefork_add_children(ev_ctx, msg_ctx,
+ spoolss_pool, spoolss_spawn_rate);
+ if (n < spoolss_spawn_rate) {
+ DEBUG(10, ("Tried to start %d children but only,"
+ "%d were actually started.!\n",
+ spoolss_spawn_rate, n));
+ }
+ }
+
+ if (total - active > spoolss_min_children) {
+ if ((total - spoolss_min_children) >= spoolss_spawn_rate) {
+ prefork_retire_children(spoolss_pool,
+ spoolss_spawn_rate,
+ now - SPOOLSS_MIN_LIFE);
+ }
+ }
+
+ n = prefork_count_allowed_connections(spoolss_pool);
+ if (n <= spoolss_spawn_rate) {
+ do {
+ prefork_increase_allowed_clients(spoolss_pool);
+ n = prefork_count_allowed_connections(spoolss_pool);
+ } while (n <= spoolss_spawn_rate);
+ } else if (n > spoolss_max_children + spoolss_spawn_rate) {
+ do {
+ prefork_decrease_allowed_clients(spoolss_pool);
+ n = prefork_count_allowed_connections(spoolss_pool);
+ } while (n > spoolss_max_children + spoolss_spawn_rate);
+ }
+}
+