OpenVAS Libraries  9.0.3
openvas_proctitle.c File Reference
#include <glib.h>
#include <string.h>
#include <stdio.h>
#include "openvas_proctitle.h"
Include dependency graph for openvas_proctitle.c:

Go to the source code of this file.

Functions

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

Variables

const char * __progname
 
const char * __progname_full
 
char ** environ
 
void * current_environ = NULL
 

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 46 of file openvas_proctitle.c.

References __progname, __progname_full, current_environ, and environ.

47 {
48  int i = 0;
49  char **envp = environ;
50  char *new_progname, *new_progname_full;
51 
52  if (argv == NULL)
53  return;
54 
55  new_progname = strdup (__progname);
56  new_progname_full = strdup (__progname_full);
57 
58  /* Move environ to new memory, to be able to reuse older one. */
59  while (envp[i]) i++;
60  environ = g_malloc0 (sizeof (char *) * (i + 1));
61  if (current_environ)
62  g_free (current_environ);
64  for (i = 0; envp[i]; i++)
65  environ[i] = g_strdup (envp[i]);
66  environ[i] = NULL;
67 
68  old_argv = argv;
69  if (i > 0)
70  argv_len = envp[i-1] + strlen (envp[i-1]) - old_argv[0];
71  else
72  argv_len = old_argv[argc-1] + strlen (old_argv[argc-1]) - old_argv[0];
73 
74  /* Seems like these are in the moved environment, so reset them. Idea from
75  * proctitle.cpp in KDE libs. */
76  __progname = new_progname;
77  __progname_full = new_progname_full;
78 }
void * current_environ
const char * __progname_full
const char * __progname
char ** environ

◆ 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 117 of file openvas_proctitle.c.

118 {
119  va_list args;
120 
121  va_start (args, new_title);
122  proctitle_set_args (new_title, args);
123  va_end (args);
124 }

Variable Documentation

◆ __progname

const char* __progname

Referenced by proctitle_init().

◆ __progname_full

const char* __progname_full

Referenced by proctitle_init().

◆ current_environ

void* current_environ = NULL

Definition at line 37 of file openvas_proctitle.c.

Referenced by proctitle_init().

◆ environ

char** environ

Referenced by proctitle_init().