Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ipc url && pid_file configurable && fixed nanomq reload memory leak. #1045

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/nng/supplemental/nanolib/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ typedef enum {

struct conf {
char *vin;
char *cmd_ipc_url;
char *hook_ipc_url;
char *conf_file;
char *url;
bool enable;
Expand Down
2 changes: 2 additions & 0 deletions include/nng/supplemental/nanolib/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
#define NANOMQ_CONF_PATH "NANOMQ_CONF_PATH"

#define NANOMQ_VIN "NANOMQ_VIN"
#define NANOMQ_PID_FILE "NANOMQ_PID_FILE"

NNG_DECL void read_env_conf(conf *config);
NNG_DECL char *read_env_vin();
NNG_DECL char *read_env_pid_file();

#endif
65 changes: 62 additions & 3 deletions src/supplemental/nanolib/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,11 @@ conf_http_server_destroy(conf_http_server *http)
void
conf_init(conf *nanomq_conf)
{
nanomq_conf->vin = NULL;
nanomq_conf->url = NULL;
nanomq_conf->conf_file = NULL;
nanomq_conf->vin = NULL;
nanomq_conf->hook_ipc_url = NULL;
nanomq_conf->cmd_ipc_url = NULL;
nanomq_conf->url = NULL;
nanomq_conf->conf_file = NULL;

#if defined(SUPP_RULE_ENGINE)
conf_rule_init(&nanomq_conf->rule_eng);
Expand Down Expand Up @@ -3921,6 +3923,42 @@ conf_sqlite_destroy(conf_sqlite *sqlite)
}
}

static void
conf_exchange_node_destory(conf_exchange_node *node)
{
if (node) {
nng_strfree(node->exchange_url);
nng_strfree(node->topic);
nng_strfree(node->name);
nng_mtx_free(node->mtx);
for (int i = 0; i < node->rbufs_sz; i++) {
if (node->rbufs[i]) {
nng_strfree(node->rbufs[i]->name);
NNI_FREE_STRUCT(node->rbufs[i]);
}
}

cvector_free(node->rbufs);
NNI_FREE_STRUCT(node);
}

}

static void
conf_exchange_destroy(conf_exchange *exchange)
{
for (int i = 0; i < exchange->count; i++) {
conf_exchange_node *node = exchange->nodes[i];
conf_exchange_node_destory(node);
}

if (exchange->encryption) {
nng_strfree(exchange->encryption->key);
NNI_FREE_STRUCT(exchange->encryption);
}
cvector_free(exchange->nodes);
}

#if defined(SUPP_RULE_ENGINE)
static void
conf_rule_destroy(conf_rule *re)
Expand Down Expand Up @@ -3974,12 +4012,29 @@ conf_tlslist_destroy(conf_tls_list *tlslist)
tlslist->nodes = NULL;
}
}
conf_parquet_destroy(conf_parquet *parquet)
{
if (parquet) {
nng_strfree(parquet->dir);
nng_strfree(parquet->file_name_prefix);

if (parquet->encryption.enable) {
nng_strfree(parquet->encryption.key);
nng_strfree(parquet->encryption.key_id);
}
}

}

void
conf_fini(conf *nanomq_conf)
{
nng_strfree(nanomq_conf->url);
nng_strfree(nanomq_conf->conf_file);
if (nanomq_conf->vin)
nng_strfree(nanomq_conf->vin);
nng_strfree(nanomq_conf->hook_ipc_url);
nng_strfree(nanomq_conf->cmd_ipc_url);
nng_strfree(nanomq_conf->websocket.tls_url);

conf_http_server_destroy(&nanomq_conf->http_server);
Expand All @@ -3999,12 +4054,16 @@ conf_fini(conf *nanomq_conf)
conf_web_hook_destroy(&nanomq_conf->web_hook);
conf_auth_http_destroy(&nanomq_conf->auth_http);
conf_auth_destroy(&nanomq_conf->auths);
conf_exchange_destroy(&nanomq_conf->exchange);
#if defined(ENABLE_LOG)
conf_log_destroy(&nanomq_conf->log);
#endif

conf_tcplist_destroy(&nanomq_conf->tcp_list);
conf_tlslist_destroy(&nanomq_conf->tls_list);

#if defined(SUPP_PARQUET)
conf_parquet_destroy(&nanomq_conf->parquet);
#endif
free(nanomq_conf);
}
2 changes: 2 additions & 0 deletions src/supplemental/nanolib/conf_ver2.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ conf_basic_parse_ver2(conf *config, cJSON *jso)
hocon_read_num(config, parallel, jso_sys);
hocon_read_bool_base(
config, ipc_internal, "enable_ipc_internal", jso_sys);
hocon_read_str(config, hook_ipc_url, jso_sys);
hocon_read_str(config, cmd_ipc_url, jso_sys);
}

#ifdef ACL_SUPP
Expand Down
7 changes: 7 additions & 0 deletions src/supplemental/nanolib/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ read_env_vin()
return env_vin;
}

char *
read_env_pid_file()
{
char *pid_file = NULL;
set_string_var(&pid_file, NANOMQ_PID_FILE);
return pid_file;
}

void
read_env_conf(conf *config)
Expand Down
Loading