Skip to content

Commit ce0a5e9

Browse files
committed
spread some more CS and folding love
1 parent c26b55a commit ce0a5e9

24 files changed

+475
-591
lines changed

sapi/fpm/fpm/fpm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
struct fpm_globals_s fpm_globals;
2525

26-
int fpm_init(int argc, char **argv, char *config)
26+
int fpm_init(int argc, char **argv, char *config) /* {{{ */
2727
{
2828
fpm_globals.argc = argc;
2929
fpm_globals.argv = argv;
@@ -51,10 +51,11 @@ int fpm_init(int argc, char **argv, char *config)
5151

5252
return 0;
5353
}
54+
/* }}} */
5455

5556
/* children: return listening socket
5657
parent: never return */
57-
int fpm_run(int *max_requests)
58+
int fpm_run(int *max_requests) /* {{{ */
5859
{
5960
struct fpm_worker_pool_s *wp;
6061

@@ -79,4 +80,5 @@ int fpm_run(int *max_requests)
7980
*max_requests = fpm_globals.max_requests;
8081
return fpm_globals.listening_socket;
8182
}
83+
/* }}} */
8284

sapi/fpm/fpm/fpm_children.c

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,34 @@ static int fault;
3434

3535
static int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop);
3636

37-
static void fpm_children_cleanup(int which, void *arg)
37+
static void fpm_children_cleanup(int which, void *arg) /* {{{ */
3838
{
3939
free(last_faults);
4040
}
41+
/* }}} */
4142

42-
static struct fpm_child_s *fpm_child_alloc()
43+
static struct fpm_child_s *fpm_child_alloc() /* {{{ */
4344
{
4445
struct fpm_child_s *ret;
4546

4647
ret = malloc(sizeof(struct fpm_child_s));
4748

48-
if (!ret) return 0;
49+
if (!ret) {
50+
return 0;
51+
}
4952

5053
memset(ret, 0, sizeof(*ret));
51-
5254
return ret;
5355
}
56+
/* }}} */
5457

55-
static void fpm_child_free(struct fpm_child_s *child)
58+
static void fpm_child_free(struct fpm_child_s *child) /* {{{ */
5659
{
5760
free(child);
5861
}
62+
/* }}} */
5963

