PostgreSQL Source Code git master
Loading...
Searching...
No Matches
ps_status.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DEFAULT_UPDATE_PROCESS_TITLE   true
 

Functions

char ** save_ps_display_args (int argc, char **argv)
 
void init_ps_display (const char *fixed_part)
 
void set_ps_display_suffix (const char *suffix)
 
void set_ps_display_remove_suffix (void)
 
void set_ps_display_with_len (const char *activity, size_t len)
 
static void set_ps_display (const char *activity)
 
const charget_ps_display (int *displen)
 

Variables

PGDLLIMPORT bool update_process_title
 

Macro Definition Documentation

◆ DEFAULT_UPDATE_PROCESS_TITLE

#define DEFAULT_UPDATE_PROCESS_TITLE   true

Definition at line 19 of file ps_status.h.

Function Documentation

◆ get_ps_display()

const char * get_ps_display ( int displen)
extern

Definition at line 549 of file ps_status.c.

550{
551#ifdef PS_USE_CLOBBER_ARGV
552 /* If ps_buffer is a pointer, it might still be null */
553 if (!ps_buffer)
554 {
555 *displen = 0;
556 return "";
557 }
558#endif
559
560#ifndef PS_USE_NONE
562
564#else
565 *displen = 0;
566 return "";
567#endif
568}
static int fb(int x)

References fb().

Referenced by log_status_format(), write_csvlog(), and write_jsonlog().

◆ init_ps_display()

void init_ps_display ( const char fixed_part)
extern

Definition at line 286 of file ps_status.c.

287{
288#ifndef PS_USE_NONE
290#endif
291
293 if (!fixed_part)
295
296#ifndef PS_USE_NONE
297 /* no ps display for stand-alone backend */
299 return;
300
301 /* no ps display if you didn't call save_ps_display_args() */
302 if (!save_argv)
303 return;
304
305#ifdef PS_USE_CLOBBER_ARGV
306 /* If ps_buffer is a pointer, it might still be null */
307 if (!ps_buffer)
308 return;
309
310 /* make extra argv slots point at end_of_area (a NUL) */
311 for (int i = 1; i < save_argc; i++)
313#endif /* PS_USE_CLOBBER_ARGV */
314
315 /*
316 * Make fixed prefix of ps display.
317 */
318
319#if defined(PS_USE_SETPROCTITLE) || defined(PS_USE_SETPROCTITLE_FAST)
320
321 /*
322 * apparently setproctitle() already adds a `progname:' prefix to the ps
323 * line
324 */
325#define PROGRAM_NAME_PREFIX ""
326#else
327#define PROGRAM_NAME_PREFIX "postgres: "
328#endif
329
330 if (*cluster_name == '\0')
331 {
334 fixed_part);
335 }
336 else
337 {
339 PROGRAM_NAME_PREFIX "%s: %s ",
341 }
342
344
345 /*
346 * On the first run, force the update.
347 */
350 set_ps_display("");
352#endif /* not PS_USE_NONE */
353}
#define Assert(condition)
Definition c.h:943
bool IsUnderPostmaster
Definition globals.c:120
char * cluster_name
Definition guc_tables.c:572
int i
Definition isn.c:77
const char * GetBackendTypeDesc(BackendType backendType)
Definition miscinit.c:264
BackendType MyBackendType
Definition miscinit.c:65
#define snprintf
Definition port.h:260
static int save_argc
Definition ps_status.c:100
bool update_process_title
Definition ps_status.c:31
static char ** save_argv
Definition ps_status.c:101
static void set_ps_display(const char *activity)
Definition ps_status.h:40

References Assert, cluster_name, fb(), GetBackendTypeDesc(), i, IsUnderPostmaster, MyBackendType, save_argc, save_argv, set_ps_display(), snprintf, and update_process_title.

Referenced by AutoVacLauncherMain(), AutoVacWorkerMain(), AuxiliaryProcessMainCommon(), BackendInitialize(), BackgroundWorkerMain(), DataChecksumsWorkerLauncherMain(), DataChecksumsWorkerMain(), ReplSlotSyncWorkerMain(), and SysLoggerMain().

◆ save_ps_display_args()

char ** save_ps_display_args ( int  argc,
char **  argv 
)
extern

Definition at line 130 of file ps_status.c.

