summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-10-22 23:18:47 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-10-23 00:18:47 -0400
commit9ce998b93770708ce992b53e93c3c7781ec9a8a2 (patch)
tree2af362c58d24d55fa4603086d088e11c6d1c3468 /src
parent50a0b0717563d08c027a16a896bff8d7754eab9e (diff)
journal-remote: better error message on failure
Return a proper code instead of simply NULL for failure.
Diffstat (limited to 'src')
-rw-r--r--src/journal-remote/journal-remote.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
index d78607c541..d94b2afc00 100644
--- a/src/journal-remote/journal-remote.c
+++ b/src/journal-remote/journal-remote.c
@@ -449,33 +449,32 @@ static int setup_raw_socket(RemoteServer *s, const char *address) {
**********************************************************************
**********************************************************************/
-static RemoteSource *request_meta(void **connection_cls, int fd, char *hostname) {
+static int request_meta(void **connection_cls, int fd, char *hostname) {
RemoteSource *source;
Writer *writer;
int r;
assert(connection_cls);
if (*connection_cls)
- return *connection_cls;
+ return 0;
r = get_writer(server, hostname, &writer);
if (r < 0) {
log_warning("Failed to get writer for source %s: %s",
hostname, strerror(-r));
- return NULL;
+ return r;
}
source = source_new(fd, true, hostname, writer);
if (!source) {
- log_oom();
writer_unref(writer);
- return NULL;
+ return log_oom();
}
log_debug("Added RemoteSource as connection metadata %p", source);
*connection_cls = source;
- return source;
+ return 0;
}
static void request_meta_free(void *cls,
@@ -487,9 +486,11 @@ static void request_meta_free(void *cls,
assert(connection_cls);
s = *connection_cls;
- log_debug("Cleaning up connection metadata %p", s);
- source_free(s);
- *connection_cls = NULL;
+ if (s) {
+ log_debug("Cleaning up connection metadata %p", s);
+ source_free(s);
+ *connection_cls = NULL;
+ }
}
static int process_http_upload(
@@ -622,8 +623,13 @@ static int request_handler(
assert(hostname);
- if (!request_meta(connection_cls, fd, hostname))
+ r = request_meta(connection_cls, fd, hostname);
+ if (r == -ENOMEM)
return respond_oom(connection);
+ else if (r < 0)
+ return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
+ strerror(-r));
+
hostname = NULL;
return MHD_YES;
}