Misc. Functions

Misc. Functions — Utility functions that do not really fit anywhere else

Synopsis


#include <monitor/monitor.h>


#define     MON_ALEN                        (ary)
void        mon_timediff                    (const struct timeval *end,
                                             const struct timeval *begin,
                                             struct timeval *result);
int         mon_check_rate                  (struct timeval *last_update,
                                             const struct timeval *min_delay,
                                             int update);
const char* mon_env_opt_value               (const char *name);
#define     MON_ENV_VAR
int         mon_issetugid                   (void);
const char* mon_errstr                      (int error);
char**      mon_strappendv                  (char **strv,
                                             const char *str);
size_t      mon_strlen                      (const char *str);
int         mon_open_ptypair                (int *master_fd,
                                             char **slave_name);
void        mon_cleanup                     (void);

Description

Details

MON_ALEN()

#define MON_ALEN(ary)		(sizeof(ary) / sizeof(ary[0]))

Returns the number of elements of an array.

ary :the name of an array.

mon_timediff ()

void        mon_timediff                    (const struct timeval *end,
                                             const struct timeval *begin,
                                             struct timeval *result);

Computes the difference of two struct timeval structures.

end :the end timestamp.
begin :the begin timestamp.
result :a struct timeval to store the difference.

mon_check_rate ()

int         mon_check_rate                  (struct timeval *last_update,
                                             const struct timeval *min_delay,
                                             int update);

Provides rate control.

last_update :timestamp of the last allowed event.
min_delay :minimum delay between allowed events.
update :if TRUE, last_update will be set to the current time if this event is allowed.
Returns :TRUE if at least min_delay has passed since last_update.

mon_env_opt_value ()

const char* mon_env_opt_value               (const char *name);

Returns the value of a named token in the MON_ENV_VAR environment variable.

name :the name of a token.
Returns :the value of the token.

MON_ENV_VAR

#define MON_ENV_VAR		"MERCURY_OPTIONS"

The name of the environment variable used by mon_env_opt_value(). The variable may contain a comma-separated list of tokens. If the token contains an equal sign ('='), the name of the token is the string before the equal sign, and the value of the token is the string after the equal sign. If the token does not contain an equal sign the value of the token is the empty string.


mon_issetugid ()

int         mon_issetugid                   (void);

Checks if the process was started with extra privileges.

Returns :TRUE if the process was started with extra privileges.

mon_errstr ()

const char* mon_errstr                      (int error);

Converts a monitoring system error code to a string. This function extends strerror().

error :an error code.
Returns :textual description of the error.

mon_strappendv ()

char**      mon_strappendv                  (char **strv,
                                             const char *str);

Appends a new string to a NULL-terminated array of strings. Returns the new address of the array if successful, or NULL if there was not enough free memory.

strv :a NULL-terminated array of strings.
str :the string to append.
Returns :the new address of the array or NULL if out of memory.

mon_strlen ()

size_t      mon_strlen                      (const char *str);

Wraper around strlen() that also accepts NULL.

str :a string.
Returns :the length of the string or 0 if str is NULL.

mon_open_ptypair ()

int         mon_open_ptypair                (int *master_fd,
                                             char **slave_name);

Opens a master/slave pseudo-tty pair. Returns a file descriptor for the master side and the filename of the slave side.

master_fd :pointer to store the master file descriptor.
slave_name :pointer to store the filename of the slave device. Must be freed by the caller using g_free().
Returns :0 if successful or an error code.

mon_cleanup ()

void        mon_cleanup                     (void);

Deallocates any resources that the libmonitor library have allocated internally.