131{
132 save_argc = argc;
133 save_argv = argv;
134
135#if defined(PS_USE_CLOBBER_ARGV)
136
137 /*
138 * If we're going to overwrite the argv area, count the available space.
139 * Also move the environment strings to make additional room.
140 */
141 {
142 char *end_of_area = NULL;
143 char **new_environ;
144 int i;
145
146 /*
147 * check for contiguous argv strings
148 */
149 for (i = 0; i < argc; i++)
150 {
151 if (i == 0 || end_of_area + 1 == argv[i])
152 end_of_area = argv[i] + strlen(argv[i]);
153 }
154
155 if (end_of_area == NULL) /* probably can't happen? */
156 {
157 ps_buffer = NULL;
158 ps_buffer_size = 0;
159 return argv;
160 }
161
162 /*
163 * check for contiguous environ strings following argv
164 */
165 for (i = 0; environ[i] != NULL; i++)
166 {
167 if (end_of_area + 1 == environ[i])
168 {
169 /*
170 * The musl dynamic linker keeps a static pointer to the
171 * initial value of LD_LIBRARY_PATH, if that is defined in the
172 * process's environment. Therefore, we must not overwrite the
173 * value of that setting and thus cannot advance end_of_area
174 * beyond it. Musl does not define any identifying compiler
175 * symbol, so we have to do this unless we see a symbol
176 * identifying a Linux libc we know is safe.
177 */
178#if defined(__linux__) && (!defined(__GLIBC__) && !defined(__UCLIBC__))
179 if (strncmp(environ[i], "LD_LIBRARY_PATH=", 16) == 0)
180 {
181 /*
182 * We can overwrite the name, but stop at the equals sign.
183 * Future loop iterations will not find any more
184 * contiguous space, but we don't break early because we
185 * need to count the total number of environ[] entries.
186 */
187 end_of_area = environ[i] + 15;
188 }
189 else
190#endif
191 {
193 }
194 }
195 }
196
197 ps_buffer = argv[0];
199
200 /*
201 * move the environment out of the way
202 */
203 new_environ = (char **) malloc((i + 1) * sizeof(char *));
204 if (!new_environ)
205 {
206 write_stderr("out of memory\n");
207 exit(1);
208 }
209 for (i = 0; environ[i] != NULL; i++)
210 {
212 if (!new_environ[i])
213 {
214 write_stderr("out of memory\n");
215 exit(1);
216 }
217 }
218 new_environ[i] = NULL;
220
221 /* See notes about Valgrind above. */
222#ifdef USE_VALGRIND
224#endif
225 }
226
227 /*
228 * If we're going to change the original argv[] then make a copy for
229 * argument parsing purposes.
230 *
231 * NB: do NOT think to remove the copying of argv[], even though
232 * postmaster.c finishes looking at argv[] long before we ever consider
233 * changing the ps display. On some platforms, getopt() keeps pointers
234 * into the argv array, and will get horribly confused when it is
235 * re-called to analyze a subprocess' argument string if the argv storage
236 * has been clobbered meanwhile. Other platforms have other dependencies
237 * on argv[]. (We use custom pg_getopt_start/next() functions nowadays
238 * that don't do that, but those other dependencies might still exist.)
239 */
240 {
241 char **new_argv;
242 int i;
243
244 new_argv = (char **) malloc((argc + 1) * sizeof(char *));
245 if (!new_argv)
246 {
247 write_stderr("out of memory\n");
248 exit(1);
249 }
250 for (i = 0; i < argc; i++)
251 {
252 new_argv[i] = strdup(argv[i]);
253 if (!new_argv[i])
254 {
255 write_stderr("out of memory\n");
256 exit(1);
257 }
258 }
259 new_argv[argc] = NULL;
260
261#if defined(__darwin__)
262
263 /*
264 * macOS has a static copy of the argv pointer, which we may fix like
265 * so:
266 */
267 *_NSGetArgv() = new_argv;
268#endif
269
270 argv = new_argv;
271 }
272#endif /* PS_USE_CLOBBER_ARGV */
273
274 return argv;
275}
#define write_stderr(str)
Definition parallel.c:186
char ** environ
#define malloc(a)

References environ, fb(), i, malloc, save_argc, save_argv, and write_stderr.

Referenced by main().

◆ set_ps_display()

◆ set_ps_display_remove_suffix()

void set_ps_display_remove_suffix ( void  )
extern

Definition at line 440 of file ps_status.c.

441{
442#ifndef PS_USE_NONE
443 /* first, check if we need to update the process title */
445 return;
446
447 /* check we added a suffix */
448 if (ps_buffer_nosuffix_len == 0)
449 return; /* no suffix */
450
451 /* remove the suffix from ps_buffer */
455
457
458 /* and set the new title */
460#endif /* not PS_USE_NONE */
461}

References Assert, and fb().

Referenced by LockBufferForCleanup(), ResolveRecoveryConflictWithVirtualXIDs(), SyncRepWaitForLSN(), and WaitOnLock().

◆ set_ps_display_suffix()

void set_ps_display_suffix ( const char suffix)
extern

Definition at line 388 of file ps_status.c.

389{
390#ifndef PS_USE_NONE
391 size_t len;
392
393 /* first, check if we need to update the process title */
395 return;
396
397 /* if there's already a suffix, overwrite it */
400 else
402
403 len = strlen(suffix);
404
405 /* check if we have enough space to append the suffix */
407 {
408 /* not enough space. Check the buffer isn't full already */
410 {
411 /* append a space before the suffix */
413
414 /* just add what we can and fill the ps_buffer */
417 ps_buffer[ps_buffer_size - 1] = '\0';
419 }
420 }
421 else
422 {
424 memcpy(ps_buffer + ps_buffer_cur_len, suffix, len + 1);
426 }
427
429
430 /* and set the new title */
432#endif /* not PS_USE_NONE */
433}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
const void size_t len

References Assert, fb(), len, and memcpy().

Referenced by LockBufferForCleanup(), ResolveRecoveryConflictWithVirtualXIDs(), SyncRepWaitForLSN(), and WaitOnLock().

◆ set_ps_display_with_len()

void set_ps_display_with_len ( const char activity,
size_t  len 
)
extern

Definition at line 470 of file ps_status.c.

471{
473
474#ifndef PS_USE_NONE
475 /* first, check if we need to update the process title */
477 return;
478
479 /* wipe out any suffix when the title is completely changed */
481
482 /* Update ps_buffer to contain both fixed part and activity */
484 {
485 /* handle the case where ps_buffer doesn't have enough space */
488 ps_buffer[ps_buffer_size - 1] = '\0';
490 }
491 else
492 {
495 }
497
498 /* Transmit new setting to kernel, if necessary */
500#endif /* not PS_USE_NONE */
501}

References Assert, fb(), len, and memcpy().

Referenced by exec_execute_message(), exec_simple_query(), and set_ps_display().

Variable Documentation

◆ update_process_title