60-
static void fpm_child_close(struct fpm_child_s *child, int in_event_loop)
64+
static void fpm_child_close(struct fpm_child_s *child, int in_event_loop) /* {{{ */
6165
{
6266
if (child->fd_stdout != -1) {
6367
if (in_event_loop) {
@@ -79,32 +83,42 @@ static void fpm_child_close(struct fpm_child_s *child, int in_event_loop)
7983

8084
fpm_child_free(child);
8185
}
86+
/* }}} */
8287

83-
static void fpm_child_link(struct fpm_child_s *child)
88+
static void fpm_child_link(struct fpm_child_s *child) /* {{{ */
8489
{
8590
struct fpm_worker_pool_s *wp = child->wp;
8691

8792
++wp->running_children;
8893
++fpm_globals.running_children;
8994

9095
child->next = wp->children;
91-
if (child->next) child->next->prev = child;
96+
if (child->next) {
97+
child->next->prev = child;
98+
}
9299
child->prev = 0;
93100
wp->children = child;
94101
}
102+
/* }}} */
95103

96-
static void fpm_child_unlink(struct fpm_child_s *child)
104+
static void fpm_child_unlink(struct fpm_child_s *child) /* {{{ */
97105
{
98106
--child->wp->running_children;
99107
--fpm_globals.running_children;
100108

101-
if (child->prev) child->prev->next = child->next;
102-
else child->wp->children = child->next;
103-
if (child->next) child->next->prev = child->prev;
109+
if (child->prev) {
110+
child->prev->next = child->next;
111+
} else {
112+
child->wp->children = child->next;
113+
}
104114

115+
if (child->next) {
116+
child->next->prev = child->prev;
117+
}
105118
}
119+
/* }}} */
106120

107-
static struct fpm_child_s *fpm_child_find(pid_t pid)
121+
static struct fpm_child_s *fpm_child_find(pid_t pid) /* {{{ */
108122
{
109123
struct fpm_worker_pool_s *wp;
110124
struct fpm_child_s *child = 0;
@@ -126,8 +140,9 @@ static struct fpm_child_s *fpm_child_find(pid_t pid)
126140

127141
return child;
128142
}
143+
/* }}} */
129144

130-
static void fpm_child_init(struct fpm_worker_pool_s *wp)
145+
static void fpm_child_init(struct fpm_worker_pool_s *wp) /* {{{ */
131146
{
132147
fpm_globals.max_requests = wp->config->max_requests;
133148

@@ -141,8 +156,9 @@ static void fpm_child_init(struct fpm_worker_pool_s *wp)
141156
exit(255);
142157
}
143158
}
159+
/* }}} */
144160

145-
int fpm_children_free(struct fpm_child_s *child)
161+
int fpm_children_free(struct fpm_child_s *child) /* {{{ */
146162
{
147163
struct fpm_child_s *next;
148164

@@ -153,8 +169,9 @@ int fpm_children_free(struct fpm_child_s *child)
153169

154170
return 0;
155171
}
172+
/* }}} */
156173

157-
void fpm_children_bury()
174+
void fpm_children_bury() /* {{{ */
158175
{
159176
int status;
160177
pid_t pid;
@@ -174,8 +191,7 @@ void fpm_children_bury()
174191
severity = ZLOG_WARNING;
175192
}
176193

177-
}
178-
else if (WIFSIGNALED(status)) {
194+
} else if (WIFSIGNALED(status)) {
179195
const char *signame = fpm_signal_names[WTERMSIG(status)];
180196
const char *have_core = WCOREDUMP(status) ? " (core dumped)" : "";
181197

@@ -188,8 +204,7 @@ void fpm_children_bury()
188204
if (WTERMSIG(status) != SIGQUIT) { /* possible request loss */
189205
severity = ZLOG_WARNING;
190206
}
191-
}
192-
else if (WIFSTOPPED(status)) {
207+
} else if (WIFSTOPPED(status)) {
193208

194209
zlog(ZLOG_STUFF, ZLOG_NOTICE, "child %d stopped for tracing", (int) pid);
195210

@@ -251,15 +266,14 @@ void fpm_children_bury()
251266
if (fpm_globals.is_child) {
252267
break;
253268
}
254-
}
255-
else {
269+
} else {
256270
zlog(ZLOG_STUFF, ZLOG_ALERT, "oops, unknown child exited %s", buf);
257271
}
258272
}
259-
260273
}
274+
/* }}} */
261275

262-
static struct fpm_child_s *fpm_resources_prepare(struct fpm_worker_pool_s *wp)
276+
static struct fpm_child_s *fpm_resources_prepare(struct fpm_worker_pool_s *wp) /* {{{ */
263277
{
264278
struct fpm_child_s *c;
265279

@@ -286,29 +300,33 @@ static struct fpm_child_s *fpm_resources_prepare(struct fpm_worker_pool_s *wp)
286300

287301
return c;
288302
}
303+
/* }}} */
289304

290-
static void fpm_resources_discard(struct fpm_child_s *child)
305+
static void fpm_resources_discard(struct fpm_child_s *child) /* {{{ */
291306
{
292307
fpm_shm_slots_discard_slot(child);
293308
fpm_stdio_discard_pipes(child);
294309
fpm_child_free(child);
295310
}
311+
/* }}} */
296312

297-
static void fpm_child_resources_use(struct fpm_child_s *child)
313+
static void fpm_child_resources_use(struct fpm_child_s *child) /* {{{ */
298314
{
299315
fpm_shm_slots_child_use_slot(child);
300316
fpm_stdio_child_use_pipes(child);
301317
fpm_child_free(child);
302318
}
319+
/* }}} */
303320

304-
static void fpm_parent_resources_use(struct fpm_child_s *child)
321+
static void fpm_parent_resources_use(struct fpm_child_s *child) /* {{{ */
305322
{
306323
fpm_shm_slots_parent_use_slot(child);
307324
fpm_stdio_parent_use_pipes(child);
308325
fpm_child_link(child);
309326
}
327+
/* }}} */
310328

311-
static int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop)
329+
static int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop) /* {{{ */
312330
{
313331
int enough = 0;
314332
pid_t pid;
@@ -356,13 +374,15 @@ static int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop)
356374

