|
5 | 5 | * to contain some useful information. Differs wildly across
|
6 | 6 | * platforms.
|
7 | 7 | *
|
8 |
| - * $Header: /cvsroot/pgsql/src/backend/utils/misc/ps_status.c,v 1.2 2000/07/09 13:14:11 petere Exp $ |
| 8 | + * $Header: /cvsroot/pgsql/src/backend/utils/misc/ps_status.c,v 1.3 2001/03/20 22:31:54 momjian Exp $ |
9 | 9 | *
|
10 | 10 | * Copyright 2000 by PostgreSQL Global Development Group
|
11 | 11 | * various details abducted from various places
|
@@ -44,7 +44,7 @@ extern char **environ;
|
44 | 44 | * PS_USE_PS_STRINGS
|
45 | 45 | * assign PS_STRINGS->ps_argvstr = "string"
|
46 | 46 | * (some BSD systems)
|
47 |
| - * PS_USE_CHANCE_ARGV |
| 47 | + * PS_USE_CHANGE_ARGV |
48 | 48 | * assign argv[0] = "string"
|
49 | 49 | * (some other BSD systems)
|
50 | 50 | * PS_USE_CLOBBER_ARGV
|
@@ -189,64 +189,68 @@ init_ps_display(int argc, char *argv[],
|
189 | 189 | void
|
190 | 190 | set_ps_display(const char * value)
|
191 | 191 | {
|
| 192 | +#ifndef PS_USE_NONE |
192 | 193 | /* no ps display for stand-alone backend */
|
193 | 194 | if (!IsUnderPostmaster)
|
194 | 195 | return;
|
195 | 196 |
|
196 |
| -#ifndef PS_USE_NONE |
| 197 | +# ifdef PS_USE_CLOBBER_ARGV |
| 198 | + /* If ps_buffer is a pointer, it might still be null */ |
197 | 199 | if (!ps_buffer)
|
198 | 200 | return;
|
199 |
| -# ifdef PS_USE_SETPROCTITLE |
200 |
| - setproctitle("%s%s", ps_buffer, value); |
| 201 | +# endif |
201 | 202 |
|
202 |
| -# else /* not PS_USE_SETPROCTITLE */ |
203 |
| - { |
204 |
| - size_t vallen = strlen(value); |
| 203 | + /* Update ps_buffer to contain both fixed part and value */ |
| 204 | + StrNCpy(ps_buffer + ps_buffer_fixed_size, value, |
| 205 | + ps_buffer_size - ps_buffer_fixed_size); |
205 | 206 |
|
206 |
| - strncpy(ps_buffer + ps_buffer_fixed_size, value, |
207 |
| - ps_buffer_size - ps_buffer_fixed_size); |
| 207 | + /* Transmit new setting to kernel, if necessary */ |
208 | 208 |
|
209 |
| - if (ps_buffer_fixed_size + vallen >= ps_buffer_size) |
210 |
| - ps_buffer[ps_buffer_size - 1] = 0; |
211 |
| - else |
212 |
| - ps_buffer[ps_buffer_fixed_size + vallen] = 0; |
| 209 | +# ifdef PS_USE_SETPROCTITLE |
| 210 | + setproctitle("%s", ps_buffer); |
| 211 | +# endif |
213 | 212 |
|
214 |
| -# ifdef PS_USE_PSTAT |
| 213 | +# ifdef PS_USE_PSTAT |
215 | 214 | {
|
216 | 215 | union pstun pst;
|
217 | 216 |
|
218 | 217 | pst.pst_command = ps_buffer;
|
219 | 218 | pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0);
|
220 | 219 | }
|
221 |
| -# endif /* PS_USE_PSTAT */ |
| 220 | +# endif /* PS_USE_PSTAT */ |
222 | 221 |
|
223 |
| -# ifdef PS_USE_PS_STRINGS |
| 222 | +# ifdef PS_USE_PS_STRINGS |
224 | 223 | PS_STRINGS->ps_nargvstr = 1;
|
225 | 224 | PS_STRINGS->ps_argvstr = ps_buffer;
|
226 |
| -# endif /* PS_USE_PS_STRINGS */ |
| 225 | +# endif /* PS_USE_PS_STRINGS */ |
227 | 226 |
|
228 |
| -# ifdef PS_USE_CLOBBER_ARGV |
| 227 | +# ifdef PS_USE_CLOBBER_ARGV |
229 | 228 | {
|
230 | 229 | char * cp;
|
231 | 230 | /* pad unused memory */
|
232 |
| - for(cp = ps_buffer + ps_buffer_fixed_size + vallen; |
| 231 | + for(cp = ps_buffer + strlen(ps_buffer); |
233 | 232 | cp < ps_buffer + ps_buffer_size;
|
234 | 233 | cp++)
|
235 | 234 | *cp = PS_PADDING;
|
236 | 235 | }
|
237 |
| -# endif /* PS_USE_CLOBBER_ARGV */ |
238 |
| - } |
239 |
| -# endif /* not USE_SETPROCTITLE */ |
| 236 | +# endif /* PS_USE_CLOBBER_ARGV */ |
| 237 | + |
240 | 238 | #endif /* not PS_USE_NONE */
|
241 | 239 | }
|
242 | 240 |
|
243 | 241 |
|
244 | 242 | /*
|
245 | 243 | * Returns what's currently in the ps display, in case someone needs
|
246 |
| - * it. |
| 244 | + * it. Note that only the variable part is returned. |
247 | 245 | */
|
248 | 246 | const char *
|
249 | 247 | get_ps_display(void)
|
250 | 248 | {
|
| 249 | +#ifdef PS_USE_CLOBBER_ARGV |
| 250 | + /* If ps_buffer is a pointer, it might still be null */ |
| 251 | + if (!ps_buffer) |
| 252 | + return ""; |
| 253 | +#endif |
| 254 | + |
251 | 255 | return ps_buffer + ps_buffer_fixed_size;
|
252 | 256 | }
|
0 commit comments