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