summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c73181f)
raw | patch | inline | side by side (parent: c73181f)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 28 Nov 2013 17:28:26 +0000 (18:28 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 28 Nov 2013 17:28:26 +0000 (18:28 +0100) |
Keep track of the latest error in a connection object and report that back to
the client in case a command handler failed.
the client in case a command handler failed.
src/frontend/connection.c | patch | blob | history | |
src/frontend/query.c | patch | blob | history | |
src/include/frontend/connection-private.h | patch | blob | history |
index 21bca4f28e1046a570c202f03eed89ed019e17a9..962cd9cf8d9a14f9a3bc2f2a864e993958eb467d 100644 (file)
"for a new connection");
return -1;
}
+ conn->errbuf = sdb_strbuf_create(0);
+ if (! conn->errbuf) {
+ sdb_log(SDB_LOG_ERR, "frontend: Failed to allocate an error buffer "
+ "for a new connection");
+ return -1;
+ }
conn->client_addr_len = sizeof(conn->client_addr);
conn->fd = accept(sock_fd, (struct sockaddr *)&conn->client_addr,
sdb_strbuf_destroy(conn->buf);
conn->buf = NULL;
+ sdb_strbuf_destroy(conn->errbuf);
+ conn->errbuf = NULL;
} /* connection_destroy */
static sdb_type_t connection_type = {
sdb_log(SDB_LOG_DEBUG, "frontend: Handling command %u (len: %u)",
conn->cmd, conn->cmd_len);
+ /* reset */
+ sdb_strbuf_sprintf(conn->errbuf, "");
+
switch (conn->cmd) {
case CONNECTION_PING:
status = sdb_connection_ping(conn);
default:
{
- char errbuf[1024];
sdb_log(SDB_LOG_WARNING, "frontend: Ignoring invalid command");
- snprintf(errbuf, sizeof(errbuf), "Invalid command %#x", conn->cmd);
- sdb_connection_send(conn, CONNECTION_ERROR,
- (uint32_t)(strlen(errbuf) + 1), errbuf);
+ sdb_strbuf_sprintf(conn->errbuf, "Invalid command %#x", conn->cmd);
status = -1;
break;
}
}
+ if (status)
+ sdb_connection_send(conn, CONNECTION_ERROR,
+ (uint32_t)sdb_strbuf_len(conn->errbuf),
+ sdb_strbuf_string(conn->errbuf));
+
/* remove the command from the buffer */
if (conn->cmd_len)
sdb_strbuf_skip(conn->buf, conn->cmd_len);
diff --git a/src/frontend/query.c b/src/frontend/query.c
index 9e3b66a3a5c2b55579dccb5fdc4741631930e95d..fa493a6dd04be5a8139c0cae0485d2bea43703c6 100644 (file)
--- a/src/frontend/query.c
+++ b/src/frontend/query.c
"buffer to handle LIST command: %s",
sdb_strerror(errno, errbuf, sizeof(errbuf)));
- /* XXX: send error message */
- sdb_connection_send(conn, CONNECTION_ERROR, 0, NULL);
+ sdb_strbuf_sprintf(conn->errbuf, "Out of memory");
sdb_strbuf_destroy(buf);
return -1;
}
if (sdb_store_tojson(buf)) {
sdb_log(SDB_LOG_ERR, "frontend: Failed to serialize "
"store to JSON");
- sdb_connection_send(conn, CONNECTION_ERROR, 0, NULL);
+ sdb_strbuf_sprintf(conn->errbuf, "Out of memory");
sdb_strbuf_destroy(buf);
return -1;
}
index d484a0863e8a670e8a8a69a9679c008f8b58b418..6cf7395b7c122b0c5c329c622be47745f71f5bb3 100644 (file)
uint32_t cmd;
uint32_t cmd_len;
+ sdb_strbuf_t *errbuf;
+
/* user information */
char *username; /* NULL if the user has not been authenticated */
};