Mercurial > hg > nginx-vendor-0-6
comparison src/os/unix/ngx_setproctitle.c @ 2:cc9f381affaa NGINX_0_1_1
nginx 0.1.1
*) Feature: the gzip_types directive.
*) Feature: the tcp_nodelay directive.
*) Feature: the send_lowat directive is working not only on OSes that
support kqueue NOTE_LOWAT, but also on OSes that support SO_SNDLOWAT.
*) Feature: the setproctitle() emulation for Linux and Solaris.
*) Bugfix: the "Location" header rewrite bug fixed while the proxying.
*) Bugfix: the ngx_http_chunked_module module may get caught in an
endless loop.
*) Bugfix: the /dev/poll module bugs fixed.
*) Bugfix: the responses were corrupted when the temporary files were
used while the proxying.
*) Bugfix: the unescaped requests were passed to the backend.
*) Bugfix: while the build configuration on Linux 2.4 the
--with-poll_module parameter was required.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 11 Oct 2004 00:00:00 +0400 |
parents | |
children | 4b2dafa26fe2 |
comparison
equal
deleted
inserted
replaced
1:80bdda0151b0 | 2:cc9f381affaa |
---|---|
1 | |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 | |
10 | |
11 #if (NGX_SETPROCTITLE_USES_ENV) | |
12 | |
13 /* | |
14 * To change the process title in Linux and Solaris we have to set argv[1] | |
15 * to NULL and to copy the title to the same place where the argv[0] points to. | |
16 * However, argv[0] may be too small to hold a new title. Fortunately, Linux | |
17 * and Solaris store argv[] and environ[] one after another. So we should | |
18 * ensure that is the continuous memory and then we allocate the new memory | |
19 * for environ[] and copy it. After this we could use the memory starting | |
20 * from argv[0] for our process title. | |
21 * | |
22 * The Solaris's standard /bin/ps does not show the changed process title. | |
23 * You have to use "/usr/ucb/ps -w" instead. Besides, the UCB ps dos not | |
24 * show a new title if its length less than the origin command line length. | |
25 * To avoid it we append to a new title the origin command line in the | |
26 * parenthesis. | |
27 */ | |
28 | |
29 extern char **environ; | |
30 | |
31 static char *ngx_os_argv_last; | |
32 | |
33 ngx_int_t ngx_init_setproctitle(ngx_log_t *log) | |
34 { | |
35 char *p; | |
36 size_t size; | |
37 ngx_uint_t i; | |
38 | |
39 size = 0; | |
40 | |
41 for (i = 0; environ[i]; i++) { | |
42 size += ngx_strlen(environ[i]) + 1; | |
43 } | |
44 | |
45 if (!(p = ngx_alloc(size, log))) { | |
46 return NGX_ERROR; | |
47 } | |
48 | |
49 ngx_os_argv_last = ngx_os_argv[0]; | |
50 | |
51 for (i = 0; ngx_os_argv[i]; i++) { | |
52 if (ngx_os_argv_last == ngx_os_argv[i]) { | |
53 ngx_os_argv_last = ngx_os_argv[i] + ngx_strlen(ngx_os_argv[i]) + 1; | |
54 } | |
55 } | |
56 | |
57 for (i = 0; environ[i]; i++) { | |
58 if (ngx_os_argv_last == environ[i]) { | |
59 | |
60 size = ngx_strlen(environ[i]) + 1; | |
61 ngx_os_argv_last = environ[i] + size; | |
62 | |
63 ngx_cpystrn(p, environ[i], size); | |
64 environ[i] = p; | |
65 p += size; | |
66 } | |
67 } | |
68 | |
69 ngx_os_argv_last--; | |
70 | |
71 return NGX_OK; | |
72 } | |
73 | |
74 | |
75 void ngx_setproctitle(char *title) | |
76 { | |
77 u_char *p; | |
78 | |
79 #if (SOLARIS) | |
80 | |
81 ngx_int_t i; | |
82 size_t size; | |
83 | |
84 #endif | |
85 | |
86 ngx_os_argv[1] = NULL; | |
87 | |
88 p = ngx_cpystrn((u_char *) ngx_os_argv[0], "nginx: ", | |
89 ngx_os_argv_last - ngx_os_argv[0]); | |
90 | |
91 p = ngx_cpystrn(p, (u_char *) title, ngx_os_argv_last - (char *) p); | |
92 | |
93 #if (SOLARIS) | |
94 | |
95 size = 0; | |
96 | |
97 for (i = 0; i < ngx_argc; i++) { | |
98 size += ngx_strlen(ngx_argv[i]) + 1; | |
99 } | |
100 | |
101 if (size > (size_t) ((char *) p - ngx_os_argv[0])) { | |
102 | |
103 /* | |
104 * ngx_setproctitle() is too rare operation so we use | |
105 * the non-optimized copies | |
106 */ | |
107 | |
108 p = ngx_cpystrn(p, (u_char *) " (", ngx_os_argv_last - (char *) p); | |
109 | |
110 for (i = 0; i < ngx_argc; i++) { | |
111 p = ngx_cpystrn(p, (u_char *) ngx_argv[i], | |
112 ngx_os_argv_last - (char *) p); | |
113 p = ngx_cpystrn(p, (u_char *) " ", ngx_os_argv_last - (char *) p); | |
114 } | |
115 | |
116 if (*(p - 1) == ' ') { | |
117 *(p - 1) = ')'; | |
118 } | |
119 } | |
120 | |
121 #endif | |
122 | |
123 if (ngx_os_argv_last - (char *) p) { | |
124 ngx_memset(p, NGX_SETPROCTITLE_PAD, ngx_os_argv_last - (char *) p); | |
125 } | |
126 | |
127 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, | |
128 "setproctitle: \"%s\"", ngx_os_argv[0]); | |
129 } | |
130 | |
131 | |
132 #elif !defined(ngx_setproctitle) | |
133 | |
134 ngx_int_t ngx_init_setproctitle(ngx_log_t *log) | |
135 { | |
136 return NGX_OK; | |
137 } | |
138 | |
139 void ngx_setproctitle(char *title) | |
140 { | |
141 } | |
142 | |
143 #endif |