Greenbone Vulnerability Manager
8.0.1~git
|
Generic utilities. More...
#include "utils.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
Macros | |
#define | _XOPEN_SOURCE |
Enable extra functions. More... | |
#define | _POSIX_C_SOURCE 199309L |
Needed for nanosleep. | |
#define | G_LOG_DOMAIN "md manage" |
GLib log domain. | |
Functions | |
int | gvm_usleep (unsigned int microseconds) |
Sleep for some number of microseconds, handling interrupts. More... | |
int | gvm_sleep (unsigned int seconds) |
Sleep for some number of seconds, handling interrupts. More... | |
static int | parse_utc_time (const char *format, const char *text_time) |
Convert a UTC time into seconds since epoch. More... | |
int | parse_otp_time (const char *text_time) |
Convert an OTP time into seconds since epoch. More... | |
int | parse_feed_timestamp (const char *text_time) |
Convert a feed timestamp into seconds since epoch. More... | |
int | parse_ctime (const char *text_time) |
Convert a ctime into seconds since epoch. More... | |
int | days_from_now (time_t *epoch_time) |
Calculate difference between now and epoch_time in days. More... | |
static char * | iso_time_internal (time_t *epoch_time, const char **abbrev) |
Create an ISO time from seconds since epoch. More... | |
char * | iso_time (time_t *epoch_time) |
Create an ISO time from seconds since epoch. More... | |
char * | iso_time_tz (time_t *epoch_time, const char *zone, const char **abbrev) |
Create an ISO time from seconds since epoch, given a timezone. More... | |
static int | lock_internal (lockfile_t *lockfile, const gchar *lockfile_basename, int operation) |
Lock a file. More... | |
int | lockfile_lock (lockfile_t *lockfile, const gchar *lockfile_basename) |
Lock a file exclusively. More... | |
int | lockfile_lock_nb (lockfile_t *lockfile, const gchar *lockfile_basename) |
Lock a file exclusively, without blocking. More... | |
int | lockfile_lock_shared_nb (lockfile_t *lockfile, const gchar *lockfile_basename) |
Lock a file with a shared lock. More... | |
int | lockfile_unlock (lockfile_t *lockfile) |
Unlock a file. More... | |
int | lockfile_locked (const gchar *lockfile_basename) |
Check if a file is locked. More... | |
Generic utilities.
Generic helper utilities. None of these are GVM specific. They could be used anywhere.
#define _XOPEN_SOURCE |
Enable extra functions.
time.h in glibc2 needs this for strptime.
int days_from_now | ( | time_t * | epoch_time | ) |
Calculate difference between now and epoch_time in days.
[in] | epoch_time | Time in seconds from epoch. |
int gvm_sleep | ( | unsigned int | seconds | ) |
Sleep for some number of seconds, handling interrupts.
[in] | seconds | Number of seconds. |
int gvm_usleep | ( | unsigned int | microseconds | ) |
Sleep for some number of microseconds, handling interrupts.
[in] | microseconds | Number of microseconds. |
char* iso_time | ( | time_t * | epoch_time | ) |
Create an ISO time from seconds since epoch.
[in] | epoch_time | Time in seconds from epoch. |
|
static |
Create an ISO time from seconds since epoch.
[in] | epoch_time | Time in seconds from epoch. |
[out] | abbrev | Abbreviation for current timezone. |
char* iso_time_tz | ( | time_t * | epoch_time, |
const char * | zone, | ||
const char ** | abbrev | ||
) |
Create an ISO time from seconds since epoch, given a timezone.
[in] | epoch_time | Time in seconds from epoch. |
[in] | zone | Timezone. |
[out] | abbrev | Timezone abbreviation. |
|
static |
Lock a file.
[in] | lockfile | Lockfile. |
[in] | lockfile_basename | Basename of lock file. |
[in] | operation | LOCK_EX (exclusive) or LOCK_SH (shared). Maybe ORd with LOCK_NB to prevent blocking. |
int lockfile_lock | ( | lockfile_t * | lockfile, |
const gchar * | lockfile_basename | ||
) |
Lock a file exclusively.
Block until file is locked.
[in] | lockfile | Lockfile. |
[in] | lockfile_basename | Basename of lock file. |
int lockfile_lock_nb | ( | lockfile_t * | lockfile, |
const gchar * | lockfile_basename | ||
) |
Lock a file exclusively, without blocking.
[in] | lockfile | Lockfile. |
[in] | lockfile_basename | Basename of lock file. |
int lockfile_lock_shared_nb | ( | lockfile_t * | lockfile, |
const gchar * | lockfile_basename | ||
) |
Lock a file with a shared lock.
[in] | lockfile | Lockfile. |
[in] | lockfile_basename | Basename of lock file. |
int lockfile_locked | ( | const gchar * | lockfile_basename | ) |
Check if a file is locked.
[in] | lockfile_basename | Basename of lock file. |
int lockfile_unlock | ( | lockfile_t * | lockfile | ) |
Unlock a file.
[in] | lockfile | Lockfile. |
int parse_ctime | ( | const char * | text_time | ) |
Convert a ctime into seconds since epoch.
Use the current timezone.
[in] | text_time | Time as text in ctime format. |
int parse_feed_timestamp | ( | const char * | text_time | ) |
Convert a feed timestamp into seconds since epoch.
[in] | text_time | Time as text in ctime format. |
int parse_otp_time | ( | const char * | text_time | ) |
Convert an OTP time into seconds since epoch.
Use UTC as timezone.
[in] | text_time | Time as text in ctime format. |
|
static |
Convert a UTC time into seconds since epoch.
[in] | format | Format of time. |
[in] | text_time | Time as text. |