summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2016-02-09 13:45:32 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2016-02-09 13:45:33 -0600
commitcf89aecc8a9aa9bffeac2ee0ae2bd3781d0ec347 (patch)
treedd6f6c50ca0c09555e2a49342c3f70c30ab2833d
parente40fddbeb5dbc4f557a6c215eb211091f2fe3161 (diff)
parent72bf53eea5b5220e537f9895192ba5cf5173bddb (diff)
Merge "res_config_pgsql: Add message on cli failed command status"
-rw-r--r--res/res_config_pgsql.c35
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;
}
}