Greenbone Vulnerability Management Libraries 22.32.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.
void proctitle_set (const char *,...)
 Sets the process' title.

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 45 of file proctitle.c.

46{
47 int i;
48 char **envp = environ;
49#ifndef __FreeBSD__
50 char *new_progname, *new_progname_full;
51#else
52 char *new_progname;
53#endif
54 old_argc = argc;
55
56 if (argv == NULL)
57 return;
58 // according to c99 argv is defined as when argc is set it follows program
59 // parameter. Since we will override on set_proctitle we know that this
60 // memory is modifiable.
61 // Everything after that is unsafe and can lead to segmentation faults.
62 // Therefore we iterate through argv and append strlen to gather the maximum
63 // safe program name.
64 for (i = 0; i < argc; i++)
65 {
66 max_prog_name += strlen (argv[i]) + 1;
67 }
68 i = 0;
69
70 new_progname = strdup (__progname);
71#ifndef __FreeBSD__
72 new_progname_full = strdup (__progname_full);
73#endif
74
75 /* Move environ to new memory, to be able to reuse older one. */
76 while (envp[i])
77 i++;
78 environ = g_malloc0 (sizeof (char *) * (i + 1));
80 g_free (current_environ);
82 for (i = 0; envp[i]; i++)
83 environ[i] = g_strdup (envp[i]);
84 environ[i] = NULL;
85
86 old_argv = argv;
87 /* Seems like these are in the moved environment, so reset them. Idea from
88 * proctitle.cpp in KDE libs. */
89 __progname = new_progname;
90#ifndef __FreeBSD__
91 __progname_full = new_progname_full;
92#endif
93}
const char * __progname_full
void * current_environ
Definition proctitle.c:35
static char ** old_argv
Definition proctitle.c:32
static int old_argc
Definition proctitle.c:33
char ** environ
static int max_prog_name
Definition proctitle.c:36
const char * __progname
Access to the executable's name.

References __progname, __progname_full, current_environ, environ, max_prog_name, old_argc, 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 139 of file proctitle.c.

140{
141 va_list args;
142
143 va_start (args, new_title);
144 proctitle_set_args (new_title, args);
145 va_end (args);
146}
static void proctitle_set_args(const char *new_title, va_list args)
Sets the process' title.
Definition proctitle.c:102

References proctitle_set_args().

Here is the call graph for this function: