Obsolete
/
libipc-old
Archived
3
0
Fork 0

pubsubd: '\0' added at the end of the chan name

more_to_read
Philippe PITTOLI 2016-09-10 23:15:10 +02:00
parent 7f0e5b62dd
commit 80c5201b04
3 changed files with 13 additions and 13 deletions

View File

@ -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);

View File

@ -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));

View File

@ -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