{ ... ... case 6: ngx_cacheline_size = 32; model = ((cpu[0] & 0xf0000) >> 8) | (cpu[0] & 0xf0); if (model >= 0xd0) { / * I n t e l C o r e , C o r e 2 , A t o m * / ngx_cacheline_size = 64; } break; ...
/ * v o i d * ( * c r e a t e _ c o n f ) ( n g x _ c y c l e _ t * c y c l e ) ; * / ngx_core_module_init_conf / * c h a r * ( * i n i t _ c o n f ) ( n g x _ c y c l e _ t * c y c l e , v o i d * c o n f ) ; * / }; ngx_module_t ngx_core_module = { NGX_MODULE_V1, &ngx_core_module_ctx, / * m o d u l e c o n t e x t * / ngx_core_commands, / * m o d u l e d i r e c t i v e s * / NGX_CORE_MODULE, / * m o d u l e t y p e * / NULL, / * i n i t m a s t e r * / NULL, / * i n i t m o d u l e * / NULL, / * i n i t p r o c e s s * / NULL, / * i n i t t h r e a d * / NULL, / * e x i t t h r e a d * / NULL, / * e x i t p r o c e s s * / NULL, / * e x i t m a s t e r * / NGX_MODULE_V1_PADDING };
if (ngx_modules[i]->init_module) { if (ngx_modules[i]->init_module(cycle) != NGX_OK) { / * f a t a l * / exit(1); } } } ngx_event_module_init ngx_regex_module_init ngx_http_spdy_module_init
= waitpid(-1, &status, WNOHANG); ... / * p i d から終了プロセスをe x i t e d へ設定 * / for (i = 0; i < ngx_last_process; i++) { if (ngx_processes[i].pid == pid) { ngx_processes[i].status = status; ngx_processes[i].exited = 1; process = ngx_processes[i].name; break; } } ...
o r k e r _ p r o c e s s e s * / for (i = 0; i < n; i++) { ngx_spawn_process(cycle, ngx_worker_process_cycle, (void *) (intptr_t) i, "worker process", type); / * f o r k ( ) した子プロセスの情報を保存 * / ch.pid = ngx_processes[ngx_process_slot].pid; ch.slot = ngx_process_slot; ch.fd = ngx_processes[ngx_process_slot].channel[0]; ngx_pass_open_channel(cycle, &ch); }
backtraceスはこんな感じ #0 ngx_epoll_process_events (cycle=0x7457f0, timer=18446744073709551615, flags=1) at src/event/ #1 0x00000000004326b3 in ngx_process_events_and_timers (cycle=0x7457f0) at src/event/ngx_event. #2 0x000000000044007d in ngx_worker_process_cycle (cycle=0x7457f0, data=0x0) at src/os/unix/ngx #3 0x000000000043c6db in ngx_spawn_process (cycle=0x7457f0, proc=0x43fe5c <ngx_worker_process_c #4 0x000000000043ed3f in ngx_start_worker_processes (cycle=0x7457f0, n=1, type=-3) at src/os/un #5 0x000000000043e34d in ngx_master_process_cycle (cycle=0x7457f0) at src/os/unix/ngx_process_c #6 0x0000000000407e5d in main (argc=1, argv=0x7fffffffd868) at src/core/nginx.c:431
epoll_event ev; / * L i s t e n s o k e t 設定用* / struct epoll_event events[MAX_EVENTS]; / * e v e n t 発生取得用 * / sock = socket(PF_INET, SOCK_STREAM, 0) bind(sock, (struct sockaddr *) &sin, sizeof sin); listen(sock, BACKLOG); ev.events = EPOLLIN; ev.data.fd = sock; epoll_ctl(epfd, EPOLL_CTL_ADD, sock, &ev); 3. wait int nfd = epoll_wait(epfd, events, MAX_EVENTS, -1);
nfd; i++) { / * L i s t e n S o c k e t が起きた * / if (events[i].data.fd == sock) { / * s o c k はL i s t e n s o c k e t * / / * クライアントのs o k e t ファイルディスクリプタの取得 * / int client = accept(socket, (struct sockaddr *) &client_addr, &client_addr_len); / * クライアントのs o k e t をn o n b l o c k i n g へ * / int flag = fcntl(client, F_GETFL, 0); fcntl(client, F_SETFL, flag | O_NONBLOCK); / * k e r n e l へ読込可能、エッジトリガ形式で登録依頼 * / ev.events = EPOLLIN | EPOLLET; ev.data.fd = client; / * 登録 * / epoll_ctl(epfd, EPOLL_CTL_ADD, client, &ev); } else { / * 読込が可能なf d が既に入ってる * / int client = events[i].data.fd; int n = read(client, buffer, sizeof(buffer)); write(client, buffer, n); } } というような感じで動きます...コードはイメージです アハ
a s h TMP=$HOME/devbin/nginx/var/lib/nginx/tmp/ LOG=$HOME/devbin/nginx/logs/ make -j6 make install if [ -d $TMP ]; then echo "[ $TMP ] found" else echo "Create directory [ $TMP ]" mkdir -p $TMP fi if [ -d $LOG ]; then echo "[ $LOG ] found" else echo "Create directory [ $LOG ]" mkdir -p $LOG fi
set history filename ~/.gdb_history set print pretty on set print static-members off set charset UTF-8 set follow-fork-mode child set detach-on-fork off dir /home/cuomo/Code/nginx/ngx-1.8.0/src dir /home/cuomo/Code/nginx/ngx-1.8.0/src/event dir /home/cuomo/Code/nginx/ngx-1.8.0/src/event/modules ... set follow-fork-mode child fork()したら子プロセスに自動attach set detach-on-fork off fork()後親、子プロセスともに捕まえる
to search for commands related to "word"... Reading symbols from /home/cuomo/devbin/nginx/sbin/nginx...done. (gdb) b main Breakpoint 1 at 0x40791f: file src/core/nginx.c, line 203. (gdb) r Starting program: /home/cuomo/devbin/nginx/sbin/nginx [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Breakpoint 1, main (argc=1, argv=0x7fffffffd818) at src/core/nginx.c:203 203 { (gdb) できたか?!