Example #1
0
static void fpm_sockets_cleanup(int which, void *arg) /* {{{ */
{
	unsigned i;
	char *env_value = 0;
	int p = 0;
	struct listening_socket_s *ls = sockets_list.data;

	for (i = 0; i < sockets_list.used; i++, ls++) {
		if (which != FPM_CLEANUP_PARENT_EXEC) {
			close(ls->sock);
		} else { /* on PARENT EXEC we want socket fds to be inherited through environment variable */
			char fd[32];
			sprintf(fd, "%d", ls->sock);
			env_value = realloc(env_value, p + (p ? 1 : 0) + strlen(ls->key) + 1 + strlen(fd) + 1);
			p += sprintf(env_value + p, "%s%s=%s", p ? "," : "", ls->key, fd);
		}

		if (which == FPM_CLEANUP_PARENT_EXIT_MAIN) {
			if (ls->type == FPM_AF_UNIX) {
				unlink(ls->key);
			}
		}
		free(ls->key);
	}

	if (env_value) {
		setenv("FPM_SOCKETS", env_value, 1);
		free(env_value);
	}

	fpm_array_free(&sockets_list);
}
Example #2
0
static void fpm_sockets_cleanup(int which, void *arg) /* {{{ */
{
	unsigned i;
	unsigned socket_set_count = 0;
	unsigned socket_set[FPM_ENV_SOCKET_SET_MAX];
	unsigned socket_set_buf = 0;
	char envname[32];
	char *env_value = 0;
	int p = 0;
	struct listening_socket_s *ls = sockets_list.data;

	for (i = 0; i < sockets_list.used; i++, ls++) {
		if (which != FPM_CLEANUP_PARENT_EXEC) {
			close(ls->sock);
		} else { /* on PARENT EXEC we want socket fds to be inherited through environment variable */
			char fd[32];
			sprintf(fd, "%d", ls->sock);

			socket_set_buf = (i % FPM_ENV_SOCKET_SET_SIZE == 0 && i) ? 1 : 0;
			env_value = realloc(env_value, p + (p ? 1 : 0) + strlen(ls->key) + 1 + strlen(fd) + socket_set_buf + 1);

			if (i % FPM_ENV_SOCKET_SET_SIZE == 0) {
				socket_set[socket_set_count] = p + socket_set_buf;
				socket_set_count++;
				if (i) {
					*(env_value + p + 1) = 0;
				}
			}

			p += sprintf(env_value + p + socket_set_buf, "%s%s=%s", (p && !socket_set_buf) ? "," : "", ls->key, fd);
			p += socket_set_buf;
		}

		if (which == FPM_CLEANUP_PARENT_EXIT_MAIN) {
			if (ls->type == FPM_AF_UNIX) {
				unlink(ls->key);
			}
		}
		free(ls->key);
	}

	if (env_value) {
		for (i = 0; i < socket_set_count; i++) {
			if (!i) {
				strcpy(envname, "FPM_SOCKETS");
			} else {
				sprintf(envname, "FPM_SOCKETS_%d", i);
			}
			setenv(envname, env_value + socket_set[i], 1);
		}
		free(env_value);
	}

	fpm_array_free(&sockets_list);
}
static void fpm_worker_pool_cleanup(int which, void *arg) /* {{{ */
{
    struct fpm_worker_pool_s *wp, *wp_next;

    for (wp = fpm_worker_all_pools; wp; wp = wp_next) {
        wp_next = wp->next;
        fpm_worker_pool_config_free(wp->config);
        fpm_children_free(wp->children);
        fpm_array_free(&wp->slots_used);
        fpm_array_free(&wp->slots_free);
        fpm_shm_free_list(wp->shm_list, which == FPM_CLEANUP_CHILD ? fpm_shm_slots_mem() : 0);
        if (wp->shm_status && which != FPM_CLEANUP_CHILD) {
            fpm_shm_free(wp->shm_status, !fpm_globals.is_child);
        }
        free(wp->config);
        free(wp->user);
        free(wp->home);
        free(wp);
    }
    fpm_worker_all_pools = 0;
}