version 1.83, 2011/09/14 14:34:28
|
version 1.96, 2011/10/10 10:58:12
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.1.3 |
RPL/2 (R) version 4.1.4 |
Copyright (C) 1989-2011 Dr. BERTRAND Joël |
Copyright (C) 1989-2011 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
Line 23
|
Line 23
|
#define MAIN_RPL |
#define MAIN_RPL |
#include "rpl-conv.h" |
#include "rpl-conv.h" |
|
|
#ifdef IPCS_SYSV |
|
#ifndef OS2 |
|
unsigned char *chemin_semaphores_SysV; |
|
#endif |
|
#endif |
|
|
|
|
|
/* |
/* |
================================================================================ |
================================================================================ |
Line 42 rplinit(int argc, char *argv[], unsigned
|
Line 36 rplinit(int argc, char *argv[], unsigned
|
# include "copyright-conv.h" |
# include "copyright-conv.h" |
# include "licence-conv.h" |
# include "licence-conv.h" |
|
|
|
char pile_signaux[SIGSTKSZ]; |
|
|
file *f_source; |
file *f_source; |
|
|
int erreur_historique; |
int erreur_historique; |
Line 105 rplinit(int argc, char *argv[], unsigned
|
Line 101 rplinit(int argc, char *argv[], unsigned
|
volatile unsigned char traitement_fichier_temporaire; |
volatile unsigned char traitement_fichier_temporaire; |
|
|
errno = 0; |
errno = 0; |
|
s_queue_signaux = NULL; |
|
routine_recursive = 0; |
pid_processus_pere = getpid(); |
pid_processus_pere = getpid(); |
|
|
# ifdef DEBUG_MEMOIRE |
# ifdef DEBUG_MEMOIRE |
Line 115 rplinit(int argc, char *argv[], unsigned
|
Line 113 rplinit(int argc, char *argv[], unsigned
|
setvbuf(stderr, NULL, _IOLBF, 0); |
setvbuf(stderr, NULL, _IOLBF, 0); |
|
|
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
sem_init(&semaphore_liste_threads, 0, 1); |
|
sem_init(&semaphore_gestionnaires_signaux, 0, 0); |
sem_init(&semaphore_gestionnaires_signaux, 0, 0); |
sem_init(&semaphore_gestionnaires_signaux_atomique, 0, 1); |
|
# else |
# else |
semaphore_liste_threads = sem_init2(1, sem_liste_threads); |
semaphore_gestionnaires_signaux = sem_init2(0, getpid(), SEM_SIGNAUX); |
semaphore_gestionnaires_signaux = sem_init2(0, sem_gestionnaires_signaux); |
|
semaphore_gestionnaires_signaux_atomique = sem_init2(1, |
if (semaphore_gestionnaires_signaux == SEM_FAILED) |
sem_gestionnaires_signaux_atomique); |
|
|
|
if ((semaphore_liste_threads == SEM_FAILED) || |
|
(semaphore_gestionnaires_signaux == SEM_FAILED) || |
|
(semaphore_gestionnaires_signaux_atomique == SEM_FAILED)) |
|
{ |
{ |
erreur = d_es_allocation_memoire; |
erreur = d_es_allocation_memoire; |
|
|
Line 188 rplinit(int argc, char *argv[], unsigned
|
Line 179 rplinit(int argc, char *argv[], unsigned
|
(*s_etat_processus).exception = d_ep; |
(*s_etat_processus).exception = d_ep; |
(*s_etat_processus).erreur_systeme = d_es; |
(*s_etat_processus).erreur_systeme = d_es; |
(*s_etat_processus).erreur_execution = d_ex; |
(*s_etat_processus).erreur_execution = d_ex; |
(*s_etat_processus).compteur_violation_d_acces = 0; |
|
(*s_etat_processus).tid_courant = pthread_self(); |
|
|
|
(*s_etat_processus).rpl_home = rpl_home; |
(*s_etat_processus).rpl_home = rpl_home; |
|
|
Line 205 rplinit(int argc, char *argv[], unsigned
|
Line 194 rplinit(int argc, char *argv[], unsigned
|
pthread_mutexattr_destroy(&attributs_mutex); |
pthread_mutexattr_destroy(&attributs_mutex); |
|
|
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
sem_init(&((*s_etat_processus).semaphore_fork), 0, 0); |
sem_init(&((*s_etat_processus).semaphore_fork), 0, 0); |
# else |
# else |
if (((*s_etat_processus).semaphore_fork = sem_init2(0, sem_fork)) == |
if (((*s_etat_processus).semaphore_fork = sem_init3(0, getpid(), |
SEM_FAILED) |
pthread_self(), SEM_FORK)) == SEM_FAILED) |
{ |
|
if ((*s_etat_processus).langue == 'F') |
|
{ |
|
uprintf("+++Système : Mémoire insuffisante\n"); |
|
} |
|
else |
|
{ |
{ |
uprintf("+++System : Not enough memory\n"); |
if ((*s_etat_processus).langue == 'F') |
} |
{ |
|
uprintf("+++Système : Mémoire insuffisante\n"); |
|
} |
|
else |
|
{ |
|
uprintf("+++System : Not enough memory\n"); |
|
} |
|
|
return(EXIT_FAILURE); |
return(EXIT_FAILURE); |
} |
} |
# endif |
# endif |
|
|
pthread_mutexattr_init(&attributs_mutex); |
pthread_mutexattr_init(&attributs_mutex); |
Line 244 rplinit(int argc, char *argv[], unsigned
|
Line 233 rplinit(int argc, char *argv[], unsigned
|
(*s_etat_processus).chemin_fichiers_temporaires = |
(*s_etat_processus).chemin_fichiers_temporaires = |
recherche_chemin_fichiers_temporaires(s_etat_processus); |
recherche_chemin_fichiers_temporaires(s_etat_processus); |
|
|
# ifdef IPCS_SYSV |
|
# ifndef OS2 |
|
chemin_semaphores_SysV = |
|
(*s_etat_processus).chemin_fichiers_temporaires; |
|
# endif |
|
# endif |
|
|
|
insertion_thread(s_etat_processus, d_vrai); |
insertion_thread(s_etat_processus, d_vrai); |
creation_queue_signaux(s_etat_processus); |
creation_queue_signaux(s_etat_processus); |
|
|
Line 334 rplinit(int argc, char *argv[], unsigned
|
Line 316 rplinit(int argc, char *argv[], unsigned
|
home = ""; |
home = ""; |
} |
} |
|
|
// Initialisation d'une clef |
# ifdef HAVE_STACK_OVERFLOW_RECOVERY |
|
if (stackoverflow_install_handler(interruption_depassement_pile, |
if (pthread_key_create(&semaphore_fork_processus_courant, NULL) != 0) |
pile_signaux, sizeof(pile_signaux)) != 0) |
{ |
|
if ((*s_etat_processus).langue == 'F') |
|
{ |
|
printf("+++Système : Mémoire insuffisante\n"); |
|
} |
|
else |
|
{ |
{ |
printf("+++System : Not enough memory\n"); |
erreur = d_es_signal; |
} |
|
|
|
return(EXIT_FAILURE); |
if ((*s_etat_processus).langue == 'F') |
} |
{ |
|
printf("+++Système : Initialisation de la pile alternative " |
# ifndef SEMAPHORES_NOMMES |
"impossible\n"); |
if (pthread_setspecific(semaphore_fork_processus_courant, |
} |
&((*s_etat_processus).semaphore_fork)) != 0) |
else |
# else |
{ |
if (pthread_setspecific(semaphore_fork_processus_courant, |
printf("+++System : Initialization of alternate " |
(*s_etat_processus).semaphore_fork) != 0) |
"stack failed\n"); |
# endif |
} |
{ |
|
if ((*s_etat_processus).langue == 'F') |
|
{ |
|
printf("+++Système : Mémoire insuffisante\n"); |
|
} |
|
else |
|
{ |
|
printf("+++System : Not enough memory\n"); |
|
} |
|
|
|
return(EXIT_FAILURE); |
|
} |
|
|
|
// Initialisation d'une pile de signal pour récupérer les |
|
// débordement de pile |
|
|
|
# if !defined(Cygwin) && !defined(OpenBSD) |
|
if (((*s_etat_processus).pile_signal.ss_sp = |
|
malloc((*s_etat_processus).pile_signal.ss_size = |
|
SIGSTKSZ)) == NULL) |
|
{ |
|
erreur = d_es_allocation_memoire; |
|
|
|
if ((*s_etat_processus).langue == 'F') |
return(EXIT_FAILURE); |
{ |
|
printf("+++Système : Mémoire insuffisante\n"); |
|
} |
|
else |
|
{ |
|
printf("+++System : Not enough memory\n"); |
|
} |
} |
|
# else |
return(EXIT_FAILURE); |
|
} |
|
|
|
(*s_etat_processus).pile_signal.ss_flags = 0; |
|
|
|
if (sigaltstack(&((*s_etat_processus).pile_signal), NULL) != 0) |
|
{ |
|
erreur = d_es_signal; |
|
|
|
if ((*s_etat_processus).langue == 'F') |
if ((*s_etat_processus).langue == 'F') |
{ |
{ |
printf("+++Système : Initialisation de la pile spécifique de signal" |
printf("+++Attention : Le système ne supporte pas de pile " |
" impossible\n"); |
"alternative\n"); |
} |
} |
else |
else |
{ |
{ |
printf("+++System : Initialization of signal stack failed\n"); |
printf("+++Warning : Operating system does not support alternate " |
|
"stack\n"); |
} |
} |
|
|
return(EXIT_FAILURE); |
|
} |
|
# endif |
# endif |
|
|
action.sa_handler = interruption1; |
action.sa_handler = interruption1; |
action.sa_flags = SA_ONSTACK; |
action.sa_flags = 0; |
|
|
if (sigaction(SIGINT, &action, NULL) != 0) |
if (sigaction(SIGINT, &action, NULL) != 0) |
{ |
{ |
Line 490 rplinit(int argc, char *argv[], unsigned
|
Line 426 rplinit(int argc, char *argv[], unsigned
|
} |
} |
|
|
action.sa_handler = interruption2; |
action.sa_handler = interruption2; |
action.sa_flags = SA_NODEFER | SA_ONSTACK; |
action.sa_flags = 0; |
|
|
if (sigaction(SIGTSTP, &action, NULL) != 0) |
if (sigaction(SIGTSTP, &action, NULL) != 0) |
{ |
{ |
Line 528 rplinit(int argc, char *argv[], unsigned
|
Line 464 rplinit(int argc, char *argv[], unsigned
|
} |
} |
|
|
action.sa_handler = interruption5; |
action.sa_handler = interruption5; |
action.sa_flags = SA_NODEFER | SA_ONSTACK; |
action.sa_flags = 0; |
|
|
if (sigaction(SIGPIPE, &action, NULL) != 0) |
if (sigaction(SIGPIPE, &action, NULL) != 0) |
{ |
{ |
Line 568 rplinit(int argc, char *argv[], unsigned
|
Line 504 rplinit(int argc, char *argv[], unsigned
|
} |
} |
|
|
action.sa_handler = interruption1; |
action.sa_handler = interruption1; |
action.sa_flags = SA_NODEFER | SA_ONSTACK; |
action.sa_flags = 0; |
|
|
if (sigaction(SIGALRM, &action, NULL) != 0) |
if (sigaction(SIGUSR1, &action, NULL) != 0) |
{ |
{ |
erreur = d_es_signal; |
erreur = d_es_signal; |
|
|
Line 588 rplinit(int argc, char *argv[], unsigned
|
Line 524 rplinit(int argc, char *argv[], unsigned
|
} |
} |
|
|
signal_test = SIGTEST; |
signal_test = SIGTEST; |
kill(getpid(), SIGALRM); |
kill(getpid(), SIGUSR1); |
|
|
if (signal_test != SIGALRM) |
if (signal_test != SIGUSR1) |
{ |
{ |
erreur = d_es_signal; |
erreur = d_es_signal; |
|
|
Line 655 rplinit(int argc, char *argv[], unsigned
|
Line 591 rplinit(int argc, char *argv[], unsigned
|
option_t = d_faux; |
option_t = d_faux; |
option_v = d_faux; |
option_v = d_faux; |
|
|
|
// Lorsque le programme est appelé depuis un shebang, argv[0] contient |
|
// le chemin du programme et argv[1] tous les arguments. |
|
// argv[2] contient quant à lui le nom du script RPL/2. |
|
// |
|
// Exemple : |
|
// argv[0] : /usr/local/bin/rpl |
|
// argv[1] : -csdp -t 800 |
|
// argv[2] : ./on_exit.rpl |
|
|
while((--argc) > 0) |
while((--argc) > 0) |
{ |
{ |
if ((*(++argv))[0] == '-') |
if ((*(++argv))[0] == '-') |
Line 1450 rplinit(int argc, char *argv[], unsigned
|
Line 1395 rplinit(int argc, char *argv[], unsigned
|
break; |
break; |
} |
} |
|
|
|
case '-': |
|
case ' ': |
|
{ |
|
break; |
|
} |
|
|
default : |
default : |
{ |
{ |
if ((*s_etat_processus).langue == 'F') |
if ((*s_etat_processus).langue == 'F') |
Line 1494 rplinit(int argc, char *argv[], unsigned
|
Line 1445 rplinit(int argc, char *argv[], unsigned
|
} |
} |
} |
} |
|
|
|
/* |
|
* Dans le cas où le programme est appelé avec l'option -d, |
|
* on ne récupère par les signaux de violation d'accès. On |
|
* tente simplement la récupération des dépassements de pile. |
|
*/ |
|
|
if (debug == d_faux) |
if (debug == d_faux) |
{ |
{ |
|
|
|
# ifdef HAVE_SIGSEGV_RECOVERY |
|
if (sigsegv_install_handler(interruption_violation_access) != 0) |
|
{ |
|
erreur = d_es_signal; |
|
|
|
if ((*s_etat_processus).langue == 'F') |
|
{ |
|
printf("+++Système : Initialisation de la pile alternative " |
|
"impossible\n"); |
|
} |
|
else |
|
{ |
|
printf("+++System : Initialization of alternate " |
|
"stack failed\n"); |
|
} |
|
|
|
return(EXIT_FAILURE); |
|
} |
|
# else |
action.sa_handler = interruption3; |
action.sa_handler = interruption3; |
action.sa_flags = SA_NODEFER | SA_ONSTACK; |
action.sa_flags = 0; |
|
|
if (sigaction(SIGSEGV, &action, NULL) != 0) |
if (sigaction(SIGSEGV, &action, NULL) != 0) |
{ |
{ |
Line 1515 rplinit(int argc, char *argv[], unsigned
|
Line 1492 rplinit(int argc, char *argv[], unsigned
|
return(EXIT_FAILURE); |
return(EXIT_FAILURE); |
} |
} |
|
|
|
signal_test = SIGTEST; |
|
kill(getpid(), SIGSEGV); |
|
|
|
if (signal_test != SIGSEGV) |
|
{ |
|
erreur = d_es_signal; |
|
|
|
if ((*s_etat_processus).langue == 'F') |
|
{ |
|
printf("+++Système : Initialisation des signaux POSIX " |
|
"impossible\n"); |
|
} |
|
else |
|
{ |
|
printf("+++System : Initialization of POSIX signals " |
|
"failed\n"); |
|
} |
|
|
|
return(EXIT_FAILURE); |
|
} |
|
# endif |
|
|
if (sigaction(SIGBUS, &action, NULL) != 0) |
if (sigaction(SIGBUS, &action, NULL) != 0) |
{ |
{ |
if ((*s_etat_processus).langue == 'F') |
if ((*s_etat_processus).langue == 'F') |
Line 1530 rplinit(int argc, char *argv[], unsigned
|
Line 1529 rplinit(int argc, char *argv[], unsigned
|
|
|
return(EXIT_FAILURE); |
return(EXIT_FAILURE); |
} |
} |
|
|
|
signal_test = SIGTEST; |
|
kill(getpid(), SIGBUS); |
|
|
|
if (signal_test != SIGBUS) |
|
{ |
|
erreur = d_es_signal; |
|
|
|
if ((*s_etat_processus).langue == 'F') |
|
{ |
|
printf("+++Système : Initialisation des signaux POSIX " |
|
"impossible\n"); |
|
} |
|
else |
|
{ |
|
printf("+++System : Initialization of POSIX signals " |
|
"failed\n"); |
|
} |
|
|
|
return(EXIT_FAILURE); |
|
} |
|
|
} |
} |
|
|
if (option_n == d_vrai) |
if (option_n == d_vrai) |
{ |
{ |
action.sa_handler = interruption4; |
action.sa_handler = interruption4; |
action.sa_flags = SA_ONSTACK; |
action.sa_flags = 0; |
|
|
if (sigaction(SIGHUP, &action, NULL) != 0) |
if (sigaction(SIGHUP, &action, NULL) != 0) |
{ |
{ |
Line 2679 rplinit(int argc, char *argv[], unsigned
|
Line 2700 rplinit(int argc, char *argv[], unsigned
|
lancement_daemon(s_etat_processus); |
lancement_daemon(s_etat_processus); |
} |
} |
|
|
// A FIXER |
|
// création signaux |
|
if (option_p == d_faux) |
if (option_p == d_faux) |
{ |
{ |
if (setjmp(contexte_initial) == 0) |
if (setjmp(contexte_initial) == 0) |
Line 2723 rplinit(int argc, char *argv[], unsigned
|
Line 2742 rplinit(int argc, char *argv[], unsigned
|
} |
} |
} |
} |
} |
} |
// A FIXER |
|
// destruction signaux |
|
} |
} |
|
|
liberation(s_etat_processus, (*s_etat_processus).at_exit); |
liberation(s_etat_processus, (*s_etat_processus).at_exit); |
Line 2959 rplinit(int argc, char *argv[], unsigned
|
Line 2976 rplinit(int argc, char *argv[], unsigned
|
.thread).nombre_objets_dans_pipe--; |
.thread).nombre_objets_dans_pipe--; |
|
|
action.sa_handler = SIG_IGN; |
action.sa_handler = SIG_IGN; |
action.sa_flags = SA_ONSTACK; |
action.sa_flags = 0; |
|
|
if (sigaction(SIGPIPE, &action, ®istre) |
if (sigaction(SIGPIPE, &action, ®istre) |
!= 0) |
!= 0) |
Line 3005 rplinit(int argc, char *argv[], unsigned
|
Line 3022 rplinit(int argc, char *argv[], unsigned
|
} |
} |
|
|
nanosleep(&attente, NULL); |
nanosleep(&attente, NULL); |
|
scrutation_interruptions(s_etat_processus); |
pthread_mutex_lock(&((*s_etat_processus).mutex)); |
pthread_mutex_lock(&((*s_etat_processus).mutex)); |
} |
} |
|
|
Line 3535 rplinit(int argc, char *argv[], unsigned
|
Line 3553 rplinit(int argc, char *argv[], unsigned
|
sem_destroy(&((*s_etat_processus).semaphore_fork)); |
sem_destroy(&((*s_etat_processus).semaphore_fork)); |
# else |
# else |
sem_post((*s_etat_processus).semaphore_fork); |
sem_post((*s_etat_processus).semaphore_fork); |
sem_destroy2((*s_etat_processus).semaphore_fork, sem_fork); |
sem_destroy3((*s_etat_processus).semaphore_fork, getpid(), pthread_self(), |
|
SEM_FORK); |
# endif |
# endif |
|
|
free((*s_etat_processus).localisation); |
free((*s_etat_processus).localisation); |
|
|
# ifndef SEMAPHORES_NOMMES |
pthread_mutex_destroy(&mutex_liste_threads); |
sem_destroy(&semaphore_liste_threads); |
pthread_mutex_destroy(&mutex_gestionnaires_signaux_atomique); |
# else |
|
sem_destroy2(semaphore_liste_threads, sem_liste_threads); |
|
# endif |
|
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
sem_post(&semaphore_gestionnaires_signaux); |
sem_post(&semaphore_gestionnaires_signaux); |
sem_destroy(&semaphore_gestionnaires_signaux); |
sem_destroy(&semaphore_gestionnaires_signaux); |
sem_destroy(&semaphore_gestionnaires_signaux_atomique); |
|
# else |
# else |
sem_post(semaphore_gestionnaires_signaux); |
sem_post(semaphore_gestionnaires_signaux); |
sem_destroy2(semaphore_gestionnaires_signaux, sem_gestionnaires_signaux); |
sem_destroy2(semaphore_gestionnaires_signaux, getpid(), SEM_SIGNAUX); |
sem_destroy2(semaphore_gestionnaires_signaux_atomique, |
|
sem_gestionnaires_signaux_atomique); |
|
# endif |
# endif |
|
|
destruction_queue_signaux(s_etat_processus); |
destruction_queue_signaux(s_etat_processus); |
Line 3567 rplinit(int argc, char *argv[], unsigned
|
Line 3581 rplinit(int argc, char *argv[], unsigned
|
analyse_post_mortem(); |
analyse_post_mortem(); |
# endif |
# endif |
|
|
|
# ifdef HAVE_STACK_OVERFLOW_RECOVERY |
|
stackoverflow_deinstall_handler(); |
|
# endif |
|
|
|
# ifdef HAVE_SIGSEGV_RECOVERY |
|
if (debug == d_faux) |
|
{ |
|
sigsegv_deinstall_handler(); |
|
} |
|
# endif |
|
|
return((erreur == d_absence_erreur) ? EXIT_SUCCESS : EXIT_FAILURE); |
return((erreur == d_absence_erreur) ? EXIT_SUCCESS : EXIT_FAILURE); |
} |
} |
|
|
Line 3622 informations(struct_processus *s_etat_pr
|
Line 3647 informations(struct_processus *s_etat_pr
|
return; |
return; |
} |
} |
|
|
|
|
|
unsigned char * |
|
date_compilation() |
|
{ |
|
unsigned char *date; |
|
|
|
if ((date = malloc((strlen(d_date_en_rpl) + 1) * sizeof(unsigned char))) |
|
== NULL) |
|
{ |
|
return(NULL); |
|
} |
|
|
|
strcpy(date, d_date_en_rpl); |
|
|
|
return(date); |
|
} |
|
|
// vim: ts=4 |
// vim: ts=4 |