OpenVAS Scanner  5.1.3
log.h File Reference
#include <stdarg.h>
Include dependency graph for log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void log_init (const char *)
 Initialization of the log file. More...
 
void log_close (void)
 
int log_get_fd ()
 Get the open log file descriptor. More...
 
void log_vwrite (const char *, va_list)
 Write into the logfile / syslog using a va_list. More...
 
void log_write (const char *,...)
 Write into the logfile / syslog. More...
 

Function Documentation

◆ log_close()

void log_close ( void  )

Definition at line 90 of file log.c.

91 {
92  if (log != NULL)
93  {
94  log_write ("closing logfile");
95  fclose (log);
96  log = NULL;
97  }
98  else
99  closelog ();
100 }
void log_write(const char *str,...)
Write into the logfile / syslog.
Definition: log.c:140

◆ log_get_fd()

int log_get_fd ( )

Get the open log file descriptor.

Parameters
[out]Returnthe log file descriptor.

Definition at line 84 of file log.c.

85 {
86  return log ? fileno (log) : -1;
87 }

◆ log_init()

void log_init ( const char *  )

Initialization of the log file.

Definition at line 48 of file log.c.

49 {
50  if ((!filename) || (!strcmp (filename, "stderr")))
51  log = stderr;
52  else if (!strcmp (filename, "syslog"))
53  {
54  openlog ("openvassd", 0, LOG_DAEMON);
55  log = NULL;
56  }
57  else
58  {
59  int fd = open (filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
60  if (fd < 0)
61  {
62  fprintf (stderr, "log_init():open : %s\n", strerror (errno));
63  fprintf (stderr, "Could not open the logfile, using stderr\n");
64  log = stderr;
65  }
66  log = fdopen (fd, "a");
67  if (log == NULL)
68  {
69  perror ("fdopen ");
70  log = stderr;
71  }
72 
73  setlinebuf (log);
74  }
75 }

◆ log_vwrite()

void log_vwrite ( const char *  str,
va_list  arg_ptr 
)

Write into the logfile / syslog using a va_list.

Parameters
[in]strFormat string.
[in]arg_ptrString parameters.

Definition at line 110 of file log.c.

111 {
112  char *tmp;
113  char timestr[255];
114  time_t t;
115 
116  if (log == NULL)
117  {
118  vsyslog (LOG_NOTICE, str, arg_ptr);
119  return;
120  }
121 
122  t = time (NULL);
123  tmp = ctime (&t);
124 
125  timestr[sizeof (timestr) - 1] = '\0';
126  strncpy (timestr, tmp, sizeof (timestr) - 1);
127  timestr[strlen (timestr) - 1] = '\0';
128  fprintf (log, "[%s][%d] ", timestr, getpid ());
129  vfprintf (log, str, arg_ptr);
130  fprintf (log, "\n");
131 }

Referenced by log_write().

Here is the caller graph for this function:

◆ log_write()

void log_write ( const char *  str,
  ... 
)

Write into the logfile / syslog.

Parameters
[in]strFormat string, followed by the corresponding parameters if any.

Definition at line 140 of file log.c.

141 {
142  va_list param;
143 
144  va_start (param, str);
145  log_vwrite (str, param);
146  va_end (param);
147 }
void log_vwrite(const char *str, va_list arg_ptr)
Write into the logfile / syslog using a va_list.
Definition: log.c:110

References log_vwrite().

Referenced by check_kb_status(), comm_init(), comm_loading(), comm_wait_order(), get_max_checks_number(), get_max_hosts_number(), nasl_plugin_add(), plugin_next_unrun_dependency(), plugins_init(), scheduler_rm_running_ports(), and send_plug_info().

Here is the call graph for this function:
Here is the caller graph for this function: