[Asterisk-code-review] res config pgsql: Add message on cli failed command status (asterisk[master])

Rodrigo Ramirez Norambuena asteriskteam at digium.com
Tue Feb 9 11:40:16 CST 2016


Rodrigo Ramirez Norambuena has uploaded a new change for review.

  https://gerrit.asterisk.org/2219

Change subject: res_config_pgsql: Add message on cli failed command status
......................................................................

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
---
M res/res_config_pgsql.c
1 file changed, 13 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/19/2219/1

diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index 7fe1daa..7597fff 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 at oxymium.net> - PostgreSQL RealTime Driver Author/Adaptor
  * Mark Spencer <markster at digium.com>  - Asterisk Author
@@ -1588,17 +1588,17 @@
 	if (a->argc != 4)
 		return CLI_SHOWUSAGE;
 
+	if (!ast_strlen_zero(dbhost))
+		snprintf(status, sizeof(status), "%s@%s, port %d", dbname, dbhost, dbport);
+	else if (!ast_strlen_zero(dbsock))
+		snprintf(status, sizeof(status), "%s on socket file %s", dbname, dbsock);
+	else
+		snprintf(status, sizeof(status), "%s@%s", dbname, dbhost);
+
+	if (!ast_strlen_zero(dbuser))
+		snprintf(credentials, sizeof(credentials), " with username %s", dbuser);
+
 	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(dbuser))
-			snprintf(credentials, sizeof(credentials), " with username %s", dbuser);
-
 		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,
@@ -1614,10 +1614,11 @@
 			ast_cli(a->fd, "%s%s for %d minutes, %d seconds.\n", status, 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", status, credentials, ctimesec);
 
 		return CLI_SUCCESS;
 	} else {
+		ast_cli(a->fd, "Unable to connect %s%s\n", status, credentials);
 		return CLI_FAILURE;
 	}
 }

-- 
To view, visit https://gerrit.asterisk.org/2219
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia8e9e2400466606e7118f52a46e05df0719b6a29
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Rodrigo Ramirez Norambuena <a at rodrigoramirez.com>



More information about the asterisk-code-review mailing list