Skip to content

Commit

Permalink
Fix error in database initialization
Browse files Browse the repository at this point in the history
Segmentation fault in database initialization process if MySQL server
down.
  • Loading branch information
borisershov committed Mar 14, 2018
1 parent 5f7e277 commit 770ddeb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 0 additions & 5 deletions src/collections/mysql/mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,13 @@ nxs_chat_srv_err_t nxs_chat_srv_c_mysql_connect(nxs_mysql_t *mysql)

nxs_log_write_error(&process, "[%s]: MySQL init error: \"%s\"", nxs_proc_get_name(&process), (char *)mysql->err_str);

nxs_mysql_free(mysql);

return NXS_CHAT_SRV_E_ERR;
}

if(nxs_mysql_connect(mysql) != NXS_MYSQL_E_OK) {

nxs_log_write_error(&process, "[%s]: MySQL connect error: \"%s\"", nxs_proc_get_name(&process), mysql->err_str);

nxs_mysql_disconnect(mysql);
nxs_mysql_free(mysql);

return NXS_CHAT_SRV_E_ERR;
}

Expand Down
9 changes: 8 additions & 1 deletion src/proc/setup/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ static nxs_chat_srv_err_t nxs_chat_srv_p_setup_create_mysql_tables(void)
}
else {

nxs_log_write_console(&process, "create MySQL tables fail: %r", &err_str);
if(nxs_string_len(&err_str) == 0) {

nxs_log_write_console(&process, "create MySQL tables fail (see logs for more details)");
}
else {

nxs_log_write_console(&process, "create MySQL tables fail: %r", &err_str);
}
}

nxs_string_free(&err_str);
Expand Down
8 changes: 4 additions & 4 deletions src/units/db-ids/db-ids.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ nxs_chat_srv_err_t nxs_chat_srv_u_db_ids_set_tlgrm(nxs_chat_srv_u_db_ids_t *u_ct
tlgrm_username,
rdmn_userid);

nxs_error(rc, NXS_CHAT_SRV_E_ERR, error);
rc = NXS_CHAT_SRV_E_ERR;
}
}
else {
Expand All @@ -222,7 +222,7 @@ nxs_chat_srv_err_t nxs_chat_srv_u_db_ids_set_tlgrm(nxs_chat_srv_u_db_ids_t *u_ct
tlgrm_username,
rdmn_userid);

nxs_error(rc, NXS_CHAT_SRV_E_ERR, error);
rc = NXS_CHAT_SRV_E_ERR;
}
}

Expand Down Expand Up @@ -296,7 +296,7 @@ nxs_chat_srv_err_t nxs_chat_srv_u_db_ids_set_rdmn(nxs_chat_srv_u_db_ids_t *u_ctx
tlgrm_username,
rdmn_userid);

nxs_error(rc, NXS_CHAT_SRV_E_ERR, error);
rc = NXS_CHAT_SRV_E_ERR;
}
}
else {
Expand All @@ -310,7 +310,7 @@ nxs_chat_srv_err_t nxs_chat_srv_u_db_ids_set_rdmn(nxs_chat_srv_u_db_ids_t *u_ctx
tlgrm_username,
rdmn_userid);

nxs_error(rc, NXS_CHAT_SRV_E_ERR, error);
rc = NXS_CHAT_SRV_E_ERR;
}
}

Expand Down

0 comments on commit 770ddeb

Please sign in to comment.