xref: /PHP-5.6/sapi/fpm/fpm/fpm_worker_pool.c (revision 744ada7d)
1 
2 	/* $Id: fpm_worker_pool.c,v 1.15.2.1 2008/12/13 03:21:18 anight Exp $ */
3 	/* (c) 2007,2008 Andrei Nigmatulin */
4 
5 #include "fpm_config.h"
6 
7 #include <string.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 
11 #include "fpm.h"
12 #include "fpm_worker_pool.h"
13 #include "fpm_cleanup.h"
14 #include "fpm_children.h"
15 #include "fpm_shm.h"
16 #include "fpm_scoreboard.h"
17 #include "fpm_conf.h"
18 #include "fpm_unix.h"
19 
20 struct fpm_worker_pool_s *fpm_worker_all_pools;
21 
fpm_worker_pool_free(struct fpm_worker_pool_s * wp)22 void fpm_worker_pool_free(struct fpm_worker_pool_s *wp) /* {{{ */
23 {
24 	if (wp->config) {
25 		free(wp->config);
26 	}
27 	if (wp->user) {
28 		free(wp->user);
29 	}
30 	if (wp->home) {
31 		free(wp->home);
32 	}
33 	fpm_unix_free_socket_premissions(wp);
34 	free(wp);
35 }
36 /* }}} */
37 
fpm_worker_pool_cleanup(int which,void * arg)38 static void fpm_worker_pool_cleanup(int which, void *arg) /* {{{ */
39 {
40 	struct fpm_worker_pool_s *wp, *wp_next;
41 
42 	for (wp = fpm_worker_all_pools; wp; wp = wp_next) {
43 		wp_next = wp->next;
44 		fpm_worker_pool_config_free(wp->config);
45 		fpm_children_free(wp->children);
46 		if ((which & FPM_CLEANUP_CHILD) == 0 && fpm_globals.parent_pid == getpid()) {
47 			fpm_scoreboard_free(wp->scoreboard);
48 		}
49 		fpm_worker_pool_free(wp);
50 	}
51 	fpm_worker_all_pools = NULL;
52 }
53 /* }}} */
54 
fpm_worker_pool_alloc()55 struct fpm_worker_pool_s *fpm_worker_pool_alloc() /* {{{ */
56 {
57 	struct fpm_worker_pool_s *ret;
58 
59 	ret = malloc(sizeof(struct fpm_worker_pool_s));
60 	if (!ret) {
61 		return 0;
62 	}
63 
64 	memset(ret, 0, sizeof(struct fpm_worker_pool_s));
65 
66 	ret->idle_spawn_rate = 1;
67 	ret->log_fd = -1;
68 	return ret;
69 }
70 /* }}} */
71 
fpm_worker_pool_init_main()72 int fpm_worker_pool_init_main() /* {{{ */
73 {
74 	if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_worker_pool_cleanup, 0)) {
75 		return -1;
76 	}
77 	return 0;
78 }
79 /* }}} */
80