18 #ifdef HAVE_SYS_PSTAT_H 19 #include <sys/pstat.h> 21 #ifdef HAVE_PS_STRINGS 22 #include <machine/vmparam.h> 25 #if defined(__darwin__) 26 #include <crt_externs.h> 62 #if defined(HAVE_SETPROCTITLE) 63 #define PS_USE_SETPROCTITLE 64 #elif defined(HAVE_PSTAT) && defined(PSTAT_SETCMD) 66 #elif defined(HAVE_PS_STRINGS) 67 #define PS_USE_PS_STRINGS 68 #elif (defined(BSD) || defined(__hurd__)) && !defined(__darwin__) 69 #define PS_USE_CHANGE_ARGV 70 #elif defined(__linux__) || defined(_AIX) || defined(__sgi) || (defined(sun) && !defined(BSD)) || defined(__svr5__) || defined(__darwin__) 71 #define PS_USE_CLOBBER_ARGV 80 #if defined(_AIX) || defined(__linux__) || defined(__darwin__) 81 #define PS_PADDING '\0' 83 #define PS_PADDING ' ' 87 #ifndef PS_USE_CLOBBER_ARGV 89 #define PS_BUFFER_SIZE 256 95 static size_t last_status_len;
126 #if defined(PS_USE_CLOBBER_ARGV) 133 char *end_of_area = NULL;
140 for (i = 0; i < argc; i++)
142 if (i == 0 || end_of_area + 1 == argv[i])
143 end_of_area = argv[
i] + strlen(argv[i]);
146 if (end_of_area == NULL)
156 for (i = 0;
environ[
i] != NULL; i++)
158 if (end_of_area + 1 ==
environ[i])
168 new_environ = (
char **)
malloc((i + 1) *
sizeof(
char *));
174 for (i = 0;
environ[
i] != NULL; i++)
176 new_environ[
i] = strdup(
environ[i]);
183 new_environ[
i] = NULL;
188 #if defined(PS_USE_CHANGE_ARGV) || defined(PS_USE_CLOBBER_ARGV) 206 new_argv = (
char **)
malloc((argc + 1) *
sizeof(
char *));
212 for (i = 0; i < argc; i++)
214 new_argv[
i] = strdup(argv[i]);
221 new_argv[argc] = NULL;
223 #if defined(__darwin__) 229 *_NSGetArgv() = new_argv;
245 const char *host_info,
const char *initial_str)
260 #ifdef PS_USE_CLOBBER_ARGV 270 #ifdef PS_USE_CHANGE_ARGV 275 #ifdef PS_USE_CLOBBER_ARGV 289 #ifdef PS_USE_SETPROCTITLE 295 #define PROGRAM_NAME_PREFIX "" 297 #define PROGRAM_NAME_PREFIX "postgres: " 303 PROGRAM_NAME_PREFIX
"%s %s %s ",
304 username, dbname, host_info);
309 PROGRAM_NAME_PREFIX
"%s: %s %s %s ",
337 #ifdef PS_USE_CLOBBER_ARGV 350 #ifdef PS_USE_SETPROCTITLE 363 #ifdef PS_USE_PS_STRINGS 364 PS_STRINGS->ps_nargvstr = 1;
368 #ifdef PS_USE_CLOBBER_ARGV 383 static HANDLE ident_handle = INVALID_HANDLE_VALUE;
386 if (ident_handle != INVALID_HANDLE_VALUE)
387 CloseHandle(ident_handle);
391 ident_handle = CreateEvent(NULL,
TRUE,
FALSE, name);
407 #ifdef PS_USE_CLOBBER_ARGV
bool update_process_title
#define write_stderr(str)
void set_ps_display(const char *activity, bool force)
#define MemSet(start, val, len)
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static const size_t ps_buffer_size
char ** save_ps_display_args(int argc, char **argv)
const char * get_ps_display(int *displen)
size_t strlcpy(char *dst, const char *src, size_t siz)
#define Assert(condition)
static size_t ps_buffer_cur_len
static size_t ps_buffer_fixed_size
static char ps_buffer[PS_BUFFER_SIZE]
void init_ps_display(const char *username, const char *dbname, const char *host_info, const char *initial_str)