open-vm-tools 12.0.5
|
A collection of useful functions. More...
Macros | |
#define | VMTOOLS_GUEST_SERVICE "vmsvc" |
#define | VMTOOLS_USER_SERVICE "vmusr" |
#define | VMTOOLS_EXTERN_C |
#define | ABS(x) (((x) >= 0) ? (x) : -(x)) |
#define | VMTOOLS_GET_FILENAME_LOCAL(path, err) |
#define | VMTOOLS_RELEASE_FILENAME_LOCAL(path) g_free(path) |
#define | VMTOOLS_WRAP_ARRAY(a) VMTools_WrapArray((a), sizeof *(a), G_N_ELEMENTS(a)) |
Typedefs | |
typedef gboolean(* | SignalSourceCb) (const siginfo_t *, gpointer) |
Functions | |
G_BEGIN_DECLS void | vm_free (void *ptr) |
gboolean | VMTools_LoadConfig (const gchar *path, GKeyFileFlags flags, GKeyFile **config, time_t *mtime) |
gboolean | VMTools_AddConfig (GKeyFile *srcConfig, GKeyFile *dstConfig) |
gboolean | VMTools_CompareConfig (GKeyFile *config1, GKeyFile *config2) |
gboolean | VMTools_WriteConfig (const gchar *path, GKeyFile *config, GError **err) |
gboolean | VMTools_ChangeLogFilePath (const gchar *delimiter, const gchar *appendString, const gchar *domain, GKeyFile *conf) |
gboolean | VMTools_ConfigGetBoolean (GKeyFile *config, const gchar *section, const gchar *key, const gboolean defValue) |
gint | VMTools_ConfigGetInteger (GKeyFile *config, const gchar *section, const gchar *key, const gint defValue) |
gchar * | VMTools_ConfigGetString (GKeyFile *config, const gchar *section, const gchar *key, const gchar *defValue) |
GSource * | VMTools_NewSignalSource (int signum) |
gchar * | VMTools_GetLibdir (void) |
GSource * | VMTools_CreateTimer (gint timeout) |
Create a timer based on a monotonic clock source. More... | |
void | VMTools_AcquireLogStateLock (void) |
void | VMTools_ReleaseLogStateLock (void) |
gchar * | VMTools_GetTimeAsString (void) |
void | VMTools_SuspendLogIO (void) |
void | VMTools_ResumeLogIO (void) |
GArray * | VMTools_WrapArray (gconstpointer data, guint elemSize, guint count) |
A collection of useful functions.
This module contains functions for loading configuration data and extensions to the glib API that are useful when writing applications.
#define VMTOOLS_GET_FILENAME_LOCAL | ( | path, | |
err | |||
) |
Converts an UTF-8 path to the local (i.e., glib) file name encoding. This is a no-op on Windows, since the local encoding is always UTF-8 in glib. The returned value should not be freed directly; instead, use VMTOOLS_RELEASE_FILENAME_LOCAL.
[in] | path | Path in UTF-8 (should not be NULL). |
[out] | err | Where to store errors (type: GError **; may be NULL). |
#define VMTOOLS_RELEASE_FILENAME_LOCAL | ( | path | ) | g_free(path) |
Frees a path allocated with VMTOOLS_GET_FILENAME_LOCAL. No-op on Windows.
[in] | path | Path in UTF-8. |
#define VMTOOLS_WRAP_ARRAY | ( | a | ) | VMTools_WrapArray((a), sizeof *(a), G_N_ELEMENTS(a)) |
Convenience macro around VMTools_WrapArray.
typedef gboolean(* SignalSourceCb) (const siginfo_t *, gpointer) |
Type of callback used by the signal event source.
G_BEGIN_DECLS void vm_free | ( | void * | ptr | ) |
Frees a pointer allocated by the vmtools library.
[in] | ptr | Pointer to memory to be freed. |
void VMTools_AcquireLogStateLock | ( | void | ) |
Acquire the log state lock.
gboolean VMTools_AddConfig | ( | GKeyFile * | srcConfig, |
GKeyFile * | dstConfig | ||
) |
Copies the key/value pairs from one config dictionary to another config dictionary. The key/value pairs are added only if they are not already present in the destination configuration dictionary.
[in] | srcConfig | Configuration dictionary from which the key/value pairs should be added. |
[in] | dstConfig | Configuration dictionary to which the key/value pairs should be added.. |
gboolean VMTools_ChangeLogFilePath | ( | const gchar * | delimiter, |
const gchar * | appendString, | ||
const gchar * | domain, | ||
GKeyFile * | conf | ||
) |
This function gets the log file location given in the config file and appends the string provided just before the delimiter specified. If more than one delimiter is present in the string, it appends just before the first delimiter. If the delimiter does not exist in the location, the string provided is appended at the end of the location.
NOTE: It is up to the caller to free the delimiter and append string.
Example: 1) location - "C:\vmresset.log", delimiter - ".", appendString - "_4" location changed = "C:\vmresset_4.log" 2) location - "C:\vmresset", delimiter - ".", appendString - "_4" location changed = "C:\vmresset_4" 3) location - "C:\vmresset.log.log", delimiter - ".", appendString - "_4" location changed = "C:\vmresset_4.log.log"
Results: TRUE if log file location is changed, FALSE otherwise.
Side effects: Appends a string into the log file location.
gboolean VMTools_CompareConfig | ( | GKeyFile * | config1, |
GKeyFile * | config2 | ||
) |
Compares two configuration dictionaries. Compares all the groups and key/value pairs in both the configuration dictionaries. If all the entries are same, TRUE is returned. Else, FALSE is returned.
[in] | config1 | First configuration dictionary to compare. |
[in] | config2 | Second configuration dictionary to compare. |
gboolean VMTools_ConfigGetBoolean | ( | GKeyFile * | config, |
const gchar * | section, | ||
const gchar * | key, | ||
const gboolean | defValue | ||
) |
Loads boolean value for a key from the specified config section.
[in] | config | Config file to read the key from. |
[in] | section | Section to look for in the config file. |
[in] | key | Key to look for in the section. |
[in] | defValue | Default value if the key is not found or error. |
gint VMTools_ConfigGetInteger | ( | GKeyFile * | config, |
const gchar * | section, | ||
const gchar * | key, | ||
const gint | defValue | ||
) |
Loads integer value for a key from the specified config section.
[in] | config | Config file to read the key from. |
[in] | section | Section to look for in the config file. |
[in] | key | Key to look for in the section. |
[in] | defValue | Default value if the key is not found or error. |
gchar* VMTools_ConfigGetString | ( | GKeyFile * | config, |
const gchar * | section, | ||
const gchar * | key, | ||
const gchar * | defValue | ||
) |
Loads string value for a key from the specified config section.
[in] | config | Config file to read the key from. |
[in] | section | Section to look for in the config file. |
[in] | key | Key to look for in the section. |
[in] | defValue | Default value if the key is not found or error. |
GSource * VMTools_CreateTimer | ( | gint | timeout | ) |
Create a timer based on a monotonic clock source.
This timer differs from the glib timeout source, which uses the system time. It is recommended for code that needs more reliable time tracking, using a clock that is not affected by changes in the system time (which can happen when using NTP or the Tools time synchronization feature).
[in] | timeout | The timeout for the timer, must be >= 0. |
gchar* VMTools_GetTimeAsString | ( | void | ) |
VMTools_GetTimeAsString –
Returns the current UTC timestamp information
Ex: "2018-02-22T21:17:38.517Z"
The caller must free the return value using g_free
gboolean VMTools_LoadConfig | ( | const gchar * | path, |
GKeyFileFlags | flags, | ||
GKeyFile ** | config, | ||
time_t * | mtime | ||
) |
Loads the configuration file at the given path.
[in] | path | Path to the configuration file, or NULL for default Tools config file. |
[in] | flags | Flags for opening the file. |
[in,out] | config | Where to store the config dictionary; when reloading the file, the old config object will be destroyed. |
[in,out] | mtime | Last known modification time of the config file. When the function succeeds, will contain the new modification time read from the file. If NULL (or 0), the config dictionary is always loaded. |
GSource * VMTools_NewSignalSource | ( | int | signum | ) |
Creates a new source for the given signal.
Rather than processing the events in the signal handling context, the main loop is woken up and callbacks are processed in the main loop's thread.
The same "wakeup" file descriptors are used for all sources, so if sources are added to different main loop instances, all of them will be woken up if any signal for which handlers are registered occurs.
This code assumes that the rest of the app is not setting signal handlers directly, at least for signals for which glib sources have been set up.
Also note that on older Linux systems (pre-NPTL), some real-time signals are used by the pthread library and shouldn't be used by applications.
Example of setting a handler for a signal:
[in] | signum | Signal to watch. |
void VMTools_ReleaseLogStateLock | ( | void | ) |
Release the log state lock.
void VMTools_ResumeLogIO | ( | void | ) |
Resume IO caused by logging activity.
void VMTools_SuspendLogIO | ( | void | ) |
Suspend IO caused by logging activity.
GArray* VMTools_WrapArray | ( | gconstpointer | data, |
guint | elemSize, | ||
guint | count | ||
) |
A convenience function for wrapping an array with a GArray instance.
[in] | data | The array data. The original data is copied into the new array. |
[in] | elemSize | The size of each element in the array. |
[in] | count | The number of elements in the array. |
gboolean VMTools_WriteConfig | ( | const gchar * | path, |
GKeyFile * | config, | ||
GError ** | err | ||
) |
Saves the given config data to the given path.
[in] | path | Where to save the data. |
[in] | config | Config data. |
[out] | err | Where to store error information (may be NULL). |