summaryrefslogtreecommitdiff
path: root/server/src/journal_commit.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/journal_commit.cc')
-rw-r--r--server/src/journal_commit.cc17
1 files changed, 13 insertions, 4 deletions
diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc
index b1ae866..c10e8c7 100644
--- a/server/src/journal_commit.cc
+++ b/server/src/journal_commit.cc
@@ -26,6 +26,8 @@
*/
#include "journal_commit.h"
+#include <config.h>
+
// for gethostbyname
#include <netdb.h>
@@ -48,18 +50,22 @@ static int mwrite(int sock, const char *fmt, ...)
va_list args;
char *buffer;
- buffer = (char*)malloc(64*1024);
+ buffer = (char*)calloc(64*1024, 1);
va_start(args, fmt);
l = vsnprintf(buffer, 64*1024, fmt, args);
va_end(args);
- if(write(sock, buffer, l) != l) {
+ if(sock != -1 && write(sock, buffer, l) != l) {
fprintf(stderr, "write did not write all the bytes in the buffer.\n");
}
free(buffer);
+#ifdef WITH_DEBUG
+ printf(buffer);
+#endif/*WITH_DEBUG*/
+
return l;
}
@@ -67,7 +73,7 @@ int journal_commit(const char *cpr, const char *user,
const char *addr, unsigned short int port,
const char *buf, size_t size)
{
- int sock = 1;
+ int sock = -1;
#ifndef WITHOUT_UPLOADSERVER
struct sockaddr_in sin;
@@ -116,9 +122,12 @@ int journal_commit(const char *cpr, const char *user,
mwrite(sock, "\r\n");
// send body
- if(write(sock, buf, size) != (ssize_t)size) {
+ if(sock != -1 && write(sock, buf, size) != (ssize_t)size) {
fprintf(stderr, "write did not write all the bytes in the buffer.\n");
}
+#ifdef WITH_DEBUG
+ printf(buf);
+#endif/*WITH_DEBUG*/
#ifndef WITHOUT_UPLOADSERVER
// close socket