diff --git a/lib/communication.c b/lib/communication.c index d3acd33..4cdbd56 100644 --- a/lib/communication.c +++ b/lib/communication.c @@ -75,11 +75,21 @@ int file_write (FILE *f, const char *buf, size_t msize) return 0; } -void srv_init (struct service *srv, const char *sname) +void srv_init (int argc, char **argv, char **env, struct service *srv, const char *sname) { if (srv == NULL) return; + // TODO + // use the argc, argv and env parameters + // it will be useful to change some parameters transparently + // ex: to get resources from other machines, choosing the + // remote with environment variables + + argc = argc; + argv = argv; + env = env; + // gets the service path, such as /tmp/ memset (srv->spath, 0, PATH_MAX); strncat (srv->spath, TMPDIR, PATH_MAX -1); diff --git a/lib/communication.h b/lib/communication.h index f646823..764dd9e 100644 --- a/lib/communication.h +++ b/lib/communication.h @@ -30,7 +30,7 @@ struct service { FILE *spipe; }; -void srv_init (struct service *srv, const char *sname); +void srv_init (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 f61cdbe..624decb 100644 --- a/lib/pubsubd.c +++ b/lib/pubsubd.c @@ -593,15 +593,16 @@ void pubsub_connection (struct service *srv, struct process *p, enum app_list_el free (straction); } -void pubsub_disconnect (struct service *srv, struct process *p, enum app_list_elm_action action, const char *channame) +// tell the service to stop +void pubsub_disconnect (struct service *srv) { - // line fmt : pid index version quit - // "quit" action is also possible (see pubsub_disconnect) + // line fmt : 0 0 0 quit char line[BUFSIZ]; - snprintf (line, BUFSIZ, "%d %d %d quit\n" , p->pid, p->index, p->version); + snprintf (line, BUFSIZ, "0 0 0 quit\n"); + app_srv_connection (srv, line, strlen (line)); } -void pubsub_msg_send (const struct service *s, struct process *p, const struct pubsub_msg * m) +void pubsub_msg_send (struct process *p, const struct pubsub_msg * m) { char *buf = NULL; size_t msize = 0; @@ -614,7 +615,7 @@ void pubsub_msg_send (const struct service *s, struct process *p, const struct p } } -void pubsub_msg_recv (const struct service *s, struct process *p, struct pubsub_msg * m) +void pubsub_msg_recv (struct process *p, struct pubsub_msg * m) { // read the message from the process size_t mlen = 0; diff --git a/lib/pubsubd.h b/lib/pubsubd.h index b7036cf..bc44c51 100644 --- a/lib/pubsubd.h +++ b/lib/pubsubd.h @@ -41,8 +41,8 @@ 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); void pubsubd_msg_recv (struct process *p, struct pubsub_msg *m); -void pubsub_msg_send (const struct service *, struct process *p, const struct pubsub_msg *msg); -void pubsub_msg_recv (const struct service *, struct process *p, struct pubsub_msg *msg); +void pubsub_msg_send (struct process *p, const struct pubsub_msg *msg); +void pubsub_msg_recv (struct process *p, struct pubsub_msg *msg); // CHANNEL @@ -102,6 +102,6 @@ void pubsubd_app_list_elm_create (struct app_list_elm *ale, struct process *p); void pubsubd_app_list_elm_free (struct app_list_elm *todel); void pubsub_connection (struct service *srv, struct process *p, enum app_list_elm_action action, const char *channame); -void pubsub_disconnect (struct service *srv, struct process *p, enum app_list_elm_action action, const char *channame); +void pubsub_disconnect (struct service *srv); #endif diff --git a/pingpong/pingpong.c b/pingpong/pingpong.c index ff58080..a40b8e5 100644 --- a/pingpong/pingpong.c +++ b/pingpong/pingpong.c @@ -63,10 +63,10 @@ void main_loop (const struct service *srv) * 5. removes the named pipe /tmp/ */ -int main(int argc, char * argv[]) +int main(int argc, char * argv[], char **env) { struct service srv; - srv_init (&srv, PONGD_SERVICE_NAME); + srv_init (argc, argv, env, &srv, PONGD_SERVICE_NAME); printf ("Listening on %s.\n", srv.spath); // creates the service named pipe, that listens to client applications diff --git a/pubsub/pubsub-test-send-params.c b/pubsub/pubsub-test-send-params.c index b7379ae..a37e15b 100644 --- a/pubsub/pubsub-test-send-params.c +++ b/pubsub/pubsub-test-send-params.c @@ -16,7 +16,7 @@ void usage (char **argv) printf ( "usage : %s pid index (pub|sub|both|quit) [chan]\n", argv[0]); } -void sim_connection (pid_t pid, int index, int version, char *cmd, char *chan) +void sim_connection (int argc, char **argv, char **env, pid_t pid, int index, int version, char *cmd, char *chan) { printf ("Simulate connnection : pid %d index %d version %d " @@ -25,7 +25,7 @@ void sim_connection (pid_t pid, int index, int version, char *cmd, char *chan) struct service srv; bzero (&srv, sizeof (struct service)); - srv_init (&srv, PUBSUB_SERVICE_NAME); + srv_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME); printf ("Writing on %s.\n", srv.spath); struct process p; @@ -47,11 +47,11 @@ void sim_connection (pid_t pid, int index, int version, char *cmd, char *chan) m.chanlen = strlen (MYCHAN); m.data = malloc (strlen (MYMESSAGE)); m.datalen = strlen (MYMESSAGE); - pubsub_msg_send (&srv, &p, &m); + pubsub_msg_send (&p, &m); // second message, to disconnect from the server m.type = PUBSUB_TYPE_DISCONNECT; - pubsub_msg_send (&srv, &p, &m); + pubsub_msg_send (&p, &m); // free everything @@ -64,7 +64,7 @@ void sim_connection (pid_t pid, int index, int version, char *cmd, char *chan) srv_process_free (&p); } -void sim_disconnection (pid_t pid, int index, int version) +void sim_disconnection (int argc, char **argv, char **env, pid_t pid, int index, int version) { struct service srv; bzero (&srv, sizeof (struct service)); @@ -85,7 +85,7 @@ void sim_disconnection (pid_t pid, int index, int version) } int -main(int argc, char* argv[]) +main(int argc, char **argv, char **env) { if (argc < 3) { @@ -108,10 +108,10 @@ main(int argc, char* argv[]) if (strcmp(cmd, "quit") != 0) { char *chan = NULL; chan = argv[4]; - sim_connection (pid, index, version, cmd, chan); + sim_connection (argc, argv, env, pid, index, version, cmd, chan); } else { - sim_disconnection (pid, index, version); + sim_disconnection (argc, argv, env, pid, index, version); } return EXIT_SUCCESS; diff --git a/pubsub/pubsub-test-send.c b/pubsub/pubsub-test-send.c index 5e2c6a8..c1f40c8 100644 --- a/pubsub/pubsub-test-send.c +++ b/pubsub/pubsub-test-send.c @@ -12,11 +12,11 @@ ohshit(int rvalue, const char* str) { } int -main(int argc, char* argv[]) +main(int argc, char **argv, char **env) { struct service srv; memset (&srv, 0, sizeof (struct service)); - srv_init (&srv, PUBSUB_SERVICE_NAME); + srv_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME); printf ("Writing on %s.\n", srv.spath); struct process p; @@ -39,11 +39,11 @@ main(int argc, char* argv[]) m.chanlen = strlen (MYCHAN); m.data = malloc (strlen (MYMESSAGE)); m.datalen = strlen (MYMESSAGE); - pubsub_msg_send (&srv, &p, &m); + pubsub_msg_send (&p, &m); // second message, to disconnect from the server m.type = PUBSUB_TYPE_DISCONNECT; - pubsub_msg_send (&srv, &p, &m); + pubsub_msg_send (&p, &m); // free everything diff --git a/pubsub/pubsubd.c b/pubsub/pubsubd.c index 7c6fc37..9396c5a 100644 --- a/pubsub/pubsubd.c +++ b/pubsub/pubsubd.c @@ -55,11 +55,11 @@ void * pubsubd_worker_thread (void *params) } int -main(int argc, char* argv[]) +main(int argc, char **argv, char **env) { struct service srv; memset (&srv, 0, sizeof (struct service)); - srv_init (&srv, PUBSUB_SERVICE_NAME); + srv_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME); printf ("Listening on %s.\n", srv.spath); // creates the service named pipe, that listens to client applications