pubsubd: debug
This commit is contained in:
parent
cdf975db29
commit
bd2e3e0d15
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
/*
|
||||
|
@ -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/<service>)
|
||||
//
|
||||
// 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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
51
pubsub/test-gen-new-process.c
Normal file
51
pubsub/test-gen-new-process.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include "../lib/pubsubd.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
7
pubsub/test-gen-new-process.sh
Executable file
7
pubsub/test-gen-new-process.sh
Executable file
@ -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
|
Reference in New Issue
Block a user