xref: /PHP-5.4/sapi/fpm/fpm/fpm_worker_pool.c (revision 331540d2)
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 
19 struct fpm_worker_pool_s *fpm_worker_all_pools;
20 
fpm_worker_pool_free(struct fpm_worker_pool_s * wp)21 void fpm_worker_pool_free(struct fpm_worker_pool_s *wp) /* {{{ */
22 {
23 	if (wp->config) {
24 		free(wp->config);
25 	}
26 	if (wp->user) {
27 		free(wp->user);
28 	}
29 	if (wp->home) {
30 		free(wp->home);
31 	}
32 	free(wp);
33 }
34 /* }}} */
35 
fpm_worker_pool_cleanup(int which,void * arg)36 static void fpm_worker_pool_cleanup(int which, void *arg) /* {{{ */
37 {
38 	struct fpm_worker_pool_s *wp, *wp_next;
39 
40 	for (wp = fpm_worker_all_pools; wp; wp = wp_next) {
41 		wp_next = wp->next;
42 		fpm_worker_pool_config_free(wp->config);
43 		fpm_children_free(wp->children);
44 		if ((which & FPM_CLEANUP_CHILD) == 0 && fpm_globals.parent_pid == getpid()) {
45 			fpm_scoreboard_free(wp->scoreboard);
46 		}
47 		fpm_worker_pool_free(wp);
48 	}
49 	fpm_worker_all_pools = NULL;
50 }
51 /* }}} */
52 
fpm_worker_pool_alloc()53 struct fpm_worker_pool_s *fpm_worker_pool_alloc() /* {{{ */
54 {
55 	struct fpm_worker_pool_s *ret;
56 
57 	ret = malloc(sizeof(struct fpm_worker_pool_s));
58 	if (!ret) {
59 		return 0;
60 	}
61 
62 	memset(ret, 0, sizeof(struct fpm_worker_pool_s));
63 
64 	ret->idle_spawn_rate = 1;
65 	ret->log_fd = -1;
66 	return ret;
67 }
68 /* }}} */
69 
fpm_worker_pool_init_main()70 int fpm_worker_pool_init_main() /* {{{ */
71 {
72 	if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_worker_pool_cleanup, 0)) {
73 		return -1;
74 	}
75 	return 0;
76 }
77 /* }}} */
78