Source
/* !defined(HAVE_FUNCTION_SETPROCTITLE) && (defined(PS_OVERWRITE_ARGV) || defined(PS_PSTAT_ARGV)) */
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/*
** Ideas from PostgreSQL implementation (src/backend/utils/misc/ps_status.c)
** were used in development of this file. Thanks to PostgreSQL developers!
**/
/* external environment we got on startup */
extern char **environ;
static int argc_ext_copied_first = 0, argc_ext_copied_last = 0, environ_ext_copied = 0;
static char **environ_ext = NULL;
/* internal copy of argv[] and environment variables */
static char **argv_int = NULL, **environ_int = NULL;
static const char *empty_str = "";
/* ps display buffer */
static char *ps_buf = NULL;
static size_t ps_buf_size = 0, prev_msg_size = 0;
static char ps_buf[PS_BUF_SIZE], *p_msg = NULL;
static size_t ps_buf_size = PS_BUF_SIZE, ps_buf_size_msg = PS_BUF_SIZE;
/******************************************************************************
* *
* Purpose: prepare for changing process commandline to display status *
* messages with "ps" command on platforms which do not support *
* setproctitle(). Depending on platform: *
* - make a copy of argc, argv[] and environment variables to *
* enable overwriting original argv[]. *
* - prepare a buffer with common part of status message. *
* *
* Comments: call this function soon after main process start, before using *
* argv[] and environment variables. *
* *
******************************************************************************/