version 1.92, 2011/09/20 15:45:53
|
version 1.107, 2012/01/05 10:19:05
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.1.3 |
RPL/2 (R) version 4.1.5 |
Copyright (C) 1989-2011 Dr. BERTRAND Joël |
Copyright (C) 1989-2012 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
|
|
Line 31
|
Line 31
|
*/ |
*/ |
|
|
int |
int |
rplinit(int argc, char *argv[], unsigned char ***resultats, char *rpl_home) |
rplinit(int argc, char *argv[], char *envp[], |
|
unsigned char ***resultats, char *rpl_home) |
{ |
{ |
# include "copyright-conv.h" |
# include "copyright-conv.h" |
# include "licence-conv.h" |
# include "licence-conv.h" |
|
|
|
char **arg_exec; |
|
|
|
# ifdef HAVE_STACK_OVERFLOW_RECOVERY |
|
char pile_signaux[SIGSTKSZ]; |
|
# endif |
|
|
|
# define RPL_PATH_MAX 1024 |
|
char repertoire_initial[RPL_PATH_MAX]; |
|
|
file *f_source; |
file *f_source; |
|
|
int erreur_historique; |
int erreur_historique; |
Line 100 rplinit(int argc, char *argv[], unsigned
|
Line 110 rplinit(int argc, char *argv[], unsigned
|
|
|
errno = 0; |
errno = 0; |
s_queue_signaux = NULL; |
s_queue_signaux = NULL; |
|
routine_recursive = 0; |
pid_processus_pere = getpid(); |
pid_processus_pere = getpid(); |
|
|
# ifdef DEBUG_MEMOIRE |
# ifdef DEBUG_MEMOIRE |
Line 171 rplinit(int argc, char *argv[], unsigned
|
Line 182 rplinit(int argc, char *argv[], unsigned
|
(*s_etat_processus).langue = 'E'; |
(*s_etat_processus).langue = 'E'; |
} |
} |
|
|
|
if (getcwd(repertoire_initial, RPL_PATH_MAX) == NULL) |
|
{ |
|
if ((langue = getenv("LANG")) != NULL) |
|
{ |
|
if (strncmp(langue, "fr", 2) == 0) |
|
{ |
|
uprintf("+++Système : Mémoire insuffisante\n"); |
|
} |
|
else |
|
{ |
|
uprintf("+++System : Not enough memory\n"); |
|
} |
|
} |
|
else |
|
{ |
|
uprintf("+++System : Not enough memory\n"); |
|
} |
|
|
|
return(EXIT_FAILURE); |
|
} |
|
|
|
if ((arg_exec = malloc((argc + 1) * sizeof(char *))) == NULL) |
|
{ |
|
if ((langue = getenv("LANG")) != NULL) |
|
{ |
|
if (strncmp(langue, "fr", 2) == 0) |
|
{ |
|
uprintf("+++Système : Mémoire insuffisante\n"); |
|
} |
|
else |
|
{ |
|
uprintf("+++System : Not enough memory\n"); |
|
} |
|
} |
|
else |
|
{ |
|
uprintf("+++System : Not enough memory\n"); |
|
} |
|
|
|
return(EXIT_FAILURE); |
|
} |
|
|
|
for(i = 0; i < (unsigned long) argc; i++) |
|
{ |
|
arg_exec[i] = argv[i]; |
|
} |
|
|
|
argv[argc] = NULL; |
|
|
initialisation_contexte_cas(s_etat_processus); |
initialisation_contexte_cas(s_etat_processus); |
|
|
(*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).requete_redemarrage = d_faux; |
(*s_etat_processus).rpl_home = rpl_home; |
(*s_etat_processus).rpl_home = rpl_home; |
|
|
pthread_mutexattr_init(&attributs_mutex); |
pthread_mutexattr_init(&attributs_mutex); |
Line 285 rplinit(int argc, char *argv[], unsigned
|
Line 345 rplinit(int argc, char *argv[], unsigned
|
|
|
if ((*s_etat_processus).langue == 'F') |
if ((*s_etat_processus).langue == 'F') |
{ |
{ |
printf("+++Copyright (C) 1989 à 2010, 2011 BERTRAND Joël\n"); |
printf("+++Copyright (C) 1989 à 2011, 2012 BERTRAND Joël\n"); |
} |
} |
else |
else |
{ |
{ |
printf("+++Copyright (C) 1989 to 2010, 2011 BERTRAND Joel\n"); |
printf("+++Copyright (C) 1989 to 2011, 2012 BERTRAND Joel\n"); |
} |
} |
|
|
if (getenv("HOME") != NULL) |
if (getenv("HOME") != NULL) |
Line 314 rplinit(int argc, char *argv[], unsigned
|
Line 374 rplinit(int argc, char *argv[], unsigned
|
home = ""; |
home = ""; |
} |
} |
|
|
// Initialisation d'une pile de signal pour récupérer les |
# ifdef HAVE_STACK_OVERFLOW_RECOVERY |
// débordement de pile |
if (stackoverflow_install_handler(interruption_depassement_pile, |
|
pile_signaux, sizeof(pile_signaux)) != 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"); |
|
} |
|
|
# if !defined(Cygwin) && !defined(OpenBSD) |
return(EXIT_FAILURE); |
if (((*s_etat_processus).pile_signal.ss_sp = |
} |
malloc((*s_etat_processus).pile_signal.ss_size = |
# else |
SIGSTKSZ)) == NULL) |
if ((*s_etat_processus).langue == 'F') |
|
{ |
|
printf("+++Attention : Le système ne supporte pas de pile " |
|
"alternative\n"); |
|
} |
|
else |
|
{ |
|
printf("+++Warning : Operating system does not support alternate " |
|
"stack\n"); |
|
} |
|
# endif |
|
|
|
action.sa_handler = interruption1; |
|
action.sa_flags = 0; |
|
|
|
if (sigaction(SIGINT, &action, NULL) != 0) |
{ |
{ |
erreur = d_es_allocation_memoire; |
erreur = d_es_signal; |
|
|
if ((*s_etat_processus).langue == 'F') |
if ((*s_etat_processus).langue == 'F') |
{ |
{ |
printf("+++Système : Mémoire insuffisante\n"); |
printf("+++Système : Initialisation des signaux POSIX " |
|
"impossible\n"); |
} |
} |
else |
else |
{ |
{ |
printf("+++System : Not enough memory\n"); |
printf("+++System : Initialization of POSIX signals failed\n"); |
} |
} |
|
|
return(EXIT_FAILURE); |
return(EXIT_FAILURE); |
} |
} |
|
|
(*s_etat_processus).pile_signal.ss_flags = 0; |
signal_test = SIGTEST; |
|
kill(getpid(), SIGINT); |
|
|
if (sigaltstack(&((*s_etat_processus).pile_signal), NULL) != 0) |
if (signal_test != SIGINT) |
{ |
{ |
erreur = d_es_signal; |
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("+++Système : Initialisation des signaux POSIX " |
" impossible\n"); |
"impossible\n"); |
} |
} |
else |
else |
{ |
{ |
printf("+++System : Initialization of signal stack failed\n"); |
printf("+++System : Initialization of POSIX signals failed\n"); |
} |
} |
|
|
return(EXIT_FAILURE); |
return(EXIT_FAILURE); |
} |
} |
# endif |
|
|
|
action.sa_handler = interruption1; |
if (sigaction(SIGTERM, &action, NULL) != 0) |
action.sa_flags = SA_ONSTACK; |
|
|
|
if (sigaction(SIGINT, &action, NULL) != 0) |
|
{ |
{ |
erreur = d_es_signal; |
erreur = d_es_signal; |
|
|
Line 377 rplinit(int argc, char *argv[], unsigned
|
Line 464 rplinit(int argc, char *argv[], unsigned
|
} |
} |
|
|
signal_test = SIGTEST; |
signal_test = SIGTEST; |
kill(getpid(), SIGINT); |
kill(getpid(), SIGTERM); |
|
|
if (signal_test != SIGINT) |
if (signal_test != SIGTERM) |
{ |
{ |
erreur = d_es_signal; |
erreur = d_es_signal; |
|
|
Line 396 rplinit(int argc, char *argv[], unsigned
|
Line 483 rplinit(int argc, char *argv[], unsigned
|
return(EXIT_FAILURE); |
return(EXIT_FAILURE); |
} |
} |
|
|
if (sigaction(SIGTERM, &action, NULL) != 0) |
if (sigaction(SIGALRM, &action, NULL) != 0) |
{ |
{ |
erreur = d_es_signal; |
erreur = d_es_signal; |
|
|
Line 414 rplinit(int argc, char *argv[], unsigned
|
Line 501 rplinit(int argc, char *argv[], unsigned
|
} |
} |
|
|
signal_test = SIGTEST; |
signal_test = SIGTEST; |
kill(getpid(), SIGTERM); |
kill(getpid(), SIGALRM); |
|
|
if (signal_test != SIGTERM) |
if (signal_test != SIGALRM) |
{ |
{ |
erreur = d_es_signal; |
erreur = d_es_signal; |
|
|
Line 434 rplinit(int argc, char *argv[], unsigned
|
Line 521 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 472 rplinit(int argc, char *argv[], unsigned
|
Line 559 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 512 rplinit(int argc, char *argv[], unsigned
|
Line 599 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 532 rplinit(int argc, char *argv[], unsigned
|
Line 619 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 1453 rplinit(int argc, char *argv[], unsigned
|
Line 1540 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 1474 rplinit(int argc, char *argv[], unsigned
|
Line 1587 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 1489 rplinit(int argc, char *argv[], unsigned
|
Line 1624 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 1875 rplinit(int argc, char *argv[], unsigned
|
Line 2032 rplinit(int argc, char *argv[], unsigned
|
(*s_etat_processus).arbre_instructions = NULL; |
(*s_etat_processus).arbre_instructions = NULL; |
|
|
(*s_etat_processus).tid_processus_pere = pthread_self(); |
(*s_etat_processus).tid_processus_pere = pthread_self(); |
|
(*s_etat_processus).tid= pthread_self(); |
(*s_etat_processus).pid_processus_pere = getpid(); |
(*s_etat_processus).pid_processus_pere = getpid(); |
(*s_etat_processus).processus_detache = d_vrai; |
(*s_etat_processus).processus_detache = d_vrai; |
(*s_etat_processus).var_volatile_processus_pere = -1; |
(*s_etat_processus).var_volatile_processus_pere = -1; |
Line 2693 rplinit(int argc, char *argv[], unsigned
|
Line 2851 rplinit(int argc, char *argv[], unsigned
|
l_element_courant = (*s_etat_processus).liste_mutexes; |
l_element_courant = (*s_etat_processus).liste_mutexes; |
while(l_element_courant != NULL) |
while(l_element_courant != NULL) |
{ |
{ |
pthread_mutex_trylock(&((*((struct_mutex *) |
|
(*(*((struct_liste_chainee *) |
|
l_element_courant)).donnee).objet)).mutex)); |
|
pthread_mutex_unlock(&((*((struct_mutex *) |
|
(*(*((struct_liste_chainee *) |
|
l_element_courant)).donnee).objet)).mutex)); |
|
pthread_mutex_destroy(&((*((struct_mutex *) |
|
(*(*((struct_liste_chainee *) |
|
l_element_courant)).donnee).objet)).mutex)); |
|
|
|
liberation(s_etat_processus, |
liberation(s_etat_processus, |
(*((struct_liste_chainee *) |
(*((struct_liste_chainee *) |
l_element_courant)).donnee); |
l_element_courant)).donnee); |
Line 2914 rplinit(int argc, char *argv[], unsigned
|
Line 3062 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 3487 rplinit(int argc, char *argv[], unsigned
|
Line 3635 rplinit(int argc, char *argv[], unsigned
|
pthread_mutex_destroy(&((*s_etat_processus).mutex_allocation)); |
pthread_mutex_destroy(&((*s_etat_processus).mutex_allocation)); |
|
|
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
sem_post(&((*s_etat_processus).semaphore_fork); |
sem_post(&((*s_etat_processus).semaphore_fork)); |
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_destroy3((*s_etat_processus).semaphore_fork, getpid(), pthread_self(), |
sem_destroy3((*s_etat_processus).semaphore_fork, getpid(), pthread_self(), |
Line 3512 rplinit(int argc, char *argv[], unsigned
|
Line 3660 rplinit(int argc, char *argv[], unsigned
|
liberation_contexte_cas(s_etat_processus); |
liberation_contexte_cas(s_etat_processus); |
|
|
free((*s_etat_processus).chemin_fichiers_temporaires); |
free((*s_etat_processus).chemin_fichiers_temporaires); |
|
|
|
if ((*s_etat_processus).requete_redemarrage == d_vrai) |
|
{ |
|
chdir(repertoire_initial); |
|
execvp(arg_exec[0], &(arg_exec[0])); |
|
erreur = d_erreur; |
|
} |
|
|
|
free(arg_exec); |
free(s_etat_processus); |
free(s_etat_processus); |
|
|
# ifdef DEBUG_MEMOIRE |
# ifdef DEBUG_MEMOIRE |
Line 3519 rplinit(int argc, char *argv[], unsigned
|
Line 3676 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 3574 informations(struct_processus *s_etat_pr
|
Line 3742 informations(struct_processus *s_etat_pr
|
return; |
return; |
} |
} |
|
|
|
|
|
logical1 |
|
controle_integrite(struct_processus *s_etat_processus, |
|
unsigned char *executable_candidat, unsigned char *executable) |
|
{ |
|
unsigned char *md5; |
|
unsigned char *sha1; |
|
|
|
if (strcmp(executable, "rplpp") == 0) |
|
{ |
|
md5 = rplpp_md5; |
|
sha1 = rplpp_sha1; |
|
} |
|
else if (strcmp(executable, "rplfile") == 0) |
|
{ |
|
md5 = rplfile_md5; |
|
sha1 = rplfile_sha1; |
|
} |
|
else if (strcmp(executable, "rpliconv") == 0) |
|
{ |
|
md5 = rpliconv_md5; |
|
sha1 = rpliconv_sha1; |
|
} |
|
else if (strcmp(executable, "rplawk") == 0) |
|
{ |
|
md5 = rplawk_md5; |
|
sha1 = rplawk_sha1; |
|
} |
|
else if (strcmp(executable, "rplconvert") == 0) |
|
{ |
|
md5 = rplconvert_md5; |
|
sha1 = rplconvert_sha1; |
|
} |
|
else |
|
{ |
|
return(d_faux); |
|
} |
|
|
|
if (controle(s_etat_processus, executable_candidat, "md5", md5) != d_vrai) |
|
{ |
|
return(d_faux); |
|
} |
|
|
|
if (controle(s_etat_processus, executable_candidat, "sha1", sha1) != d_vrai) |
|
{ |
|
return(d_faux); |
|
} |
|
|
|
return(d_vrai); |
|
} |
|
|
|
|
|
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 |