pubsubd: '\0' added at the end of the chan name
This commit is contained in:
parent
7f0e5b62dd
commit
80c5201b04
@ -59,8 +59,8 @@ struct channel * pubsubd_channel_copy (struct channel *c)
|
|||||||
memcpy (copy, c, sizeof(struct channel));
|
memcpy (copy, c, sizeof(struct channel));
|
||||||
|
|
||||||
if (c->chan != NULL) {
|
if (c->chan != NULL) {
|
||||||
copy->chan = malloc (c->chanlen);
|
copy->chan = malloc (c->chanlen +1);
|
||||||
memset (copy->chan, 0, c->chanlen);
|
memset (copy->chan, 0, c->chanlen +1);
|
||||||
memcpy (copy->chan, c->chan, c->chanlen);
|
memcpy (copy->chan, c->chan, c->chanlen);
|
||||||
copy->chanlen = 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);
|
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);
|
c->chan = malloc (nlen +1);
|
||||||
memset (c->chan, 0, nlen +1);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset (c->chan, 0, nlen +1);
|
memset (c->chan, 0, nlen +1);
|
||||||
memcpy (c->chan, name, nlen);
|
memcpy (c->chan, name, nlen);
|
||||||
c->chanlen = nlen;
|
c->chanlen = nlen;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,8 +400,6 @@ int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
|
|||||||
printf ("INIT: %s\n", buf);
|
printf ("INIT: %s\n", buf);
|
||||||
|
|
||||||
for (str = buf, i = 1; ; str = NULL, i++) {
|
for (str = buf, i = 1; ; str = NULL, i++) {
|
||||||
if (str == NULL)
|
|
||||||
break;
|
|
||||||
token = strtok_r(str, " ", &saveptr);
|
token = strtok_r(str, " ", &saveptr);
|
||||||
if (token == NULL)
|
if (token == NULL)
|
||||||
break;
|
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
|
else { // everything else is about killing the service
|
||||||
ale->action = PUBSUB_QUIT;
|
ale->action = PUBSUB_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf ("ACTION : %s\n", token);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 5 : {
|
case 5 : {
|
||||||
// for the last element of the line
|
// for the last element of the line
|
||||||
// drop the following \n
|
// 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) ?
|
memcpy (chan, token, (strlen (token) < BUFSIZ) ?
|
||||||
strlen (token) -1 : BUFSIZ);
|
strlen (token) -1 : BUFSIZ);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -463,10 +462,11 @@ int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
|
|||||||
}
|
}
|
||||||
|
|
||||||
chan[BUFSIZ -1] = '\0';
|
chan[BUFSIZ -1] = '\0';
|
||||||
|
printf ("AVANT\n");
|
||||||
pubsubd_channel_new (*c, chan);
|
pubsubd_channel_new (*c, chan);
|
||||||
|
printf ("APRES\n");
|
||||||
|
|
||||||
struct channel *new_chan = NULL;
|
struct channel *new_chan = NULL;
|
||||||
|
|
||||||
new_chan = pubsubd_channel_get (chans, *c);
|
new_chan = pubsubd_channel_get (chans, *c);
|
||||||
if (new_chan == NULL) {
|
if (new_chan == NULL) {
|
||||||
new_chan = pubsubd_channels_add (chans, *c);
|
new_chan = pubsubd_channels_add (chans, *c);
|
||||||
|
@ -27,7 +27,7 @@ main(int argc, char **argv)
|
|||||||
struct channels chans;
|
struct channels chans;
|
||||||
memset (&chans, 0, sizeof (struct channels));
|
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;
|
struct app_list_elm ale;
|
||||||
memset (&ale, 0, sizeof (struct app_list_elm));
|
memset (&ale, 0, sizeof (struct app_list_elm));
|
||||||
|
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
for i in $(seq 1 10)
|
for i in $(seq 1 10)
|
||||||
do
|
do
|
||||||
echo "${i} 1 1 pub chan${i}" > /tmp/ipc/gen
|
echo "${i} 1 1 pub chan1" > /tmp/ipc/gen
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
done
|
done
|
||||||
|
Reference in New Issue
Block a user