summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-10-24 07:44:26 +0000
committerChristian Grothoff <christian@grothoff.org>2016-10-24 07:44:26 +0000
commitb81008870d47cfb342bc2a689718fd03eee10cd4 (patch)
tree04fa93931f8bed6c0a3d4089e26f396d4c6df846
parent10f9bc91ab9d758d0d60dd672206027cd136342a (diff)
downloadgnunet-b81008870d47cfb342bc2a689718fd03eee10cd4.tar.gz
gnunet-b81008870d47cfb342bc2a689718fd03eee10cd4.zip
put logging into place to diagnose #4737
-rw-r--r--src/postgres/postgres.c58
-rw-r--r--src/pq/pq.c3
2 files changed, 47 insertions, 14 deletions
diff --git a/src/postgres/postgres.c b/src/postgres/postgres.c
index 4c8b2b046..f286ff705 100644
--- a/src/postgres/postgres.c
+++ b/src/postgres/postgres.c
@@ -54,14 +54,22 @@ GNUNET_POSTGRES_check_result_ (PGconn *dbh,
54 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 54 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
55 "postgres", 55 "postgres",
56 "Postgres failed to allocate result for `%s:%s' at %s:%d\n", 56 "Postgres failed to allocate result for `%s:%s' at %s:%d\n",
57 command, args, filename, line); 57 command,
58 args,
59 filename,
60 line);
58 return GNUNET_SYSERR; 61 return GNUNET_SYSERR;
59 } 62 }
60 if (PQresultStatus (ret) != expected_status) 63 if (PQresultStatus (ret) != expected_status)
61 { 64 {
62 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 65 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
63 "postgres", _("`%s:%s' failed at %s:%d with error: %s\n"), 66 "postgres",
64 command, args, filename, line, PQerrorMessage (dbh)); 67 _("`%s:%s' failed at %s:%d with error: %s\n"),
68 command,
69 args,
70 filename,
71 line,
72 PQerrorMessage (dbh));
65 PQclear (ret); 73 PQclear (ret);
66 return GNUNET_SYSERR; 74 return GNUNET_SYSERR;
67 } 75 }
@@ -86,10 +94,21 @@ GNUNET_POSTGRES_exec_ (PGconn * dbh,
86{ 94{
87 PGresult *ret; 95 PGresult *ret;
88 96
89 ret = PQexec (dbh, sql); 97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
98 "Executing SQL statement `%s' at %s:%d\n",
99 sql,
100 filename,
101 line);
102 ret = PQexec (dbh,
103 sql);
90 if (GNUNET_OK != 104 if (GNUNET_OK !=
91 GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQexec", sql, 105 GNUNET_POSTGRES_check_result_ (dbh,
92 filename, line)) 106 ret,
107 PGRES_COMMAND_OK,
108 "PQexec",
109 sql,
110 filename,
111 line))
93 return GNUNET_SYSERR; 112 return GNUNET_SYSERR;
94 PQclear (ret); 113 PQclear (ret);
95 return GNUNET_OK; 114 return GNUNET_OK;
@@ -117,6 +136,12 @@ GNUNET_POSTGRES_prepare_ (PGconn *dbh,
117{ 136{
118 PGresult *ret; 137 PGresult *ret;
119 138
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
140 "Preparing SQL statement `%s' as `%s' at %s:%d\n",
141 sql,
142 name,
143 filename,
144 line);
120 ret = PQprepare (dbh, 145 ret = PQprepare (dbh,
121 name, 146 name,
122 sql, 147 sql,
@@ -151,7 +176,10 @@ GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle * cfg,
151 176
152 /* Open database and precompile statements */ 177 /* Open database and precompile statements */
153 if (GNUNET_OK != 178 if (GNUNET_OK !=
154 GNUNET_CONFIGURATION_get_value_string (cfg, section, "CONFIG", &conninfo)) 179 GNUNET_CONFIGURATION_get_value_string (cfg,
180 section,
181 "CONFIG",
182 &conninfo))
155 conninfo = NULL; 183 conninfo = NULL;
156 dbh = PQconnectdb (conninfo == NULL ? "" : conninfo); 184 dbh = PQconnectdb (conninfo == NULL ? "" : conninfo);
157 GNUNET_free_non_null (conninfo); 185 GNUNET_free_non_null (conninfo);
@@ -162,7 +190,8 @@ GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle * cfg,
162 } 190 }
163 if (PQstatus (dbh) != CONNECTION_OK) 191 if (PQstatus (dbh) != CONNECTION_OK)
164 { 192 {
165 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "postgres", 193 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
194 "postgres",
166 _("Unable to initialize Postgres: %s\n"), 195 _("Unable to initialize Postgres: %s\n"),
167 PQerrorMessage (dbh)); 196 PQerrorMessage (dbh));
168 PQfinish (dbh); 197 PQfinish (dbh);
@@ -192,12 +221,13 @@ GNUNET_POSTGRES_delete_by_rowid (PGconn * dbh,
192 const int paramFormats[] = { 1 }; 221 const int paramFormats[] = { 1 };
193 PGresult *ret; 222 PGresult *ret;
194 223
195 ret = 224 ret = PQexecPrepared (dbh,
196 PQexecPrepared (dbh, stmt, 1, 225 stmt,
197 paramValues, 226 1,
198 paramLengths, 227 paramValues,
199 paramFormats, 228 paramLengths,
200 1); 229 paramFormats,
230 1);
201 if (GNUNET_OK != 231 if (GNUNET_OK !=
202 GNUNET_POSTGRES_check_result_ (dbh, ret, 232 GNUNET_POSTGRES_check_result_ (dbh, ret,
203 PGRES_COMMAND_OK, 233 PGRES_COMMAND_OK,
diff --git a/src/pq/pq.c b/src/pq/pq.c
index 46463a190..f4bab4e00 100644
--- a/src/pq/pq.c
+++ b/src/pq/pq.c
@@ -85,6 +85,9 @@ GNUNET_PQ_exec_prepared (PGconn *db_conn,
85 off += x->num_params; 85 off += x->num_params;
86 } 86 }
87 GNUNET_assert (off == len); 87 GNUNET_assert (off == len);
88 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
89 "Executing prepared SQL statement `%s'\n",
90 name);
88 res = PQexecPrepared (db_conn, 91 res = PQexecPrepared (db_conn,
89 name, 92 name,
90 len, 93 len,