8
8
#include <errno.h>
9
9
#include <stdlib.h> /* for putenv */
10
10
#include <string.h>
11
- #include <sys/types.h> /* for event.h below */
12
- #include <event.h>
13
11
14
12
#include "fpm.h"
15
13
#include "fpm_process_ctl.h"
22
20
23
21
static void fpm_event_cleanup (int which , void * arg ) /* {{{ */
24
22
{
25
- event_base_free (0 );
23
+ struct event_base * base = (struct event_base * )arg ;
24
+ event_base_free (base );
26
25
}
27
26
/* }}} */
28
27
29
28
static void fpm_got_signal (int fd , short ev , void * arg ) /* {{{ */
30
29
{
31
30
char c ;
32
31
int res ;
32
+ struct event_base * base = (struct event_base * )arg ;
33
33
34
34
do {
35
35
do {
@@ -46,22 +46,22 @@ static void fpm_got_signal(int fd, short ev, void *arg) /* {{{ */
46
46
switch (c ) {
47
47
case 'C' : /* SIGCHLD */
48
48
zlog (ZLOG_STUFF , ZLOG_DEBUG , "received SIGCHLD" );
49
- fpm_children_bury ();
49
+ fpm_children_bury (base );
50
50
break ;
51
51
case 'I' : /* SIGINT */
52
52
zlog (ZLOG_STUFF , ZLOG_DEBUG , "received SIGINT" );
53
53
zlog (ZLOG_STUFF , ZLOG_NOTICE , "Terminating ..." );
54
- fpm_pctl (FPM_PCTL_STATE_TERMINATING , FPM_PCTL_ACTION_SET );
54
+ fpm_pctl (FPM_PCTL_STATE_TERMINATING , FPM_PCTL_ACTION_SET , base );
55
55
break ;
56
56
case 'T' : /* SIGTERM */
57
57
zlog (ZLOG_STUFF , ZLOG_DEBUG , "received SIGTERM" );
58
58
zlog (ZLOG_STUFF , ZLOG_NOTICE , "Terminating ..." );
59
- fpm_pctl (FPM_PCTL_STATE_TERMINATING , FPM_PCTL_ACTION_SET );
59
+ fpm_pctl (FPM_PCTL_STATE_TERMINATING , FPM_PCTL_ACTION_SET , base );
60
60
break ;
61
61
case 'Q' : /* SIGQUIT */
62
62
zlog (ZLOG_STUFF , ZLOG_DEBUG , "received SIGQUIT" );
63
63
zlog (ZLOG_STUFF , ZLOG_NOTICE , "Finishing ..." );
64
- fpm_pctl (FPM_PCTL_STATE_FINISHING , FPM_PCTL_ACTION_SET );
64
+ fpm_pctl (FPM_PCTL_STATE_FINISHING , FPM_PCTL_ACTION_SET , base );
65
65
break ;
66
66
case '1' : /* SIGUSR1 */
67
67
zlog (ZLOG_STUFF , ZLOG_DEBUG , "received SIGUSR1" );
@@ -74,7 +74,7 @@ static void fpm_got_signal(int fd, short ev, void *arg) /* {{{ */
74
74
case '2' : /* SIGUSR2 */
75
75
zlog (ZLOG_STUFF , ZLOG_DEBUG , "received SIGUSR2" );
76
76
zlog (ZLOG_STUFF , ZLOG_NOTICE , "Reloading in progress ..." );
77
- fpm_pctl (FPM_PCTL_STATE_RELOADING , FPM_PCTL_ACTION_SET );
77
+ fpm_pctl (FPM_PCTL_STATE_RELOADING , FPM_PCTL_ACTION_SET , base );
78
78
break ;
79
79
}
80
80
@@ -86,36 +86,38 @@ static void fpm_got_signal(int fd, short ev, void *arg) /* {{{ */
86
86
}
87
87
/* }}} */
88
88
89
- int fpm_event_init_main () /* {{{ */
89
+ int fpm_event_init_main (struct event_base * * base ) /* {{{ */
90
90
{
91
- event_init ();
91
+ * base = event_base_new ();
92
92
93
- zlog (ZLOG_STUFF , ZLOG_NOTICE , "libevent: using %s" , event_get_method ( ));
93
+ zlog (ZLOG_STUFF , ZLOG_NOTICE , "libevent: using %s" , event_base_get_method ( * base ));
94
94
95
- if (0 > fpm_cleanup_add (FPM_CLEANUP_ALL , fpm_event_cleanup , 0 )) {
95
+ if (0 > fpm_cleanup_add (FPM_CLEANUP_ALL , fpm_event_cleanup , * base )) {
96
96
return -1 ;
97
97
}
98
98
return 0 ;
99
99
}
100
100
/* }}} */
101
101
102
- int fpm_event_loop () /* {{{ */
102
+ int fpm_event_loop (struct event_base * base ) /* {{{ */
103
103
{
104
104
static struct event signal_fd_event ;
105
105
106
- event_set (& signal_fd_event , fpm_signals_get_fd (), EV_PERSIST | EV_READ , & fpm_got_signal , 0 );
106
+ event_set (& signal_fd_event , fpm_signals_get_fd (), EV_PERSIST | EV_READ , & fpm_got_signal , base );
107
+ event_base_set (base , & signal_fd_event );
107
108
event_add (& signal_fd_event , 0 );
108
- fpm_pctl_heartbeat (-1 , 0 , 0 );
109
- fpm_pctl_perform_idle_server_maintenance_heartbeat (-1 , 0 , 0 );
109
+ fpm_pctl_heartbeat (-1 , 0 , base );
110
+ fpm_pctl_perform_idle_server_maintenance_heartbeat (-1 , 0 , base );
110
111
zlog (ZLOG_STUFF , ZLOG_NOTICE , "ready to handle connections" );
111
- event_loop ( 0 );
112
+ event_base_dispatch ( base );
112
113
return 0 ;
113
114
}
114
115
/* }}} */
115
116
116
- int fpm_event_add (int fd , struct event * ev , void (* callback )(int , short , void * ), void * arg ) /* {{{ */
117
+ int fpm_event_add (int fd , struct event_base * base , struct event * ev , void (* callback )(int , short , void * ), void * arg ) /* {{{ */
117
118
{
118
119
event_set (ev , fd , EV_PERSIST | EV_READ , callback , arg );
120
+ event_base_set (base , ev );
119
121
return event_add (ev , 0 );
120
122
}
121
123
/* }}} */
@@ -126,9 +128,9 @@ int fpm_event_del(struct event *ev) /* {{{ */
126
128
}
127
129
/* }}} */
128
130
129
- void fpm_event_exit_loop () /* {{{ */
131
+ void fpm_event_exit_loop (struct event_base * base ) /* {{{ */
130
132
{
131
- event_loopbreak ( );
133
+ event_base_loopbreak ( base );
132
134
}
133
135
/* }}} */
134
136
0 commit comments