diff options
author | Rodrigo Ramírez Norambuena <a@rodrigoramirez.com> | 2016-02-07 16:00:24 -0300 |
---|---|---|
committer | Rodrigo Ramírez Norambuena <a@rodrigoramirez.com> | 2016-02-07 17:08:43 -0300 |
commit | 72bf53eea5b5220e537f9895192ba5cf5173bddb (patch) | |
tree | 40ec353b1a1553fe848d715a9f6209c6de60de1d | |
parent | 4b768281bbfd18f031d1522c17728b3a343411f6 (diff) |
res_config_pgsql: Add message on cli failed command status
In case failed of command "realtime show pgsql status" show a message the data
of connection to more clear information in error.
Change-Id: Ia8e9e2400466606e7118f52a46e05df0719b6a29
-rw-r--r-- | res/res_config_pgsql.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c index 7fe1daa65..d0e01bc8d 100644 --- a/res/res_config_pgsql.c +++ b/res/res_config_pgsql.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999-2010, Digium, Inc. + * Copyright (C) 1999 - 2016, Digium, Inc. * * Manuel Guesdon <mguesdon@oxymium.net> - PostgreSQL RealTime Driver Author/Adaptor * Mark Spencer <markster@digium.com> - Asterisk Author @@ -1571,7 +1571,7 @@ static char *handle_cli_realtime_pgsql_cache(struct ast_cli_entry *e, int cmd, s static char *handle_cli_realtime_pgsql_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - char status[256], credentials[100] = ""; + char connection_info[256], credentials[100] = ""; int ctimesec = time(NULL) - connect_time; switch (cmd) { @@ -1588,36 +1588,37 @@ static char *handle_cli_realtime_pgsql_status(struct ast_cli_entry *e, int cmd, if (a->argc != 4) return CLI_SHOWUSAGE; - if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) { - if (!ast_strlen_zero(dbhost)) - snprintf(status, sizeof(status), "Connected to %s@%s, port %d", dbname, dbhost, dbport); - else if (!ast_strlen_zero(dbsock)) - snprintf(status, sizeof(status), "Connected to %s on socket file %s", dbname, dbsock); - else - snprintf(status, sizeof(status), "Connected to %s@%s", dbname, dbhost); + if (!ast_strlen_zero(dbhost)) + snprintf(connection_info, sizeof(connection_info), "%s@%s, port %d", dbname, dbhost, dbport); + else if (!ast_strlen_zero(dbsock)) + snprintf(connection_info, sizeof(connection_info), "%s on socket file %s", dbname, dbsock); + else + snprintf(connection_info, sizeof(connection_info), "%s@%s", dbname, dbhost); - if (!ast_strlen_zero(dbuser)) - snprintf(credentials, sizeof(credentials), " with username %s", dbuser); + if (!ast_strlen_zero(dbuser)) + snprintf(credentials, sizeof(credentials), " with username %s", dbuser); + if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) { if (ctimesec > 31536000) - ast_cli(a->fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n", - status, credentials, ctimesec / 31536000, (ctimesec % 31536000) / 86400, + ast_cli(a->fd, "Connected to %s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n", + connection_info, credentials, ctimesec / 31536000, (ctimesec % 31536000) / 86400, (ctimesec % 86400) / 3600, (ctimesec % 3600) / 60, ctimesec % 60); else if (ctimesec > 86400) - ast_cli(a->fd, "%s%s for %d days, %d hours, %d minutes, %d seconds.\n", status, + ast_cli(a->fd, "Connected to %s%s for %d days, %d hours, %d minutes, %d seconds.\n", connection_info, credentials, ctimesec / 86400, (ctimesec % 86400) / 3600, (ctimesec % 3600) / 60, ctimesec % 60); else if (ctimesec > 3600) - ast_cli(a->fd, "%s%s for %d hours, %d minutes, %d seconds.\n", status, credentials, + ast_cli(a->fd, "Connected to %s%s for %d hours, %d minutes, %d seconds.\n", connection_info, credentials, ctimesec / 3600, (ctimesec % 3600) / 60, ctimesec % 60); else if (ctimesec > 60) - ast_cli(a->fd, "%s%s for %d minutes, %d seconds.\n", status, credentials, ctimesec / 60, + ast_cli(a->fd, "Connected to %s%s for %d minutes, %d seconds.\n", connection_info, credentials, ctimesec / 60, ctimesec % 60); else - ast_cli(a->fd, "%s%s for %d seconds.\n", status, credentials, ctimesec); + ast_cli(a->fd, "Connected to %s%s for %d seconds.\n", connection_info, credentials, ctimesec); return CLI_SUCCESS; } else { + ast_cli(a->fd, "Unable to connect %s%s\n", connection_info, credentials); return CLI_FAILURE; } } |