357375
return 1; /* we are done */
358376
}
377+
/* }}} */
359378

360-
int fpm_children_create_initial(struct fpm_worker_pool_s *wp)
379+
int fpm_children_create_initial(struct fpm_worker_pool_s *wp) /* {{{ */
361380
{
362381
return fpm_children_make(wp, 0 /* not in event loop yet */);
363382
}
383+
/* }}} */
364384

365-
int fpm_children_init_main()
385+
int fpm_children_init_main() /* {{{ */
366386
{
367387
if (fpm_global_config.emergency_restart_threshold &&
368388
fpm_global_config.emergency_restart_interval) {
@@ -382,4 +402,5 @@ int fpm_children_init_main()
382402

383403
return 0;
384404
}
405+
/* }}} */
385406

sapi/fpm/fpm/fpm_cleanup.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct cleanup_s {
1818

1919
static struct fpm_array_s cleanups = { .sz = sizeof(struct cleanup_s) };
2020

21-
int fpm_cleanup_add(int type, void (*cleanup)(int, void *), void *arg)
21+
int fpm_cleanup_add(int type, void (*cleanup)(int, void *), void *arg) /* {{{ */
2222
{
2323
struct cleanup_s *c;
2424

@@ -34,8 +34,9 @@ int fpm_cleanup_add(int type, void (*cleanup)(int, void *), void *arg)
3434

3535
return 0;
3636
}
37+
/* }}} */
3738

38-
void fpm_cleanups_run(int type)
39+
void fpm_cleanups_run(int type) /* {{{ */
3940
{
4041
struct cleanup_s *c = fpm_array_item_last(&cleanups);
4142
int cl = cleanups.used;
@@ -48,4 +49,5 @@ void fpm_cleanups_run(int type)
4849

4950
fpm_array_free(&cleanups);
5051
}
52+
/* }}} */
5153

sapi/fpm/fpm/fpm_clock.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
static int monotonic_works;
1919

20-
int fpm_clock_init()
20+
int fpm_clock_init() /* {{{ */
2121
{
2222
struct timespec ts;
2323

@@ -29,8 +29,9 @@ int fpm_clock_init()
2929

3030
return 0;
3131
}
32+
/* }}} */
3233

33-
int fpm_clock_get(struct timeval *tv)
34+
int fpm_clock_get(struct timeval *tv) /* {{{ */
3435
{
3536
if (monotonic_works) {
3637
struct timespec ts;
@@ -47,6 +48,7 @@ int fpm_clock_get(struct timeval *tv)
4748

4849
return gettimeofday(tv, 0);
4950
}
51+
/* }}} */
5052

5153
/* macosx clock */
5254
#elif defined(HAVE_CLOCK_GET_TIME)
@@ -59,7 +61,7 @@ static clock_serv_t mach_clock;
5961

6062
/* this code borrowed from here: http://lists.apple.com/archives/Darwin-development/2002/Mar/msg00746.html */
6163
/* mach_clock also should be re-initialized in child process after fork */
62-
int fpm_clock_init()
64+
int fpm_clock_init() /* {{{ */
6365
{
6466
kern_return_t ret;
6567
mach_timespec_t aTime;
@@ -81,8 +83,9 @@ int fpm_clock_init()
8183

8284
return 0;
8385
}
86+
/* }}} */
8487

85-
int fpm_clock_get(struct timeval *tv)
88+
int fpm_clock_get(struct timeval *tv) /* {{{ */
8689
{
8790
kern_return_t ret;
8891
mach_timespec_t aTime;
@@ -99,17 +102,20 @@ int fpm_clock_get(struct timeval *tv)
99102

100103
return 0;
101104
}
105+
/* }}} */
102106

103107
#else /* no clock */
104108

105-
int fpm_clock_init()
109+
int fpm_clock_init() /* {{{ */
106110
{
107111
return 0;
108112
}
113+
/* }}} */
109114

110-
int fpm_clock_get(struct timeval *tv)
115+
int fpm_clock_get(struct timeval *tv) /* {{{ */
111116
{
112117
return gettimeofday(tv, 0);
113118
}
119+
/* }}} */
114120

115121
#endif

0 commit comments

Comments
 (0)