aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-05-14 04:45:22 +0200
committerMattias Andrée <maandree@operamail.com>2014-05-14 04:45:22 +0200
commit33f3c3234c250908ae02fbe908c83a5fc4bf0461 (patch)
tree548e71c31dc8e4ab9bb4d0a3c39b6b47827d7837
parentm + add test client (diff)
downloadmds-33f3c3234c250908ae02fbe908c83a5fc4bf0461.tar.gz
mds-33f3c3234c250908ae02fbe908c83a5fc4bf0461.tar.bz2
mds-33f3c3234c250908ae02fbe908c83a5fc4bf0461.tar.xz
fix bugs
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--Makefile4
-rw-r--r--src/libmdsserver/mds-message.c5
-rw-r--r--src/mds-server/mds-server.c24
-rwxr-xr-xtest.d/mds-server2
4 files changed, 26 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 1052984..ca1b6bb 100644
--- a/Makefile
+++ b/Makefile
@@ -84,6 +84,10 @@ MDS_SERVER_OBJ = mds-server/mds-server mds-server/interception_condition mds-ser
bin/mds-server: $(foreach O,$(MDS_SERVER_OBJ),obj/$(O).o) bin/libmdsserver.so
mkdir -p $(shell dirname $@)
$(CC) $(C_FLAGS) -o $@ $(LDS) $(foreach O,$(MDS_SERVER_OBJ),obj/$(O).o)
+ifeq ($(DEBUG),y)
+ mv $@ $@.real
+ cp test.d/mds-server $@
+endif
bin/%: obj/%.o bin/libmdsserver.so
mkdir -p $(shell dirname $@)
diff --git a/src/libmdsserver/mds-message.c b/src/libmdsserver/mds-message.c
index 1f05579..dcb8986 100644
--- a/src/libmdsserver/mds-message.c
+++ b/src/libmdsserver/mds-message.c
@@ -273,6 +273,11 @@ int mds_message_read(mds_message_t* restrict this, int fd)
this->buffer_ptr += (size_t)(got < 0 ? 0 : got);
if (errno)
return -1;
+ if (got == 0)
+ {
+ errno = ECONNRESET;
+ return -1;
+ }
}
}
diff --git a/src/mds-server/mds-server.c b/src/mds-server/mds-server.c
index 3bf3cd7..aebd104 100644
--- a/src/mds-server/mds-server.c
+++ b/src/mds-server/mds-server.c
@@ -498,6 +498,7 @@ void* slave_loop(void* data)
information->interception_conditions = NULL;
information->send_pending = NULL;
information->modify_message = NULL;
+ information->multicasts = NULL;
information->mutex_created = 0;
information->modify_mutex_created = 0;
information->modify_cond_created = 0;
@@ -529,6 +530,7 @@ void* slave_loop(void* data)
information->id = 0;
information->interception_conditions_count = 0;
information->send_pending_size = 0;
+ information->multicasts_count = 0;
if (mds_message_initialise(&(information->message)))
{
perror(*argv);
@@ -663,13 +665,16 @@ void* slave_loop(void* data)
/* Multicast information about the client closing. */
n = 2 * 10 + 1 + strlen("Client closed: :\n\n");
+ if (xmalloc(msgbuf, n, char))
+ goto fail;
snprintf(msgbuf, n,
"Client closed: %" PRIu32 ":%" PRIu32 "\n"
"\n",
(uint32_t)(information->id >> 32),
(uint32_t)(information->id >> 0));
- n = strlen(msgbuf) + 1;
+ n = strlen(msgbuf);
queue_message_multicast(msgbuf, n, information);
+ msgbuf = NULL;
fail: /* The loop does break, this done on success as well. */
@@ -1108,6 +1113,7 @@ static int cmp_queued_interception(const void* a, const void* b)
*/
void queue_message_multicast(char* message, size_t length, client_t* sender)
{
+ char* msg = message;
size_t header_count = 0;
size_t n = length - 1;
size_t* hashes = NULL;
@@ -1135,7 +1141,7 @@ void queue_message_multicast(char* message, size_t length, client_t* sender)
return; /* Invalid message. */
/* Allocate multicast message. */
- if (xmalloc(multicast, 1, sizeof(multicast_t))) goto fail;
+ if (xmalloc(multicast, 1, multicast_t)) goto fail;
multicast_initialise(multicast);
/* Allocate header lists. */
@@ -1146,17 +1152,17 @@ void queue_message_multicast(char* message, size_t length, client_t* sender)
/* Populate header lists. */
for (i = 0; i < header_count; i++)
{
- char* end = strchr(message, '\n');
- char* colon = strchr(message, ':');
+ char* end = strchr(msg, '\n');
+ char* colon = strchr(msg, ':');
*end = '\0';
- if ((header_values[i] = strdup(message)) == NULL)
+ if ((header_values[i] = strdup(msg)) == NULL)
{
header_count = i;
goto fail;
}
*colon = '\0';
- if ((headers[i] = strdup(message)) == NULL)
+ if ((headers[i] = strdup(msg)) == NULL)
{
free(headers[i]);
header_count = i;
@@ -1166,7 +1172,7 @@ void queue_message_multicast(char* message, size_t length, client_t* sender)
*end = '\n';
hashes[i] = string_hash(headers[i]);
- message = end + 1;
+ msg = end + 1;
}
/* Get intercepting clients. */
@@ -1251,7 +1257,7 @@ void queue_message_multicast(char* message, size_t length, client_t* sender)
message = old_buf;
goto fail;
}
- memmove(message + n, message, (n + length) * sizeof(char));
+ memmove(message + n, message, length * sizeof(char));
memcpy(message, modify_id_header, n * sizeof(char));
/* Store information. */
@@ -1264,7 +1270,7 @@ void queue_message_multicast(char* message, size_t length, client_t* sender)
/* Queue message multicasting. */
with_mutex(sender->mutex,
- if (sender->multicasts_count == 1)
+ if (sender->multicasts == NULL)
{
if (xmalloc(sender->multicasts, 1, multicast_t))
goto fail_queue;
diff --git a/test.d/mds-server b/test.d/mds-server
new file mode 100755
index 0000000..04a6d7f
--- /dev/null
+++ b/test.d/mds-server
@@ -0,0 +1,2 @@
+#!/bin/sh
+valgrind --leak-check=full --show-leak-kinds=all "$0".real "$@"