|
|
@@ -45,30 +45,38 @@ https://e2li.org -> menu : Projet Prosecco. |
|
|
|
#include <arpa/inet.h> |
|
|
|
#include <pthread.h> |
|
|
|
|
|
|
|
#define Version "1.01" |
|
|
|
#define Version "1.02" |
|
|
|
|
|
|
|
#define F_GETPIPE_SZ 1032 |
|
|
|
#define F_SETPIPE_SZ 1031 |
|
|
|
|
|
|
|
static int RUN=1, REQ=0, ENDT=0, REPR=0, JCTL=0, LogC=0, WH=1, p1[2],Trace=0; |
|
|
|
static int RUN=1, REQ=0, ENDT=0, REINI=0, REPR=0, JCTL=0, LogC=0, WH=1, p1[2],Trace=0; |
|
|
|
static pid_t pid; |
|
|
|
static char * NPROG, *IFACE=NULL; |
|
|
|
#define DELAYR 20 /* delai avant relance auto */ |
|
|
|
|
|
|
|
void interup (int S) |
|
|
|
{ |
|
|
|
if (S==SIGINT) { |
|
|
|
write(p1[1],"\n",1); |
|
|
|
REQ=1; return; |
|
|
|
} |
|
|
|
if (S==SIGCHLD) { |
|
|
|
if (waitpid(pid,NULL,WNOHANG) == pid) { |
|
|
|
ENDT=1; |
|
|
|
write(p1[1],"\n",1); |
|
|
|
} |
|
|
|
return; |
|
|
|
switch(S) { |
|
|
|
case SIGINT: |
|
|
|
write(p1[1],"\n",1); |
|
|
|
REQ=1; return; |
|
|
|
break; |
|
|
|
case SIGCHLD: |
|
|
|
if (waitpid(pid,NULL,WNOHANG) == pid) { |
|
|
|
ENDT=1; |
|
|
|
write(p1[1],"\n",1); |
|
|
|
} |
|
|
|
break; |
|
|
|
case SIGHUP: |
|
|
|
case SIGILL: |
|
|
|
case SIGSEGV: |
|
|
|
ENDT=S+1; |
|
|
|
write(p1[1],"\n",1); |
|
|
|
break; |
|
|
|
default: |
|
|
|
fprintf(stderr,"Reçu signal %d !!??\n",S); |
|
|
|
} |
|
|
|
fprintf(stderr,"Reçu signal %d !!??\n",S); |
|
|
|
} |
|
|
|
|
|
|
|
/* ### les niveaux de trace */ |
|
|
@@ -654,10 +662,11 @@ char *rep=NULL; |
|
|
|
size_t lr = 0; |
|
|
|
int n; |
|
|
|
while (1) { |
|
|
|
printf("Voulez-vous %s ?\n Taper O (OUI) ou N (NON) :\n",q); |
|
|
|
printf("Voulez-vous %s ?\n Taper O/o pour OUI, autre touche = NON :\n",q); |
|
|
|
if ((n = getline(&rep, &lr, stdin)) != 2) continue; |
|
|
|
if (*rep == 'O') return 1; |
|
|
|
if (*rep == 'N') return 0; |
|
|
|
if (*rep == 'o') return 1; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -695,6 +704,7 @@ pid_t pid; |
|
|
|
if (kill(pid,SIGUSR1) < 0) { /* verif processus acquisition */ |
|
|
|
ENDT=1; |
|
|
|
write(p1[1],"\n",1); |
|
|
|
break; |
|
|
|
} |
|
|
|
free(cmd); |
|
|
|
sprintf(pr,"\e[01;34m%s-> \e[00m",NPROG); |
|
|
@@ -844,6 +854,14 @@ pid_t pid; |
|
|
|
pr_encours(); |
|
|
|
comsh(com,EX_NOERR); |
|
|
|
break; |
|
|
|
case 'N' : |
|
|
|
if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); |
|
|
|
if (printQ("Re-initialiser")) { |
|
|
|
RUN = 0; |
|
|
|
REINI = 1; |
|
|
|
write(p1[1],"\n",1); |
|
|
|
} |
|
|
|
break; |
|
|
|
case 'S' : |
|
|
|
if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); |
|
|
|
RUN = 0; |
|
|
@@ -882,6 +900,7 @@ pid_t pid; |
|
|
|
printf(">\t\t: Traces des demandes triees\n"); |
|
|
|
printf("<\t\t: Traces des reponses triees\n"); |
|
|
|
} |
|
|
|
printf("N\t\t: Nouvelle initialisation\n"); |
|
|
|
printf("S\t\t: Stopper\n"); |
|
|
|
break; |
|
|
|
} |
|
|
@@ -1019,6 +1038,9 @@ int Inter=0, i, ie, np=0, opt; |
|
|
|
sleep(1); /* attend le fils en place */ |
|
|
|
if (kill(pid,SIGUSR1) < 0) return 6; |
|
|
|
signal(SIGCHLD,interup); |
|
|
|
signal(SIGHUP,interup); |
|
|
|
signal(SIGILL,interup); |
|
|
|
signal(SIGSEGV,interup); |
|
|
|
/* |
|
|
|
fcntl(p1[0], F_SETFL, O_NONBLOCK); |
|
|
|
flag0 = fcntl(0, F_GETFL, O_NONBLOCK); |
|
|
@@ -1042,7 +1064,8 @@ int Inter=0, i, ie, np=0, opt; |
|
|
|
tachePer1(); |
|
|
|
if ((n = getline(&line, &ll, fp)) > 0) { |
|
|
|
if (ENDT) { |
|
|
|
printf("Erreur : plus de tache d'analyse !\n"); break; |
|
|
|
if (ENDT==1) printf("Erreur : plus de tache d'analyse !\n"); |
|
|
|
break; |
|
|
|
} |
|
|
|
if (RUN == 0) break; |
|
|
|
if ((n==1) && (*line=='\n')) continue; |
|
|
@@ -1165,14 +1188,17 @@ int Inter=0, i, ie, np=0, opt; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
syslog(LOG_INFO,"Fin de l'analyse !"); |
|
|
|
if (REINI==0) { |
|
|
|
if (ENDT==1) syslog(LOG_INFO,"Fin de l'analyse !"); |
|
|
|
else syslog(LOG_WARNING,"Reçu signal %d !",ENDT-1); |
|
|
|
} |
|
|
|
free(line); |
|
|
|
free(cmd); |
|
|
|
kill(pid,SIGTERM); |
|
|
|
close(p1[0]); |
|
|
|
close(p1[1]); |
|
|
|
closelog(); |
|
|
|
if (ENDT) { /* relance auto */ |
|
|
|
if (ENDT|REINI) { /* relance auto */ |
|
|
|
if (T1) printf("Relance auto %s dans %d sec. ...\n",strPID, DELAYR); |
|
|
|
sleep(DELAYR); /* attend N s */ |
|
|
|
NP = (char**)malloc((sizeof(Pars))*(N+3)); |
|
|
|