TO FIX - suppression de pid pour le process
This commit is contained in:
parent
f451e0f88d
commit
7c7bcb63ef
@ -9,7 +9,7 @@
|
|||||||
#define handle_error(msg) \
|
#define handle_error(msg) \
|
||||||
do { perror(msg); exit(EXIT_FAILURE); } while (0)
|
do { perror(msg); exit(EXIT_FAILURE); } while (0)
|
||||||
|
|
||||||
int file_write (const int fd, const char *buf, const int msize)
|
int msg_send (const int fd, const char *buf, const int msize)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
//printf ("%ld bytes to write\n", msize);
|
//printf ("%ld bytes to write\n", msize);
|
||||||
@ -21,7 +21,7 @@ int file_write (const int fd, const char *buf, const int msize)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int file_read (const int fd, char **buf)
|
int msg_recv (const int fd, char **buf)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
ret = recv (fd, *buf, BUFSIZ, 0);
|
ret = recv (fd, *buf, BUFSIZ, 0);
|
||||||
@ -128,7 +128,6 @@ int srv_get_new_process (char *buf, struct process *p)
|
|||||||
char *str = NULL;
|
char *str = NULL;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
pid_t pid = 0;
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int version = 0;
|
int version = 0;
|
||||||
|
|
||||||
@ -138,19 +137,16 @@ int srv_get_new_process (char *buf, struct process *p)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
pid = strtoul(token, NULL, 10);
|
|
||||||
}
|
|
||||||
else if (i == 2) {
|
|
||||||
index = strtoul(token, NULL, 10);
|
index = strtoul(token, NULL, 10);
|
||||||
}
|
}
|
||||||
else if (i == 3) {
|
else if (i == 2) {
|
||||||
version = strtoul(token, NULL, 10);
|
version = strtoul(token, NULL, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (buf != NULL)
|
//if (buf != NULL)
|
||||||
// free (buf);
|
// free (buf);
|
||||||
srv_process_gen (p, pid, index, version);
|
srv_process_gen (p, index, version);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -158,13 +154,13 @@ int srv_get_new_process (char *buf, struct process *p)
|
|||||||
int srv_read (const struct service *srv, char ** buf)
|
int srv_read (const struct service *srv, char ** buf)
|
||||||
{
|
{
|
||||||
//printf("---%s\n", srv->spath);
|
//printf("---%s\n", srv->spath);
|
||||||
return file_read (srv->service_fd, buf);
|
return msg_recv (srv->service_fd, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int srv_write (const struct service *srv, const char * buf, size_t msize)
|
int srv_write (const struct service *srv, const char * buf, size_t msize)
|
||||||
{
|
{
|
||||||
//printf("---%s\n", srv->spath);
|
//printf("---%s\n", srv->spath);
|
||||||
return file_write (srv->service_fd, buf, msize);
|
return msg_send (srv->service_fd, buf, msize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// APPLICATION
|
// APPLICATION
|
||||||
@ -227,14 +223,14 @@ int proc_connection(struct process *p) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_create (struct process *p, pid_t pid, int index, int version)
|
int app_create (struct process *p, int index, int version)
|
||||||
{
|
{
|
||||||
if (version == 0) {
|
if (version == 0) {
|
||||||
version = COMMUNICATION_VERSION;
|
version = COMMUNICATION_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
// then creates the structure
|
// then creates the structure
|
||||||
srv_process_gen (p, pid, index, version);
|
srv_process_gen (p, index, version);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -251,13 +247,13 @@ int app_destroy (struct process *p)
|
|||||||
int app_read (struct process *p, char ** buf)
|
int app_read (struct process *p, char ** buf)
|
||||||
{
|
{
|
||||||
//printf("---%s\n", p->path_proc);
|
//printf("---%s\n", p->path_proc);
|
||||||
return file_read (p->proc_fd, buf);
|
return msg_recv (p->proc_fd, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_write (struct process *p, char * buf, size_t msize)
|
int app_write (struct process *p, char * buf, size_t msize)
|
||||||
{
|
{
|
||||||
//printf("---%s\n", p->path_proc);
|
//printf("---%s\n", p->path_proc);
|
||||||
return file_write (p->proc_fd, buf, msize);
|
return msg_send (p->proc_fd, buf, msize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*init a unix socket : bind, listen
|
/*init a unix socket : bind, listen
|
31
core/process.c
Normal file
31
core/process.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "process.h"
|
||||||
|
|
||||||
|
struct process * srv_process_copy (const struct process *p)
|
||||||
|
{
|
||||||
|
if (p == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
struct process * copy = malloc (sizeof(struct process));
|
||||||
|
memcpy (copy, p, sizeof (struct process));
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
int srv_process_eq (const struct process *p1, const struct process *p2)
|
||||||
|
{
|
||||||
|
return (p1->version == p2->version && p1->index == p2->index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void srv_process_gen (struct process *p
|
||||||
|
, unsigned int index, unsigned int version)
|
||||||
|
{
|
||||||
|
p->version = version;
|
||||||
|
p->index = index;
|
||||||
|
snprintf(p->path_proc, PATH_MAX, "%s%d-%d", TMPDIR, index, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
void srv_process_print (struct process *p)
|
||||||
|
{
|
||||||
|
if (p != NULL)
|
||||||
|
printf ("process %d : index %d, version %d\n", p->index, p->version);
|
||||||
|
}
|
@ -14,11 +14,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct process {
|
struct process {
|
||||||
pid_t pid;
|
|
||||||
unsigned int version;
|
unsigned int version;
|
||||||
unsigned int index;
|
unsigned int index;
|
||||||
char path_in [PATH_MAX];
|
|
||||||
char path_out [PATH_MAX];
|
|
||||||
char path_proc [PATH_MAX];
|
char path_proc [PATH_MAX];
|
||||||
int proc_fd;
|
int proc_fd;
|
||||||
};
|
};
|
||||||
@ -29,7 +26,7 @@ int srv_process_eq (const struct process *p1, const struct process *p2);
|
|||||||
|
|
||||||
// create the service process structure
|
// create the service process structure
|
||||||
void srv_process_gen (struct process *p
|
void srv_process_gen (struct process *p
|
||||||
, pid_t pid, unsigned int index, unsigned int version);
|
, unsigned int index, unsigned int version);
|
||||||
|
|
||||||
void srv_process_print (struct process *);
|
void srv_process_print (struct process *);
|
||||||
|
|
@ -113,10 +113,11 @@ void pubsub_connection (struct service *srv, struct process *p, enum app_list_el
|
|||||||
char line[BUFSIZ];
|
char line[BUFSIZ];
|
||||||
memset (line, 0, BUFSIZ);
|
memset (line, 0, BUFSIZ);
|
||||||
|
|
||||||
// line fmt : pid index version action chan
|
// line fmt : index version action chan
|
||||||
// "quit" action is also possible (see pubsubd_quit)
|
// "quit" action is also possible (see pubsubd_quit)
|
||||||
snprintf (line, BUFSIZ, "%d %d %d %s %s\n"
|
snprintf (line, BUFSIZ, "%d %d %s %s\n"
|
||||||
, p->pid, p->index, p->version
|
, p->index
|
||||||
|
, p->version
|
||||||
, straction
|
, straction
|
||||||
, channame);
|
, channame);
|
||||||
line[BUFSIZ -1] = '\0'; // to be sure
|
line[BUFSIZ -1] = '\0'; // to be sure
|
@ -1,41 +0,0 @@
|
|||||||
#include "process.h"
|
|
||||||
|
|
||||||
struct process * srv_process_copy (const struct process *p)
|
|
||||||
{
|
|
||||||
if (p == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
struct process * copy = malloc (sizeof(struct process));
|
|
||||||
memcpy (copy, p, sizeof (struct process));
|
|
||||||
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
int srv_process_eq (const struct process *p1, const struct process *p2)
|
|
||||||
{
|
|
||||||
return (p1->pid == p2->pid && p1->version == p2->version
|
|
||||||
&& p1->index == p2->index);
|
|
||||||
}
|
|
||||||
|
|
||||||
void srv_process_gen (struct process *p
|
|
||||||
, pid_t pid, unsigned int index, unsigned int version)
|
|
||||||
{
|
|
||||||
p->pid = pid;
|
|
||||||
p->version = version;
|
|
||||||
p->index = index;
|
|
||||||
|
|
||||||
memset (p->path_in, 0, PATH_MAX);
|
|
||||||
memset (p->path_out, 0, PATH_MAX);
|
|
||||||
|
|
||||||
snprintf(p->path_in , PATH_MAX, "%s%d-%d-%d-in" , TMPDIR, pid, index, version);
|
|
||||||
snprintf(p->path_out, PATH_MAX, "%s%d-%d-%d-out", TMPDIR, pid, index, version);
|
|
||||||
snprintf(p->path_proc, PATH_MAX, "%s%d-%d-%d", TMPDIR, pid, index, version);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void srv_process_print (struct process *p)
|
|
||||||
{
|
|
||||||
if (p != NULL)
|
|
||||||
printf ("process %d : index %d, version %d\n"
|
|
||||||
, p->pid, p->index, p->version);
|
|
||||||
}
|
|
@ -8,19 +8,6 @@ ohshit(int rvalue, const char* str) {
|
|||||||
exit(rvalue);
|
exit(rvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* pipes creation and removal test program
|
|
||||||
*
|
|
||||||
* 1. S creates the named pipe /tmp/ipc/<service>
|
|
||||||
* 2. App creates named pipes in & out, /tmp/ipc/$pid-$index-$version-{in,out}
|
|
||||||
*
|
|
||||||
* ... some communication between S and App...
|
|
||||||
* App wants to stop
|
|
||||||
*
|
|
||||||
* 3. App removes the named pipes in and out
|
|
||||||
* 4. S removes the named pipe /tmp/ipc/<service>
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main(int argc, char * argv[], char *env[])
|
int main(int argc, char * argv[], char *env[])
|
||||||
{
|
{
|
||||||
struct service srv;
|
struct service srv;
|
||||||
@ -39,12 +26,11 @@ int main(int argc, char * argv[], char *env[])
|
|||||||
struct process p;
|
struct process p;
|
||||||
memset (&p, 0, sizeof (struct process));
|
memset (&p, 0, sizeof (struct process));
|
||||||
|
|
||||||
pid_t pid = getpid();
|
|
||||||
int index = 0; // first time we communication with the service
|
int index = 0; // first time we communication with the service
|
||||||
int version = 1;
|
int version = 1;
|
||||||
|
|
||||||
printf ("app creation\n");
|
printf ("app creation\n");
|
||||||
if (app_create (&p, pid, index, version)) // called by the application
|
if (app_create (&p, index, version)) // called by the application
|
||||||
ohshit (1, "app_create");
|
ohshit (1, "app_create");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -21,15 +21,10 @@ fi
|
|||||||
|
|
||||||
for pid in `seq 1 ${NB}`
|
for pid in `seq 1 ${NB}`
|
||||||
do
|
do
|
||||||
# we make the application pipes
|
|
||||||
# mkfifo ${REP}${pid}-1-1-in 2>/dev/null
|
|
||||||
# mkfifo ${REP}${pid}-1-1-out 2>/dev/null
|
|
||||||
|
|
||||||
# pid index version
|
# pid index version
|
||||||
echo "${pid} 1 1" | nc -U ${REP}${SERVICE}
|
echo "${pid} 1 1" | nc -U ${REP}${SERVICE}
|
||||||
|
|
||||||
# the purpose is to send something in the pipe
|
# the purpose is to send something in the pipe
|
||||||
#cat /dev/urandom | base64 | head -n 1 > ${REP}${pid}-1-1-out
|
|
||||||
echo "hello frero" | nc -U ${REP}${pid}-1-1
|
echo "hello frero" | nc -U ${REP}${pid}-1-1
|
||||||
#echo "exit" | nc -U ${REP}${pid}-1-1
|
#echo "exit" | nc -U ${REP}${pid}-1-1
|
||||||
|
|
||||||
|
@ -35,8 +35,6 @@ void fill_process (struct process *p)
|
|||||||
p->pid = 10;
|
p->pid = 10;
|
||||||
p->version = 1;
|
p->version = 1;
|
||||||
p->index = 1;
|
p->index = 1;
|
||||||
memcpy (p->path_in, "pathin", strlen ("pathin") +1);
|
|
||||||
memcpy (p->path_out, "pathout", strlen ("pathout") +1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// enum app_list_elm_action {PUBSUB_QUIT = 1, PUBSUB_PUB, PUBSUB_SUB, PUBSUB_BOTH};
|
// enum app_list_elm_action {PUBSUB_QUIT = 1, PUBSUB_PUB, PUBSUB_SUB, PUBSUB_BOTH};
|
||||||
|
@ -126,7 +126,7 @@ void * pubsubd_worker_thread (void *params)
|
|||||||
pubsubd_msg_recv (ale->p, &m);
|
pubsubd_msg_recv (ale->p, &m);
|
||||||
|
|
||||||
if (m.type == PUBSUB_TYPE_DISCONNECT) {
|
if (m.type == PUBSUB_TYPE_DISCONNECT) {
|
||||||
printf ("process %d disconnecting...\n", ale->p->pid);
|
// printf ("process %d disconnecting...\n", ale->p->pid);
|
||||||
if ( 0 != pubsubd_subscriber_del (chan->alh, ale)) {
|
if ( 0 != pubsubd_subscriber_del (chan->alh, ale)) {
|
||||||
fprintf (stderr, "err : subscriber not registered\n");
|
fprintf (stderr, "err : subscriber not registered\n");
|
||||||
}
|
}
|
||||||
@ -462,13 +462,12 @@ int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
|
|||||||
file_read (spath, &buf, &msize);
|
file_read (spath, &buf, &msize);
|
||||||
// parse pubsubd init msg (sent in TMPDIR/<service>)
|
// parse pubsubd init msg (sent in TMPDIR/<service>)
|
||||||
//
|
//
|
||||||
// line fmt : pid index version action chan
|
// line fmt : index version action chan
|
||||||
// action : quit | pub | sub
|
// action : quit | pub | sub
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
char *str = NULL, *token = NULL, *saveptr = NULL;
|
char *str = NULL, *token = NULL, *saveptr = NULL;
|
||||||
|
|
||||||
pid_t pid = 0;
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int version = 0;
|
int version = 0;
|
||||||
|
|
||||||
@ -488,10 +487,9 @@ int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 1 : pid = strtoul(token, NULL, 10); break;
|
case 1 : index = strtoul(token, NULL, 10); break;
|
||||||
case 2 : index = strtoul(token, NULL, 10); break;
|
case 2 : version = strtoul(token, NULL, 10); break;
|
||||||
case 3 : version = strtoul(token, NULL, 10); break;
|
case 3 : {
|
||||||
case 4 : {
|
|
||||||
if (strncmp("both", token, 4) == 0) {
|
if (strncmp("both", token, 4) == 0) {
|
||||||
ale->action = PUBSUB_BOTH;
|
ale->action = PUBSUB_BOTH;
|
||||||
}
|
}
|
||||||
@ -506,7 +504,7 @@ int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 5 : {
|
case 4 : {
|
||||||
// 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) {
|
||||||
@ -534,7 +532,7 @@ int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
|
|||||||
|
|
||||||
ale->p = malloc (sizeof (struct process));
|
ale->p = malloc (sizeof (struct process));
|
||||||
memset (ale->p, 0, sizeof (struct process));
|
memset (ale->p, 0, sizeof (struct process));
|
||||||
srv_process_gen (ale->p, pid, index, version);
|
srv_process_gen (ale->p, index, version);
|
||||||
|
|
||||||
chan[BUFSIZ -1] = '\0';
|
chan[BUFSIZ -1] = '\0';
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ struct app_list_elm;
|
|||||||
|
|
||||||
// parse pubsubd init msg (sent in TMPDIR/<service>)
|
// parse pubsubd init msg (sent in TMPDIR/<service>)
|
||||||
//
|
//
|
||||||
// line fmt : pid index version action chan
|
// TODO TLV line fmt : index version action chan
|
||||||
// action : quit | pub | sub
|
// action : quit | pub | sub
|
||||||
int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
|
int pubsubd_get_new_process (const char *spath, struct app_list_elm *ale
|
||||||
, struct channels *chans, struct channel **c);
|
, struct channels *chans, struct channel **c);
|
||||||
|
Reference in New Issue
Block a user