mirror of https://git.48k.eu/ogserver
schema: fix bug when og_dbi_open cannot open a connection
When og_dbi_open cannot open a connection during schema update, then ogServer crashes. og_dbi_open returns NULL when it cannot open a DB connection. Do not use dbi variable if og_dbi_open is unable to open a DB connection. Add syslog message when database schema couldn't be updated.master
parent
e080fd5526
commit
35a3b0a1a3
|
|
@ -92,8 +92,10 @@ int main(int argc, char *argv[])
|
||||||
ev_io_init(&ev_io_agent_rest, og_server_accept_cb, socket_agent_rest, EV_READ);
|
ev_io_init(&ev_io_agent_rest, og_server_accept_cb, socket_agent_rest, EV_READ);
|
||||||
ev_io_start(og_loop, &ev_io_agent_rest);
|
ev_io_start(og_loop, &ev_io_agent_rest);
|
||||||
|
|
||||||
if (og_dbi_schema_update() < 0)
|
if (og_dbi_schema_update() < 0) {
|
||||||
|
syslog(LOG_ERR, "Cannot update the database schema\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
if (og_dbi_schedule_get() < 0) {
|
if (og_dbi_schedule_get() < 0) {
|
||||||
syslog(LOG_ERR, "Cannot connect to database\n");
|
syslog(LOG_ERR, "Cannot connect to database\n");
|
||||||
|
|
|
||||||
|
|
@ -255,13 +255,11 @@ int og_dbi_schema_update(void)
|
||||||
{
|
{
|
||||||
int version, i, err;
|
int version, i, err;
|
||||||
struct og_dbi *dbi;
|
struct og_dbi *dbi;
|
||||||
const char *msglog;
|
|
||||||
|
|
||||||
dbi = og_dbi_open(&ogconfig.db);
|
dbi = og_dbi_open(&ogconfig.db);
|
||||||
if (!dbi) {
|
if (!dbi) {
|
||||||
dbi_conn_error(dbi->conn, &msglog);
|
syslog(LOG_ERR, "cannot open a database connection (%s:%d)\n",
|
||||||
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
|
__func__, __LINE__);
|
||||||
__func__, __LINE__, msglog);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue