comparison src/os/unix/ngx_process_cycle.c @ 7802:0215ec9aaa8a

Removed "ch" argument from ngx_pass_open_channel().
author Ruslan Ermilov <ru@nginx.com>
date Thu, 11 Mar 2021 09:58:45 +0300
parents 7cbf6389194b
children f2ff291bbdac
comparison
equal deleted inserted replaced
7801:777373b5a169 7802:0215ec9aaa8a
13 13
14 static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, 14 static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
15 ngx_int_t type); 15 ngx_int_t type);
16 static void ngx_start_cache_manager_processes(ngx_cycle_t *cycle, 16 static void ngx_start_cache_manager_processes(ngx_cycle_t *cycle,
17 ngx_uint_t respawn); 17 ngx_uint_t respawn);
18 static void ngx_pass_open_channel(ngx_cycle_t *cycle, ngx_channel_t *ch); 18 static void ngx_pass_open_channel(ngx_cycle_t *cycle);
19 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo); 19 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo);
20 static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle); 20 static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle);
21 static void ngx_master_process_exit(ngx_cycle_t *cycle); 21 static void ngx_master_process_exit(ngx_cycle_t *cycle);
22 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); 22 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
23 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker); 23 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker);
333 333
334 334
335 static void 335 static void
336 ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type) 336 ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type)
337 { 337 {
338 ngx_int_t i; 338 ngx_int_t i;
339 ngx_channel_t ch;
340 339
341 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start worker processes"); 340 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start worker processes");
342
343 ngx_memzero(&ch, sizeof(ngx_channel_t));
344
345 ch.command = NGX_CMD_OPEN_CHANNEL;
346 341
347 for (i = 0; i < n; i++) { 342 for (i = 0; i < n; i++) {
348 343
349 ngx_spawn_process(cycle, ngx_worker_process_cycle, 344 ngx_spawn_process(cycle, ngx_worker_process_cycle,
350 (void *) (intptr_t) i, "worker process", type); 345 (void *) (intptr_t) i, "worker process", type);
351 346
352 ch.pid = ngx_processes[ngx_process_slot].pid; 347 ngx_pass_open_channel(cycle);
353 ch.slot = ngx_process_slot;
354 ch.fd = ngx_processes[ngx_process_slot].channel[0];
355
356 ngx_pass_open_channel(cycle, &ch);
357 } 348 }
358 } 349 }
359 350
360 351
361 static void 352 static void
362 ngx_start_cache_manager_processes(ngx_cycle_t *cycle, ngx_uint_t respawn) 353 ngx_start_cache_manager_processes(ngx_cycle_t *cycle, ngx_uint_t respawn)
363 { 354 {
364 ngx_uint_t i, manager, loader; 355 ngx_uint_t i, manager, loader;
365 ngx_path_t **path; 356 ngx_path_t **path;
366 ngx_channel_t ch;
367 357
368 manager = 0; 358 manager = 0;
369 loader = 0; 359 loader = 0;
370 360
371 path = ngx_cycle->paths.elts; 361 path = ngx_cycle->paths.elts;
386 376
387 ngx_spawn_process(cycle, ngx_cache_manager_process_cycle, 377 ngx_spawn_process(cycle, ngx_cache_manager_process_cycle,
388 &ngx_cache_manager_ctx, "cache manager process", 378 &ngx_cache_manager_ctx, "cache manager process",
389 respawn ? NGX_PROCESS_JUST_RESPAWN : NGX_PROCESS_RESPAWN); 379 respawn ? NGX_PROCESS_JUST_RESPAWN : NGX_PROCESS_RESPAWN);
390 380
391 ngx_memzero(&ch, sizeof(ngx_channel_t)); 381 ngx_pass_open_channel(cycle);
382
383 if (loader == 0) {
384 return;
385 }
386
387 ngx_spawn_process(cycle, ngx_cache_manager_process_cycle,
388 &ngx_cache_loader_ctx, "cache loader process",
389 respawn ? NGX_PROCESS_JUST_SPAWN : NGX_PROCESS_NORESPAWN);
390
391 ngx_pass_open_channel(cycle);
392 }
393
394
395 static void
396 ngx_pass_open_channel(ngx_cycle_t *cycle)
397 {
398 ngx_int_t i;
399 ngx_channel_t ch;
392 400
393 ch.command = NGX_CMD_OPEN_CHANNEL; 401 ch.command = NGX_CMD_OPEN_CHANNEL;
394 ch.pid = ngx_processes[ngx_process_slot].pid; 402 ch.pid = ngx_processes[ngx_process_slot].pid;
395 ch.slot = ngx_process_slot; 403 ch.slot = ngx_process_slot;
396 ch.fd = ngx_processes[ngx_process_slot].channel[0]; 404 ch.fd = ngx_processes[ngx_process_slot].channel[0];
397
398 ngx_pass_open_channel(cycle, &ch);
399
400 if (loader == 0) {
401 return;
402 }
403
404 ngx_spawn_process(cycle, ngx_cache_manager_process_cycle,
405 &ngx_cache_loader_ctx, "cache loader process",
406 respawn ? NGX_PROCESS_JUST_SPAWN : NGX_PROCESS_NORESPAWN);
407
408 ch.command = NGX_CMD_OPEN_CHANNEL;
409 ch.pid = ngx_processes[ngx_process_slot].pid;
410 ch.slot = ngx_process_slot;
411 ch.fd = ngx_processes[ngx_process_slot].channel[0];
412
413 ngx_pass_open_channel(cycle, &ch);
414 }
415
416
417 static void
418 ngx_pass_open_channel(ngx_cycle_t *cycle, ngx_channel_t *ch)
419 {
420 ngx_int_t i;
421 405
422 for (i = 0; i < ngx_last_process; i++) { 406 for (i = 0; i < ngx_last_process; i++) {
423 407
424 if (i == ngx_process_slot 408 if (i == ngx_process_slot
425 || ngx_processes[i].pid == -1 409 || ngx_processes[i].pid == -1
428 continue; 412 continue;
429 } 413 }
430 414
431 ngx_log_debug6(NGX_LOG_DEBUG_CORE, cycle->log, 0, 415 ngx_log_debug6(NGX_LOG_DEBUG_CORE, cycle->log, 0,
432 "pass channel s:%i pid:%P fd:%d to s:%i pid:%P fd:%d", 416 "pass channel s:%i pid:%P fd:%d to s:%i pid:%P fd:%d",
433 ch->slot, ch->pid, ch->fd, 417 ch.slot, ch.pid, ch.fd,
434 i, ngx_processes[i].pid, 418 i, ngx_processes[i].pid,
435 ngx_processes[i].channel[0]); 419 ngx_processes[i].channel[0]);
436 420
437 /* TODO: NGX_AGAIN */ 421 /* TODO: NGX_AGAIN */
438 422
439 ngx_write_channel(ngx_processes[i].channel[0], 423 ngx_write_channel(ngx_processes[i].channel[0],
440 ch, sizeof(ngx_channel_t), cycle->log); 424 &ch, sizeof(ngx_channel_t), cycle->log);
441 } 425 }
442 } 426 }
443 427
444 428
445 static void 429 static void
619 ngx_processes[i].name); 603 ngx_processes[i].name);
620 continue; 604 continue;
621 } 605 }
622 606
623 607
624 ch.command = NGX_CMD_OPEN_CHANNEL; 608 ngx_pass_open_channel(cycle);
625 ch.pid = ngx_processes[ngx_process_slot].pid;
626 ch.slot = ngx_process_slot;
627 ch.fd = ngx_processes[ngx_process_slot].channel[0];
628
629 ngx_pass_open_channel(cycle, &ch);
630 609
631 live = 1; 610 live = 1;
632 611
633 continue; 612 continue;
634 } 613 }