From 80c5201b043b334feedc6a1ba2e923b77d2c1f34 Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Sat, 10 Sep 2016 23:15:10 +0200
Subject: [PATCH] pubsubd: '\0' added at the end of the chan name
---
lib/pubsubd.c | 22 +++++++++++-----------
pubsub/test-gen-new-process.c | 2 +-
pubsub/test-gen-new-process.sh | 2 +-
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/lib/pubsubd.c b/lib/pubsubd.c
index a45f106..72a6e86 100644
--- a/lib/pubsubd.c
+++ b/lib/pubsubd.c
@@ -59,8 +59,8 @@ struct channel * pubsubd_channel_copy (struct channel *c)
memcpy (copy, c, sizeof(struct channel));
if (c->chan != NULL) {
- copy->chan = malloc (c->chanlen);
- memset (copy->chan, 0, c->chanlen);
+ copy->chan = malloc (c->chanlen +1);
+ memset (copy->chan, 0, c->chanlen +1);
memcpy (copy->chan, c->chan, c->chanlen);
copy->chanlen = c->chanlen;
}
@@ -76,16 +76,13 @@ int pubsubd_channel_new (struct channel *c, const char * name)
size_t nlen = (strlen (name) > BUFSIZ) ? BUFSIZ : strlen (name);
- printf ("NAME : %s, SIZE : %ld\n", name, nlen);
-
- if (c->chan == NULL) {
+ if (c->chan == NULL)
c->chan = malloc (nlen +1);
- memset (c->chan, 0, nlen +1);
- }
memset (c->chan, 0, nlen +1);
memcpy (c->chan, name, nlen);
c->chanlen = nlen;
+
return 0;
}
@@ -403,8 +400,6 @@ int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
printf ("INIT: %s\n", buf);
for (str = buf, i = 1; ; str = NULL, i++) {
- if (str == NULL)
- break;
token = strtok_r(str, " ", &saveptr);
if (token == NULL)
break;
@@ -426,14 +421,18 @@ int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
else { // everything else is about killing the service
ale->action = PUBSUB_QUIT;
}
+
+ printf ("ACTION : %s\n", token);
break;
}
case 5 : {
// for the last element of the line
// drop the following \n
- if (ale->action != PUBSUB_QUIT)
+ if (ale->action != PUBSUB_QUIT) {
+ printf ("REQUESTED CHAN : %s", token);
memcpy (chan, token, (strlen (token) < BUFSIZ) ?
strlen (token) -1 : BUFSIZ);
+ }
break;
}
}
@@ -463,10 +462,11 @@ int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
}
chan[BUFSIZ -1] = '\0';
+ printf ("AVANT\n");
pubsubd_channel_new (*c, chan);
+ printf ("APRES\n");
struct channel *new_chan = NULL;
-
new_chan = pubsubd_channel_get (chans, *c);
if (new_chan == NULL) {
new_chan = pubsubd_channels_add (chans, *c);
diff --git a/pubsub/test-gen-new-process.c b/pubsub/test-gen-new-process.c
index cc2f733..425e339 100644
--- a/pubsub/test-gen-new-process.c
+++ b/pubsub/test-gen-new-process.c
@@ -27,7 +27,7 @@ main(int argc, char **argv)
struct channels chans;
memset (&chans, 0, sizeof (struct channels));
- for (int nb = 1, i = 0 ; nb > 0; i++, nb--) {
+ for (int nb = 2, i = 0 ; nb > 0; i++, nb--) {
struct app_list_elm ale;
memset (&ale, 0, sizeof (struct app_list_elm));
diff --git a/pubsub/test-gen-new-process.sh b/pubsub/test-gen-new-process.sh
index 67d6699..0cd4f1c 100755
--- a/pubsub/test-gen-new-process.sh
+++ b/pubsub/test-gen-new-process.sh
@@ -2,6 +2,6 @@
for i in $(seq 1 10)
do
- echo "${i} 1 1 pub chan${i}" > /tmp/ipc/gen
+ echo "${i} 1 1 pub chan1" > /tmp/ipc/gen
sleep 0.1
done