2000-06-04 03:44:38 +02:00
|
|
|
/*--------------------------------------------------------------------
|
|
|
|
* ps_status.c
|
|
|
|
*
|
|
|
|
* Routines to support changing the ps display of PostgreSQL backends
|
2001-10-21 05:25:36 +02:00
|
|
|
* to contain some useful information. Mechanism differs wildly across
|
2000-06-04 03:44:38 +02:00
|
|
|
* platforms.
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/utils/misc/ps_status.c
|
2000-06-04 03:44:38 +02:00
|
|
|
*
|
2016-01-02 19:33:40 +01:00
|
|
|
* Copyright (c) 2000-2016, PostgreSQL Global Development Group
|
2000-06-04 03:44:38 +02:00
|
|
|
* various details abducted from various places
|
|
|
|
*--------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#ifdef HAVE_SYS_PSTAT_H
|
2001-03-22 05:01:46 +01:00
|
|
|
#include <sys/pstat.h> /* for HP-UX */
|
2000-06-04 03:44:38 +02:00
|
|
|
#endif
|
2000-07-09 15:14:19 +02:00
|
|
|
#ifdef HAVE_PS_STRINGS
|
2001-03-22 05:01:46 +01:00
|
|
|
#include <machine/vmparam.h> /* for old BSD */
|
|
|
|
#include <sys/exec.h>
|
2000-06-04 03:44:38 +02:00
|
|
|
#endif
|
2004-02-22 22:26:55 +01:00
|
|
|
#if defined(__darwin__)
|
|
|
|
#include <crt_externs.h>
|
|
|
|
#endif
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2004-03-09 05:43:07 +01:00
|
|
|
#include "libpq/libpq.h"
|
2000-06-04 03:44:38 +02:00
|
|
|
#include "miscadmin.h"
|
|
|
|
#include "utils/ps_status.h"
|
2014-06-29 14:15:09 +02:00
|
|
|
#include "utils/guc.h"
|
2000-06-04 03:44:38 +02:00
|
|
|
|
|
|
|
extern char **environ;
|
2006-10-04 02:30:14 +02:00
|
|
|
bool update_process_title = true;
|
2000-06-04 03:44:38 +02:00
|
|
|
|
|
|
|
|
2006-06-12 04:39:49 +02:00
|
|
|
/*
|
2000-06-04 03:44:38 +02:00
|
|
|
* Alternative ways of updating ps display:
|
|
|
|
*
|
|
|
|
* PS_USE_SETPROCTITLE
|
2001-03-22 05:01:46 +01:00
|
|
|
* use the function setproctitle(const char *, ...)
|
|
|
|
* (newer BSD systems)
|
2000-06-04 03:44:38 +02:00
|
|
|
* PS_USE_PSTAT
|
2001-03-22 05:01:46 +01:00
|
|
|
* use the pstat(PSTAT_SETCMD, )
|
|
|
|
* (HPUX)
|
2000-06-04 03:44:38 +02:00
|
|
|
* PS_USE_PS_STRINGS
|
2001-03-22 05:01:46 +01:00
|
|
|
* assign PS_STRINGS->ps_argvstr = "string"
|
|
|
|
* (some BSD systems)
|
2001-03-20 23:31:54 +01:00
|
|
|
* PS_USE_CHANGE_ARGV
|
2001-03-22 05:01:46 +01:00
|
|
|
* assign argv[0] = "string"
|
|
|
|
* (some other BSD systems)
|
2000-06-04 03:44:38 +02:00
|
|
|
* PS_USE_CLOBBER_ARGV
|
2001-03-22 05:01:46 +01:00
|
|
|
* write over the argv and environment area
|
2010-05-27 21:19:38 +02:00
|
|
|
* (Linux and most SysV-like systems)
|
2006-06-12 04:39:49 +02:00
|
|
|
* PS_USE_WIN32
|
|
|
|
* push the string out as the name of a Windows event
|
2000-06-04 03:44:38 +02:00
|
|
|
* PS_USE_NONE
|
2001-03-22 05:01:46 +01:00
|
|
|
* don't update ps display
|
|
|
|
* (This is the default, as it is safest.)
|
2000-06-04 03:44:38 +02:00
|
|
|
*/
|
|
|
|
#if defined(HAVE_SETPROCTITLE)
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PS_USE_SETPROCTITLE
|
2000-06-04 03:44:38 +02:00
|
|
|
#elif defined(HAVE_PSTAT) && defined(PSTAT_SETCMD)
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PS_USE_PSTAT
|
2000-06-04 03:44:38 +02:00
|
|
|
#elif defined(HAVE_PS_STRINGS)
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PS_USE_PS_STRINGS
|
2012-05-03 16:58:44 +02:00
|
|
|
#elif (defined(BSD) || defined(__hurd__)) && !defined(__darwin__)
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PS_USE_CHANGE_ARGV
|
2014-06-28 21:40:40 +02:00
|
|
|
#elif defined(__linux__) || defined(_AIX) || defined(__sgi) || (defined(sun) && !defined(BSD)) || defined(__svr5__) || defined(__darwin__)
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PS_USE_CLOBBER_ARGV
|
2006-06-12 04:39:49 +02:00
|
|
|
#elif defined(WIN32)
|
2004-12-02 23:28:22 +01:00
|
|
|
#define PS_USE_WIN32
|
2000-06-04 03:44:38 +02:00
|
|
|
#else
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PS_USE_NONE
|
2000-06-04 03:44:38 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Different systems want the buffer padded differently */
|
2012-05-02 06:29:17 +02:00
|
|
|
#if defined(_AIX) || defined(__linux__) || defined(__darwin__)
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PS_PADDING '\0'
|
2000-06-04 03:44:38 +02:00
|
|
|
#else
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PS_PADDING ' '
|
2000-06-04 03:44:38 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef PS_USE_CLOBBER_ARGV
|
2010-05-27 21:19:38 +02:00
|
|
|
/* all but one option need a buffer to write their ps line in */
|
2000-06-04 03:44:38 +02:00
|
|
|
#define PS_BUFFER_SIZE 256
|
|
|
|
static char ps_buffer[PS_BUFFER_SIZE];
|
|
|
|
static const size_t ps_buffer_size = PS_BUFFER_SIZE;
|
2001-03-22 05:01:46 +01:00
|
|
|
#else /* PS_USE_CLOBBER_ARGV */
|
|
|
|
static char *ps_buffer; /* will point to argv area */
|
|
|
|
static size_t ps_buffer_size; /* space determined at run time */
|
2007-02-16 22:34:04 +01:00
|
|
|
static size_t last_status_len; /* use to minimize length of clobber */
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PS_USE_CLOBBER_ARGV */
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2010-07-06 21:19:02 +02:00
|
|
|
static size_t ps_buffer_cur_len; /* nominal strlen(ps_buffer) */
|
2010-05-27 21:19:38 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
static size_t ps_buffer_fixed_size; /* size of the constant prefix */
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2001-10-21 05:25:36 +02:00
|
|
|
/* save the original argv[] location here */
|
|
|
|
static int save_argc;
|
|
|
|
static char **save_argv;
|
2000-06-04 03:44:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-10-21 05:25:36 +02:00
|
|
|
* Call this early in startup to save the original argc/argv values.
|
2004-02-22 22:26:55 +01:00
|
|
|
* If needed, we make a copy of the original argv[] array to preserve it
|
|
|
|
* from being clobbered by subsequent ps_display actions.
|
2001-10-22 21:41:38 +02:00
|
|
|
*
|
2004-02-22 22:26:55 +01:00
|
|
|
* (The original argv[] will not be overwritten by this routine, but may be
|
2014-05-06 18:12:18 +02:00
|
|
|
* overwritten during init_ps_display. Also, the physical location of the
|
2004-02-22 22:26:55 +01:00
|
|
|
* environment strings may be moved, so this should be called before any code
|
|
|
|
* that might try to hang onto a getenv() result.)
|
2016-08-31 00:22:43 +02:00
|
|
|
*
|
|
|
|
* Note that in case of failure this cannot call elog() as that is not
|
|
|
|
* initialized yet. We rely on write_stderr() instead.
|
2000-06-04 03:44:38 +02:00
|
|
|
*/
|
2005-10-15 04:49:52 +02:00
|
|
|
char **
|
2004-02-22 22:26:55 +01:00
|
|
|
save_ps_display_args(int argc, char **argv)
|
2001-10-21 05:25:36 +02:00
|
|
|
{
|
|
|
|
save_argc = argc;
|
|
|
|
save_argv = argv;
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2004-02-22 22:26:55 +01:00
|
|
|
#if defined(PS_USE_CLOBBER_ARGV)
|
2001-10-25 07:50:21 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* If we're going to overwrite the argv area, count the available space.
|
|
|
|
* Also move the environment to make additional room.
|
2001-03-22 05:01:46 +01:00
|
|
|
*/
|
2000-06-04 03:44:38 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
char *end_of_area = NULL;
|
|
|
|
char **new_environ;
|
|
|
|
int i;
|
2000-06-04 03:44:38 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check for contiguous argv strings
|
|
|
|
*/
|
2001-10-22 21:41:38 +02:00
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (i == 0 || end_of_area + 1 == argv[i])
|
|
|
|
end_of_area = argv[i] + strlen(argv[i]);
|
|
|
|
}
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2001-10-28 07:26:15 +01:00
|
|
|
if (end_of_area == NULL) /* probably can't happen? */
|
2000-06-04 03:44:38 +02:00
|
|
|
{
|
|
|
|
ps_buffer = NULL;
|
|
|
|
ps_buffer_size = 0;
|
2004-02-22 22:26:55 +01:00
|
|
|
return argv;
|
2000-06-04 03:44:38 +02:00
|
|
|
}
|
2001-10-22 21:41:38 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check for contiguous environ strings following argv
|
|
|
|
*/
|
|
|
|
for (i = 0; environ[i] != NULL; i++)
|
2000-06-04 03:44:38 +02:00
|
|
|
{
|
2001-10-22 21:41:38 +02:00
|
|
|
if (end_of_area + 1 == environ[i])
|
|
|
|
end_of_area = environ[i] + strlen(environ[i]);
|
2000-06-04 03:44:38 +02:00
|
|
|
}
|
2001-10-22 21:41:38 +02:00
|
|
|
|
|
|
|
ps_buffer = argv[0];
|
2007-02-16 22:34:04 +01:00
|
|
|
last_status_len = ps_buffer_size = end_of_area - argv[0];
|
2007-11-15 22:14:46 +01:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
/*
|
|
|
|
* move the environment out of the way
|
|
|
|
*/
|
2004-02-22 22:26:55 +01:00
|
|
|
new_environ = (char **) malloc((i + 1) * sizeof(char *));
|
2016-08-31 00:22:43 +02:00
|
|
|
if (!new_environ)
|
|
|
|
{
|
|
|
|
write_stderr("out of memory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-06-04 03:44:38 +02:00
|
|
|
for (i = 0; environ[i] != NULL; i++)
|
2016-08-31 00:22:43 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
new_environ[i] = strdup(environ[i]);
|
2016-08-31 00:22:43 +02:00
|
|
|
if (!new_environ[i])
|
|
|
|
{
|
|
|
|
write_stderr("out of memory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2000-06-04 03:44:38 +02:00
|
|
|
new_environ[i] = NULL;
|
|
|
|
environ = new_environ;
|
|
|
|
}
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PS_USE_CLOBBER_ARGV */
|
2004-02-22 22:26:55 +01:00
|
|
|
|
|
|
|
#if defined(PS_USE_CHANGE_ARGV) || defined(PS_USE_CLOBBER_ARGV)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're going to change the original argv[] then make a copy for
|
|
|
|
* argument parsing purposes.
|
|
|
|
*
|
|
|
|
* (NB: do NOT think to remove the copying of argv[], even though
|
2005-10-15 04:49:52 +02:00
|
|
|
* postmaster.c finishes looking at argv[] long before we ever consider
|
|
|
|
* changing the ps display. On some platforms, getopt() keeps pointers
|
|
|
|
* into the argv array, and will get horribly confused when it is
|
|
|
|
* re-called to analyze a subprocess' argument string if the argv storage
|
|
|
|
* has been clobbered meanwhile. Other platforms have other dependencies
|
|
|
|
* on argv[].
|
2004-02-22 22:26:55 +01:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
char **new_argv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
new_argv = (char **) malloc((argc + 1) * sizeof(char *));
|
2016-08-31 00:22:43 +02:00
|
|
|
if (!new_argv)
|
|
|
|
{
|
|
|
|
write_stderr("out of memory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2004-02-22 22:26:55 +01:00
|
|
|
for (i = 0; i < argc; i++)
|
2016-08-31 00:22:43 +02:00
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
new_argv[i] = strdup(argv[i]);
|
2016-08-31 00:22:43 +02:00
|
|
|
if (!new_argv[i])
|
|
|
|
{
|
|
|
|
write_stderr("out of memory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2004-02-22 22:26:55 +01:00
|
|
|
new_argv[argc] = NULL;
|
|
|
|
|
|
|
|
#if defined(__darwin__)
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2004-02-22 22:26:55 +01:00
|
|
|
/*
|
Refer to OS X as "macOS", except for the port name which is still "darwin".
We weren't terribly consistent about whether to call Apple's OS "OS X"
or "Mac OS X", and the former is probably confusing to people who aren't
Apple users. Now that Apple has rebranded it "macOS", follow their lead
to establish a consistent naming pattern. Also, avoid the use of the
ancient project name "Darwin", except as the port code name which does not
seem desirable to change. (In short, this patch touches documentation and
comments, but no actual code.)
I didn't touch contrib/start-scripts/osx/, either. I suspect those are
obsolete and due for a rewrite, anyway.
I dithered about whether to apply this edit to old release notes, but
those were responsible for quite a lot of the inconsistencies, so I ended
up changing them too. Anyway, Apple's being ahistorical about this,
so why shouldn't we be?
2016-09-25 21:40:57 +02:00
|
|
|
* macOS (and perhaps other NeXT-derived platforms?) has a static copy
|
|
|
|
* of the argv pointer, which we may fix like so:
|
2004-02-22 22:26:55 +01:00
|
|
|
*/
|
|
|
|
*_NSGetArgv() = new_argv;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
argv = new_argv;
|
|
|
|
}
|
2005-10-15 04:49:52 +02:00
|
|
|
#endif /* PS_USE_CHANGE_ARGV or PS_USE_CLOBBER_ARGV */
|
2004-02-22 22:26:55 +01:00
|
|
|
|
|
|
|
return argv;
|
2001-10-22 21:41:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call this once during subprocess startup to set the identification
|
2014-05-06 18:12:18 +02:00
|
|
|
* values. At this point, the original argv[] array may be overwritten.
|
2001-10-22 21:41:38 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
init_ps_display(const char *username, const char *dbname,
|
2006-06-28 00:16:44 +02:00
|
|
|
const char *host_info, const char *initial_str)
|
2001-10-22 21:41:38 +02:00
|
|
|
{
|
|
|
|
Assert(username);
|
|
|
|
Assert(dbname);
|
|
|
|
Assert(host_info);
|
|
|
|
|
|
|
|
#ifndef PS_USE_NONE
|
|
|
|
/* no ps display for stand-alone backend */
|
|
|
|
if (!IsUnderPostmaster)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* no ps display if you didn't call save_ps_display_args() */
|
|
|
|
if (!save_argv)
|
|
|
|
return;
|
2010-05-27 21:19:38 +02:00
|
|
|
|
2001-10-22 21:41:38 +02:00
|
|
|
#ifdef PS_USE_CLOBBER_ARGV
|
|
|
|
/* If ps_buffer is a pointer, it might still be null */
|
|
|
|
if (!ps_buffer)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Overwrite argv[] to point at appropriate space, if needed
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef PS_USE_CHANGE_ARGV
|
|
|
|
save_argv[0] = ps_buffer;
|
|
|
|
save_argv[1] = NULL;
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PS_USE_CHANGE_ARGV */
|
2001-10-22 21:41:38 +02:00
|
|
|
|
|
|
|
#ifdef PS_USE_CLOBBER_ARGV
|
2003-11-08 20:07:24 +01:00
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
int i;
|
2003-11-08 20:07:24 +01:00
|
|
|
|
|
|
|
/* make extra argv slots point at end_of_area (a NUL) */
|
|
|
|
for (i = 1; i < save_argc; i++)
|
|
|
|
save_argv[i] = ps_buffer + ps_buffer_size;
|
|
|
|
}
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PS_USE_CLOBBER_ARGV */
|
2000-06-04 03:44:38 +02:00
|
|
|
|
|
|
|
/*
|
2001-10-22 21:41:38 +02:00
|
|
|
* Make fixed prefix of ps display.
|
2000-06-04 03:44:38 +02:00
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2001-10-22 21:41:38 +02:00
|
|
|
#ifdef PS_USE_SETPROCTITLE
|
2001-10-25 07:50:21 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* apparently setproctitle() already adds a `progname:' prefix to the ps
|
|
|
|
* line
|
2001-03-22 05:01:46 +01:00
|
|
|
*/
|
2014-06-29 14:15:09 +02:00
|
|
|
#define PROGRAM_NAME_PREFIX ""
|
2001-03-22 05:01:46 +01:00
|
|
|
#else
|
2014-06-29 14:15:09 +02:00
|
|
|
#define PROGRAM_NAME_PREFIX "postgres: "
|
2001-03-22 05:01:46 +01:00
|
|
|
#endif
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2014-06-29 14:15:09 +02:00
|
|
|
if (*cluster_name == '\0')
|
|
|
|
{
|
|
|
|
snprintf(ps_buffer, ps_buffer_size,
|
|
|
|
PROGRAM_NAME_PREFIX "%s %s %s ",
|
|
|
|
username, dbname, host_info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(ps_buffer, ps_buffer_size,
|
|
|
|
PROGRAM_NAME_PREFIX "%s: %s %s %s ",
|
|
|
|
cluster_name, username, dbname, host_info);
|
|
|
|
}
|
|
|
|
|
2010-05-27 21:19:38 +02:00
|
|
|
ps_buffer_cur_len = ps_buffer_fixed_size = strlen(ps_buffer);
|
2004-12-02 23:28:22 +01:00
|
|
|
|
2006-06-28 00:16:44 +02:00
|
|
|
set_ps_display(initial_str, true);
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* not PS_USE_NONE */
|
2000-06-04 03:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call this to update the ps status display to a fixed prefix plus an
|
|
|
|
* indication of what you're currently doing passed in the argument.
|
|
|
|
*/
|
|
|
|
void
|
2006-06-28 00:16:44 +02:00
|
|
|
set_ps_display(const char *activity, bool force)
|
2000-06-04 03:44:38 +02:00
|
|
|
{
|
2010-05-27 21:19:38 +02:00
|
|
|
#ifndef PS_USE_NONE
|
|
|
|
/* update_process_title=off disables updates, unless force = true */
|
2006-06-28 00:16:44 +02:00
|
|
|
if (!force && !update_process_title)
|
|
|
|
return;
|
2006-10-04 02:30:14 +02:00
|
|
|
|
2004-03-19 03:23:59 +01:00
|
|
|
/* no ps display for stand-alone backend */
|
|
|
|
if (!IsUnderPostmaster)
|
|
|
|
return;
|
2004-03-09 05:43:07 +01:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#ifdef PS_USE_CLOBBER_ARGV
|
2001-03-20 23:31:54 +01:00
|
|
|
/* If ps_buffer is a pointer, it might still be null */
|
2000-06-04 03:44:38 +02:00
|
|
|
if (!ps_buffer)
|
|
|
|
return;
|
2001-03-22 05:01:46 +01:00
|
|
|
#endif
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2001-10-21 05:25:36 +02:00
|
|
|
/* Update ps_buffer to contain both fixed part and activity */
|
2006-09-27 20:40:10 +02:00
|
|
|
strlcpy(ps_buffer + ps_buffer_fixed_size, activity,
|
2001-03-20 23:31:54 +01:00
|
|
|
ps_buffer_size - ps_buffer_fixed_size);
|
2010-05-27 21:19:38 +02:00
|
|
|
ps_buffer_cur_len = strlen(ps_buffer);
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2001-03-20 23:31:54 +01:00
|
|
|
/* Transmit new setting to kernel, if necessary */
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#ifdef PS_USE_SETPROCTITLE
|
2001-03-20 23:31:54 +01:00
|
|
|
setproctitle("%s", ps_buffer);
|
2001-03-22 05:01:46 +01:00
|
|
|
#endif
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#ifdef PS_USE_PSTAT
|
|
|
|
{
|
|
|
|
union pstun pst;
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
pst.pst_command = ps_buffer;
|
2010-05-27 21:19:38 +02:00
|
|
|
pstat(PSTAT_SETCMD, pst, ps_buffer_cur_len, 0, 0);
|
2001-03-22 05:01:46 +01:00
|
|
|
}
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PS_USE_PSTAT */
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#ifdef PS_USE_PS_STRINGS
|
|
|
|
PS_STRINGS->ps_nargvstr = 1;
|
|
|
|
PS_STRINGS->ps_argvstr = ps_buffer;
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PS_USE_PS_STRINGS */
|
2000-06-04 03:44:38 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#ifdef PS_USE_CLOBBER_ARGV
|
2010-05-27 21:19:38 +02:00
|
|
|
/* pad unused memory; need only clobber remainder of old status string */
|
|
|
|
if (last_status_len > ps_buffer_cur_len)
|
|
|
|
MemSet(ps_buffer + ps_buffer_cur_len, PS_PADDING,
|
|
|
|
last_status_len - ps_buffer_cur_len);
|
|
|
|
last_status_len = ps_buffer_cur_len;
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PS_USE_CLOBBER_ARGV */
|
2004-12-02 23:28:22 +01:00
|
|
|
|
2006-06-12 04:39:49 +02:00
|
|
|
#ifdef PS_USE_WIN32
|
|
|
|
{
|
|
|
|
/*
|
2006-10-04 02:30:14 +02:00
|
|
|
* Win32 does not support showing any changed arguments. To make it at
|
|
|
|
* all possible to track which backend is doing what, we create a
|
2006-06-12 04:39:49 +02:00
|
|
|
* named object that can be viewed with for example Process Explorer.
|
|
|
|
*/
|
|
|
|
static HANDLE ident_handle = INVALID_HANDLE_VALUE;
|
|
|
|
char name[PS_BUFFER_SIZE + 32];
|
|
|
|
|
|
|
|
if (ident_handle != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle(ident_handle);
|
|
|
|
|
2008-01-31 10:21:17 +01:00
|
|
|
sprintf(name, "pgident(%d): %s", MyProcPid, ps_buffer);
|
2006-06-12 04:39:49 +02:00
|
|
|
|
|
|
|
ident_handle = CreateEvent(NULL, TRUE, FALSE, name);
|
|
|
|
}
|
|
|
|
#endif /* PS_USE_WIN32 */
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* not PS_USE_NONE */
|
2000-06-04 03:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns what's currently in the ps display, in case someone needs
|
2014-05-06 18:12:18 +02:00
|
|
|
* it. Note that only the activity part is returned. On some platforms
|
2005-11-05 04:04:53 +01:00
|
|
|
* the string will not be null-terminated, so return the effective
|
|
|
|
* length into *displen.
|
2000-06-04 03:44:38 +02:00
|
|
|
*/
|
|
|
|
const char *
|
2005-11-05 04:04:53 +01:00
|
|
|
get_ps_display(int *displen)
|
2000-06-04 03:44:38 +02:00
|
|
|
{
|
2001-03-20 23:31:54 +01:00
|
|
|
#ifdef PS_USE_CLOBBER_ARGV
|
|
|
|
/* If ps_buffer is a pointer, it might still be null */
|
|
|
|
if (!ps_buffer)
|
2005-11-05 04:04:53 +01:00
|
|
|
{
|
|
|
|
*displen = 0;
|
2001-03-20 23:31:54 +01:00
|
|
|
return "";
|
2005-11-05 04:04:53 +01:00
|
|
|
}
|
2001-03-20 23:31:54 +01:00
|
|
|
#endif
|
|
|
|
|
2010-05-27 21:19:38 +02:00
|
|
|
*displen = (int) (ps_buffer_cur_len - ps_buffer_fixed_size);
|
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
return ps_buffer + ps_buffer_fixed_size;
|
|
|
|
}
|