Greenbone Vulnerability Management Libraries  11.0.0
proctitle.h File Reference

API for process title setting. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void proctitle_init (int, char **)
 Initializes the process setting variables. More...
 
void proctitle_set (const char *,...)
 Sets the process' title. More...
 

Detailed Description

API for process title setting.

Definition in file proctitle.h.

Function Documentation

◆ proctitle_init()

void proctitle_init ( int  argc,
char **  argv 
)

Initializes the process setting variables.

Parameters
[in]argcArgc argument from main.
[in]argvArgv argument from main.

Definition at line 51 of file proctitle.c.

52 {
53  int i = 0;
54  char **envp = environ;
55 #ifndef __FreeBSD__
56  char *new_progname, *new_progname_full;
57 #else
58  char *new_progname;
59 #endif
60 
61  if (argv == NULL)
62  return;
63 
64  new_progname = strdup (__progname);
65 #ifndef __FreeBSD__
66  new_progname_full = strdup (__progname_full);
67 #endif
68 
69  /* Move environ to new memory, to be able to reuse older one. */
70  while (envp[i])
71  i++;
72  environ = g_malloc0 (sizeof (char *) * (i + 1));
73  if (current_environ)
74  g_free (current_environ);
76  for (i = 0; envp[i]; i++)
77  environ[i] = g_strdup (envp[i]);
78  environ[i] = NULL;
79 
80  old_argv = argv;
81  if (i > 0)
82  argv_len = envp[i - 1] + strlen (envp[i - 1]) - old_argv[0];
83  else
84  argv_len = old_argv[argc - 1] + strlen (old_argv[argc - 1]) - old_argv[0];
85 
86  /* Seems like these are in the moved environment, so reset them. Idea from
87  * proctitle.cpp in KDE libs. */
88  __progname = new_progname;
89 #ifndef __FreeBSD__
90  __progname_full = new_progname_full;
91 #endif
92 }

References __progname, __progname_full, argv_len, current_environ, environ, and old_argv.

◆ proctitle_set()

void proctitle_set ( const char *  new_title,
  ... 
)

Sets the process' title.

Parameters
[in]new_titleFormat string for new process title.
[in]...Arguments for format string.

Definition at line 131 of file proctitle.c.

132 {
133  va_list args;
134 
135  va_start (args, new_title);
136  proctitle_set_args (new_title, args);
137  va_end (args);
138 }

References proctitle_set_args().

Here is the call graph for this function:
__progname_full
const char * __progname_full
current_environ
void * current_environ
Definition: proctitle.c:42
argv_len
static int argv_len
Definition: proctitle.c:39
old_argv
static char ** old_argv
Definition: proctitle.c:40
proctitle_set_args
static void proctitle_set_args(const char *new_title, va_list args)
Sets the process' title.
Definition: proctitle.c:101
environ
char ** environ
__progname
const char * __progname
Access to the executable's name.