From bd2e3e0d15c75e768e3faf2e9631cf59f5579b7a Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Fri, 9 Sep 2016 21:52:56 +0200
Subject: [PATCH] pubsubd: debug
---
lib/communication.c | 6 ----
lib/communication.h | 1 -
lib/pubsubd.c | 9 +++---
lib/pubsubd.h | 2 +-
pubsub/pubsubd.c | 2 +-
pubsub/test-gen-new-process.c | 51 ++++++++++++++++++++++++++++++++++
pubsub/test-gen-new-process.sh | 7 +++++
7 files changed, 65 insertions(+), 13 deletions(-)
create mode 100644 pubsub/test-gen-new-process.c
create mode 100755 pubsub/test-gen-new-process.sh
diff --git a/lib/communication.c b/lib/communication.c
index 0f6d387..68030ce 100644
--- a/lib/communication.c
+++ b/lib/communication.c
@@ -124,12 +124,6 @@ int srv_close (struct service *srv)
return 0;
}
-// TODO remove, replace by file_read
-int srv_get_listen_raw (const struct service *srv, char **buf, size_t *msize)
-{
- return file_read (srv->spath, buf, msize);
-}
-
int srv_get_new_process (const struct service *srv, struct process *p)
{
if (srv->spath == NULL) {
diff --git a/lib/communication.h b/lib/communication.h
index bc875f5..f91dd3f 100644
--- a/lib/communication.h
+++ b/lib/communication.h
@@ -37,7 +37,6 @@ int srv_init (int argc, char **argv, char **env
, int (*cb)(int argc, char **argv, char **env
, struct service *srv, const char *sname));
-int srv_get_listen_raw (const struct service *srv, char **buf, size_t *msize);
int srv_get_new_process (const struct service *srv, struct process *proc);
/*
diff --git a/lib/pubsubd.c b/lib/pubsubd.c
index 7b31021..e07c7db 100644
--- a/lib/pubsubd.c
+++ b/lib/pubsubd.c
@@ -363,16 +363,15 @@ void pubsubd_msg_free (struct pubsub_msg *msg)
// COMMUNICATION
-int pubsubd_get_new_process (struct service *srv, struct app_list_elm *ale
+int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
, struct channels *chans, struct channel **c)
{
- if (srv == NULL || ale == NULL || chans == NULL)
+ if (spath == NULL || ale == NULL || chans == NULL)
return -1;
char *buf = NULL;
size_t msize = 0;
- srv_get_listen_raw (srv, &buf, &msize);
-
+ file_read (spath, &buf, &msize);
// parse pubsubd init msg (sent in TMPDIR/)
//
// line fmt : pid index version action chan
@@ -416,6 +415,8 @@ int pubsubd_get_new_process (struct service *srv, struct app_list_elm *ale
break;
}
case 5 : {
+ // for the last element of the line
+ // drop the following \n
if (ale->action != PUBSUB_QUIT)
memcpy (chan, token, (strlen (token) < BUFSIZ) ?
strlen (token) -1 : BUFSIZ);
diff --git a/lib/pubsubd.h b/lib/pubsubd.h
index c261ac7..2dd3e63 100644
--- a/lib/pubsubd.h
+++ b/lib/pubsubd.h
@@ -35,7 +35,7 @@ void pubsubd_msg_print (const struct pubsub_msg *msg);
//
// line fmt : pid index version action chan
// action : quit | pub | sub
-int pubsubd_get_new_process (struct service *srv, struct app_list_elm *ale
+int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
, struct channels *chans, struct channel **c);
int pubsubd_msg_read_cb (FILE *f, char ** buf, size_t * msize);
void pubsubd_msg_send (const struct app_list_head *alh, const struct pubsub_msg *m);
diff --git a/pubsub/pubsubd.c b/pubsub/pubsubd.c
index 21e9bad..1c1984f 100644
--- a/pubsub/pubsubd.c
+++ b/pubsub/pubsubd.c
@@ -117,7 +117,7 @@ main(int argc, char **argv, char **env)
struct app_list_elm ale;
memset (&ale, 0, sizeof (struct app_list_elm));
struct channel *chan = NULL;
- pubsubd_get_new_process (&srv, &ale, &chans, &chan);
+ pubsubd_get_new_process (srv.spath, &ale, &chans, &chan);
pubsubd_channels_print (&chans);
// end the application
diff --git a/pubsub/test-gen-new-process.c b/pubsub/test-gen-new-process.c
new file mode 100644
index 0000000..6999ac1
--- /dev/null
+++ b/pubsub/test-gen-new-process.c
@@ -0,0 +1,51 @@
+#include "../lib/pubsubd.h"
+#include
+#include
+
+void
+ohshit(int rvalue, const char* str) {
+ fprintf(stderr, "%s\n", str);
+ exit(rvalue);
+}
+
+void usage (char **argv) {
+ fprintf (stderr, "usage: %s path\n", argv[0]);
+ exit (1);
+}
+
+int
+main(int argc, char **argv)
+{
+ if (argc != 2) {
+ usage (argv);
+ }
+
+ char *spath = argv[1];
+
+ printf ("Listening on %s.\n", spath);
+
+ struct channels chans;
+ memset (&chans, 0, sizeof (struct channels));
+
+ for (int nb = 10, i = 0 ; nb > 0; i++, nb--) {
+ struct app_list_elm ale;
+ memset (&ale, 0, sizeof (struct app_list_elm));
+
+ struct channel chan;
+ memset (&chan, 0, sizeof (struct channel));
+ struct channel *c = &chan;
+
+ pubsubd_get_new_process (spath, &ale, &chans, &c);
+
+ printf ("print the channels, %d chan\n", i);
+ printf ("--\n");
+ pubsubd_channels_print (&chans);
+ printf ("--\n");
+ printf ("still %d remaining processes\n", nb);
+ }
+
+ pubsubd_channels_del_all (&chans);
+
+ return EXIT_SUCCESS;
+}
+
diff --git a/pubsub/test-gen-new-process.sh b/pubsub/test-gen-new-process.sh
new file mode 100755
index 0000000..e6aad3a
--- /dev/null
+++ b/pubsub/test-gen-new-process.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+for i in $(seq 1 10)
+do
+ echo "${i} 1 1 pub chan${i}" > /tmp/ipc/gen
+ sleep 1
+done