Skip to content

Commit

Permalink
lib: Add function to see if lib is initialized
Browse files Browse the repository at this point in the history
This is needed by test-lib to prevent double init/deinit.
  • Loading branch information
cmouse committed Oct 31, 2016
1 parent b73cfe3 commit 8a20f96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/lib/lib.c
Expand Up @@ -10,6 +10,8 @@
#include <unistd.h>
#include <sys/time.h>

static bool lib_initialized = FALSE;

struct atexit_callback {
int priority;
lib_atexit_callback_t *callback;
Expand Down Expand Up @@ -116,6 +118,7 @@ void lib_atexit_run(void)
void lib_init(void)
{
struct timeval tv;
i_assert(!lib_initialized);

/* standard way to get rand() return different values. */
if (gettimeofday(&tv, NULL) < 0)
Expand All @@ -124,10 +127,18 @@ void lib_init(void)

data_stack_init();
hostpid_init();
lib_initialized = TRUE;
}

bool lib_is_initialized(void)
{
return lib_initialized;
}

void lib_deinit(void)
{
i_assert(lib_initialized);
lib_initialized = FALSE;
lib_atexit_run();
ipwd_deinit();
hostpid_deinit();
Expand Down
1 change: 1 addition & 0 deletions src/lib/lib.h
Expand Up @@ -76,6 +76,7 @@ void lib_atexit_priority(lib_atexit_callback_t *callback, int priority);
void lib_atexit_run(void);

void lib_init(void);
bool lib_is_initialized(void);
void lib_deinit(void);

#endif

0 comments on commit 8a20f96

Please sign in to comment.