Skip to content

Commit 3c6da4b

Browse files
committed
Add argument to installing cdb2api libs, and env var
Signed-off-by: Salil Chandra <[email protected]>
1 parent 32e9109 commit 3c6da4b

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

cdb2api/cdb2api.c

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ void cdb2_protobuf_free(void *allocator_data, void *ptr)
190190
#include <openssl/crypto.h>
191191

192192
static int cdb2_use_env_vars = 1;
193+
static int cdb2_install_set_from_env = 0;
194+
static int cdb2_uninstall_set_from_env = 0;
193195

194196
static int default_type_override_env = 0;
195197

@@ -280,16 +282,16 @@ typedef void (*cdb2_init_t)(void);
280282
#ifndef CDB2_INSTALL_LIBS
281283
#define CDB2_INSTALL_LIBS NULL
282284
#else
283-
extern void CDB2_INSTALL_LIBS(void);
285+
extern void CDB2_INSTALL_LIBS(const char *);
284286
#endif
285-
void (*cdb2_install)(void) = CDB2_INSTALL_LIBS;
287+
void (*cdb2_install)(const char *) = CDB2_INSTALL_LIBS;
286288

287289
#ifndef CDB2_UNINSTALL_LIBS
288290
#define CDB2_UNINSTALL_LIBS NULL
289291
#else
290-
extern void CDB2_UNINSTALL_LIBS(void);
292+
extern void CDB2_UNINSTALL_LIBS(const char *);
291293
#endif
292-
void (*cdb2_uninstall)(void) = CDB2_UNINSTALL_LIBS;
294+
void (*cdb2_uninstall)(const char *) = CDB2_UNINSTALL_LIBS;
293295

294296
#ifndef CDB2_IDENTITY_CALLBACKS
295297
struct cdb2_identity *identity_cb = NULL;
@@ -304,8 +306,14 @@ void (*cdb2_uninstall)(void) = CDB2_UNINSTALL_LIBS;
304306

305307
#if WITH_DL_LIBS
306308
#include <dlfcn.h>
307-
void cdb2_set_install_libs(void (*ptr)(void)) { cdb2_install = ptr; }
308-
void cdb2_set_uninstall_libs(void (*ptr)(void)) { cdb2_uninstall = ptr; }
309+
void cdb2_set_install_libs(void (*ptr)(const char *))
310+
{
311+
cdb2_install = ptr;
312+
}
313+
void cdb2_set_uninstall_libs(void (*ptr)(const char *))
314+
{
315+
cdb2_uninstall = ptr;
316+
}
309317
#endif
310318

311319
pthread_mutex_t cdb2_sockpool_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -1395,6 +1403,18 @@ static void read_comdb2db_environment_cfg(cdb2_hndl_tp *hndl, const char *comdb2
13951403
process_env_var_int("COMDB2_CONFIG_SOCKET_TIMEOUT", &CDB2_SOCKET_TIMEOUT, &cdb2_socket_timeout_set_from_env);
13961404
process_env_var_int("COMDB2_CONFIG_PROTOBUF_SIZE", &CDB2_PROTOBUF_SIZE, &cdb2_protobuf_size_set_from_env);
13971405

1406+
char *arg = getenv("COMDB2_CONFIG_INSTALL_STATIC_LIBS");
1407+
if ((cdb2_install != NULL) && arg != NULL) {
1408+
(*cdb2_install)(arg);
1409+
cdb2_install_set_from_env = 1;
1410+
}
1411+
1412+
arg = getenv("COMDB2_CONFIG_UNINSTALL_STATIC_LIBS");
1413+
if ((cdb2_uninstall != NULL) && arg != NULL) {
1414+
(*cdb2_uninstall)(arg);
1415+
cdb2_uninstall_set_from_env = 1;
1416+
}
1417+
13981418
have_read_env = 1;
13991419
}
14001420

@@ -1564,15 +1584,20 @@ static void read_comdb2db_cfg(cdb2_hndl_tp *hndl, SBUF2 *s, const char *comdb2db
15641584
if (tok) {
15651585
cdb2_allow_pmux_route = value_on_off(tok, &err, 1);
15661586
}
1567-
} else if ((strcasecmp("uninstall_static_libs_v2", tok) == 0 ||
1568-
strcasecmp("disable_static_libs", tok) == 0)) {
1587+
} else if (!cdb2_uninstall_set_from_env && (strcasecmp("uninstall_static_libs_v4", tok) == 0 ||
1588+
strcasecmp("disable_static_libs", tok) == 0)) {
15691589
/* Provide a way to disable statically installed (via
15701590
* CDB2_INSTALL_LIBS) libraries. */
1591+
tok = strtok_r(NULL, " :,", &last);
15711592
if (cdb2_uninstall != NULL)
1572-
(*cdb2_uninstall)();
1573-
} else if ((strcasecmp("install_static_libs_v2", tok) == 0 || strcasecmp("enable_static_libs", tok) == 0)) {
1593+
(*cdb2_uninstall)(tok);
1594+
} else if (!cdb2_install_set_from_env &&
1595+
(strcasecmp("install_static_libs_v4", tok) == 0 || strcasecmp("enable_static_libs", tok) == 0)) {
1596+
/* Provide a way to enable statically installed (via
1597+
* CDB2_INSTALL_LIBS) libraries. */
1598+
tok = strtok_r(NULL, " :,", &last);
15741599
if (cdb2_install != NULL)
1575-
(*cdb2_install)();
1600+
(*cdb2_install)(tok);
15761601
#if WITH_DL_LIBS
15771602
} else if (strcasecmp("lib", tok) == 0) {
15781603
tok = strtok_r(NULL, " :,", &last);

cdb2api/cdb2api_int.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ void cdb2_socket_pool_donate_ext(cdb2_hndl_tp *hndl, const char *typestr, int fd
3030
int cdb2_send_2pc(cdb2_hndl_tp *hndl, char *dbname, char *pname, char *ptier, char *source, unsigned int op,
3131
char *dist_txnid, int rcode, int outrc, char *errmsg, int async);
3232

33+
#ifndef WITH_DL_LIBS
34+
#define WITH_DL_LIBS 0
35+
#endif
36+
37+
#if WITH_DL_LIBS
38+
void cdb2_set_install_libs(void (*ptr)(const char *));
39+
void cdb2_set_uninstall_libs(void (*ptr)(const char *));
40+
#endif
41+
3342
#endif

tests/tools/api_libs.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33
#include <cdb2api.h>
4-
5-
typedef void (lib_cb)(void);
6-
void cdb2_set_install_libs(lib_cb *);
7-
void cdb2_set_uninstall_libs(lib_cb *);
4+
#define WITH_DL_LIBS 1
5+
#include <cdb2api_int.h>
86

97
static void *my_open_hook(cdb2_hndl_tp *hndl, void *user_arg, int argc, void **argv)
108
{
@@ -15,7 +13,7 @@ static void *my_open_hook(cdb2_hndl_tp *hndl, void *user_arg, int argc, void **a
1513
static cdb2_event *e;
1614

1715
static int inited = 0;
18-
void gbl_init_once(void)
16+
void gbl_init_once(const char *unused)
1917
{
2018
if (inited)
2119
return;
@@ -25,7 +23,7 @@ void gbl_init_once(void)
2523
inited = 1;
2624
}
2725

28-
void gbl_uninit(void)
26+
void gbl_uninit(const char *unused)
2927
{
3028
if (!inited)
3129
return;

0 commit comments

Comments
 (0)