--- rpl/src/rpl.c 2011/09/09 12:23:25 1.81 +++ rpl/src/rpl.c 2011/09/15 17:51:44 1.85 @@ -105,6 +105,8 @@ rplinit(int argc, char *argv[], unsigned volatile unsigned char traitement_fichier_temporaire; errno = 0; + s_queue_signaux = NULL; + pid_processus_pere = getpid(); # ifdef DEBUG_MEMOIRE debug_memoire_initialisation(); @@ -114,18 +116,11 @@ rplinit(int argc, char *argv[], unsigned setvbuf(stderr, NULL, _IOLBF, 0); # ifndef SEMAPHORES_NOMMES - sem_init(&semaphore_liste_threads, 0, 1); sem_init(&semaphore_gestionnaires_signaux, 0, 0); - sem_init(&semaphore_gestionnaires_signaux_atomique, 0, 1); # else - semaphore_liste_threads = sem_init2(1, sem_liste_threads); semaphore_gestionnaires_signaux = sem_init2(0, sem_gestionnaires_signaux); - semaphore_gestionnaires_signaux_atomique = sem_init2(1, - sem_gestionnaires_signaux_atomique); - - if ((semaphore_liste_threads == SEM_FAILED) || - (semaphore_gestionnaires_signaux == SEM_FAILED) || - (semaphore_gestionnaires_signaux_atomique == SEM_FAILED)) + + if (semaphore_gestionnaires_signaux == SEM_FAILED) { erreur = d_es_allocation_memoire; @@ -202,24 +197,12 @@ rplinit(int argc, char *argv[], unsigned &attributs_mutex); pthread_mutexattr_destroy(&attributs_mutex); -# ifndef SEMAPHORES_NOMMES - sem_init(&((*s_etat_processus).semaphore_fork), 0, 0); -# else - if (((*s_etat_processus).semaphore_fork = sem_init2(0, sem_fork)) == - SEM_FAILED) - { - if ((*s_etat_processus).langue == 'F') - { - uprintf("+++Système : Mémoire insuffisante\n"); - } - else - { - uprintf("+++System : Not enough memory\n"); - } - - return(EXIT_FAILURE); - } -# endif + pthread_mutexattr_init(&attributs_mutex); + pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL); + pthread_mutex_init(&((*s_etat_processus).mutex_fork), + &attributs_mutex); + pthread_mutexattr_destroy(&attributs_mutex); + pthread_mutex_lock(&((*s_etat_processus).mutex_fork)); pthread_mutexattr_init(&attributs_mutex); pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL); @@ -243,20 +226,14 @@ rplinit(int argc, char *argv[], unsigned recherche_chemin_fichiers_temporaires(s_etat_processus); # ifdef IPCS_SYSV -# ifndef OS2 - chemin_semaphores_SysV = (*s_etat_processus).chemin_fichiers_temporaires; -# endif -# endif - -# ifdef _BROKEN_SIGINFO - creation_fifos_signaux(s_etat_processus); -# ifdef return -# undef return -# endif -# define return destruction_fifos_signaux(s_etat_processus); return +# ifndef OS2 + chemin_semaphores_SysV = + (*s_etat_processus).chemin_fichiers_temporaires; +# endif # endif insertion_thread(s_etat_processus, d_vrai); + creation_queue_signaux(s_etat_processus); # ifndef OS2 localisation_courante(s_etat_processus); @@ -338,42 +315,6 @@ rplinit(int argc, char *argv[], unsigned home = ""; } - // Initialisation d'une clef - - if (pthread_key_create(&semaphore_fork_processus_courant, NULL) != 0) - { - if ((*s_etat_processus).langue == 'F') - { - printf("+++Système : Mémoire insuffisante\n"); - } - else - { - printf("+++System : Not enough memory\n"); - } - - return(EXIT_FAILURE); - } - -# ifndef SEMAPHORES_NOMMES - if (pthread_setspecific(semaphore_fork_processus_courant, - &((*s_etat_processus).semaphore_fork)) != 0) -# else - if (pthread_setspecific(semaphore_fork_processus_courant, - (*s_etat_processus).semaphore_fork) != 0) -# 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 @@ -416,12 +357,8 @@ rplinit(int argc, char *argv[], unsigned } # endif -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption1; -# else action.sa_handler = interruption1; -# endif - action.sa_flags = SA_ONSTACK | SA_SIGINFO; + action.sa_flags = SA_ONSTACK; if (sigaction(SIGINT, &action, NULL) != 0) { @@ -497,12 +434,8 @@ rplinit(int argc, char *argv[], unsigned return(EXIT_FAILURE); } -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption2; -# else action.sa_handler = interruption2; -# endif - action.sa_flags = SA_NODEFER | SA_ONSTACK | SA_SIGINFO; + action.sa_flags = SA_NODEFER | SA_ONSTACK; if (sigaction(SIGTSTP, &action, NULL) != 0) { @@ -539,222 +472,8 @@ rplinit(int argc, char *argv[], unsigned return(EXIT_FAILURE); } -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption4; -# else - action.sa_handler = interruption4; -# endif - // SIGCONT ne doit pas pouvoir être appelé depuis son gestionnaire. - action.sa_flags = SA_ONSTACK | SA_SIGINFO; - - if (sigaction(SIGSTART, &action, NULL) != 0) - { - 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); - } - - signal_test = SIGTEST; - kill(getpid(), SIGSTART); - - if (signal_test != SIGSTART) - { - 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 (sigaction(SIGCONT, &action, NULL) != 0) - { - 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); - } - - signal_test = SIGTEST; - kill(getpid(), SIGCONT); - - if (signal_test != SIGCONT) - { - 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); - } - -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption5; -# else action.sa_handler = interruption5; -# endif - action.sa_flags = SA_NODEFER | SA_ONSTACK | SA_SIGINFO; - - if (sigaction(SIGFSTOP, &action, NULL) != 0) - { - 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); - } - - signal_test = SIGTEST; - kill(getpid(), SIGFSTOP); - - if (signal_test != SIGFSTOP) - { - 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); - } - -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption11; -# else - action.sa_handler = interruption11; -# endif - action.sa_flags = SA_NODEFER | SA_ONSTACK | SA_SIGINFO; - - if (sigaction(SIGFABORT, &action, NULL) != 0) - { - 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); - } - - signal_test = SIGTEST; - kill(getpid(), SIGFABORT); - - if (signal_test != SIGFABORT) - { - 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); - } - -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption8; -# else - action.sa_handler = interruption8; -# endif - action.sa_flags = SA_NODEFER | SA_ONSTACK | SA_SIGINFO; - - if (sigaction(SIGURG, &action, NULL) != 0) - { - 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); - } - - signal_test = SIGTEST; - kill(getpid(), SIGURG); - - if (signal_test != SIGURG) - { - 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); - } - -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption7; -# else - action.sa_handler = interruption7; -# endif - action.sa_flags = SA_NODEFER | SA_ONSTACK | SA_SIGINFO; + action.sa_flags = SA_NODEFER | SA_ONSTACK; if (sigaction(SIGPIPE, &action, NULL) != 0) { @@ -793,100 +512,8 @@ rplinit(int argc, char *argv[], unsigned return(EXIT_FAILURE); } -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption6; -# else - action.sa_handler = interruption6; -# endif - action.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_NODEFER; - - if (sigaction(SIGINJECT, &action, NULL) != 0) - { - 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); - } - - signal_test = SIGTEST; - kill(getpid(), SIGINJECT); - - if (signal_test != SIGINJECT) - { - 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); - } - -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption9; -# else - action.sa_handler = interruption9; -# endif - action.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_NODEFER; - - if (sigaction(SIGABORT, &action, NULL) != 0) - { - 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); - } - - signal_test = SIGTEST; - kill(getpid(), SIGABORT); - - if (signal_test != SIGABORT) - { - 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); - } - -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption1; -# else action.sa_handler = interruption1; -# endif - action.sa_flags = SA_NODEFER | SA_ONSTACK | SA_SIGINFO; + action.sa_flags = SA_NODEFER | SA_ONSTACK; if (sigaction(SIGALRM, &action, NULL) != 0) { @@ -925,12 +552,7 @@ rplinit(int argc, char *argv[], unsigned return(EXIT_FAILURE); } -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption3; -# else - action.sa_handler = interruption3; -# endif - action.sa_flags = SA_NODEFER | SA_ONSTACK | SA_SIGINFO; + signal_test = SIGTEST + 1; erreur = d_absence_erreur; core = d_faux; @@ -1819,6 +1441,9 @@ rplinit(int argc, char *argv[], unsigned if (debug == d_faux) { + action.sa_handler = interruption3; + action.sa_flags = SA_NODEFER | SA_ONSTACK; + if (sigaction(SIGSEGV, &action, NULL) != 0) { if ((*s_etat_processus).langue == 'F') @@ -1854,12 +1479,8 @@ rplinit(int argc, char *argv[], unsigned if (option_n == d_vrai) { -# ifndef _BROKEN_SIGINFO - action.sa_sigaction = interruption10; -# else - action.sa_handler = interruption10; -# endif - action.sa_flags = SA_ONSTACK | SA_SIGINFO; + action.sa_handler = interruption4; + action.sa_flags = SA_ONSTACK; if (sigaction(SIGHUP, &action, NULL) != 0) { @@ -2253,6 +1874,8 @@ rplinit(int argc, char *argv[], unsigned (*s_etat_processus).var_volatile_recursivite = 0; (*s_etat_processus).var_volatile_exception_gsl = 0; (*s_etat_processus).arret_depuis_abort = 0; + (*s_etat_processus).pointeur_signal_lecture = 0; + (*s_etat_processus).pointeur_signal_ecriture = 0; initialisation_allocateur(s_etat_processus); initialisation_drapeaux(s_etat_processus); @@ -3001,6 +2624,8 @@ rplinit(int argc, char *argv[], unsigned lancement_daemon(s_etat_processus); } +// A FIXER +// création signaux if (option_p == d_faux) { if (setjmp(contexte_initial) == 0) @@ -3043,6 +2668,8 @@ rplinit(int argc, char *argv[], unsigned } } } +// A FIXER +// destruction signaux } liberation(s_etat_processus, (*s_etat_processus).at_exit); @@ -3157,27 +2784,30 @@ rplinit(int argc, char *argv[], unsigned { if ((*s_etat_processus).var_volatile_alarme != 0) { - kill((*(*((struct_processus_fils *) + envoi_signal_processus( + (*(*((struct_processus_fils *) (*(*((struct_liste_chainee *) l_element_courant)).donnee).objet)) - .thread).pid, SIGURG); + .thread).pid, rpl_sigurg); } else { if ((*s_etat_processus).arret_depuis_abort == -1) { - kill((*(*((struct_processus_fils *) + envoi_signal_processus( + (*(*((struct_processus_fils *) (*(*((struct_liste_chainee *) l_element_courant)).donnee).objet)) - .thread).pid, SIGFABORT); + .thread).pid, rpl_sigabort); } else { - kill((*(*((struct_processus_fils *) + envoi_signal_processus( + (*(*((struct_processus_fils *) (*(*((struct_liste_chainee *) l_element_courant)).donnee).objet)) - .thread).pid, SIGFSTOP); + .thread).pid, rpl_sigstop); } } } @@ -3196,31 +2826,32 @@ rplinit(int argc, char *argv[], unsigned if ((*s_etat_processus).var_volatile_alarme != 0) { - pthread_kill((*(*((struct_processus_fils *) + envoi_signal_thread( + (*(*((struct_processus_fils *) (*(*((struct_liste_chainee *) l_element_courant)).donnee).objet)) - .thread).tid, SIGURG); + .thread).tid, rpl_sigurg); } else { if ((*s_etat_processus).arret_depuis_abort == -1) { - pthread_kill( + envoi_signal_thread( (*(*((struct_processus_fils *) (*(*((struct_liste_chainee *) l_element_courant)).donnee) .objet)).thread).tid, - SIGFABORT); + rpl_sigabort); } else { - pthread_kill( + envoi_signal_thread( (*(*((struct_processus_fils *) (*(*((struct_liste_chainee *) l_element_courant)).donnee) .objet)).thread).tid, - SIGFSTOP); + rpl_sigstop); } } } @@ -3319,6 +2950,7 @@ rplinit(int argc, char *argv[], unsigned } nanosleep(&attente, NULL); + scrutation_interruptions(s_etat_processus); pthread_mutex_lock(&((*s_etat_processus).mutex)); } @@ -3844,37 +3476,23 @@ rplinit(int argc, char *argv[], unsigned pthread_mutex_destroy(&((*s_etat_processus).mutex)); pthread_mutex_destroy(&((*s_etat_processus).mutex_allocation)); -# ifndef SEMAPHORES_NOMMES - sem_post(&((*s_etat_processus).semaphore_fork)); - sem_destroy(&((*s_etat_processus).semaphore_fork)); -# else - sem_post((*s_etat_processus).semaphore_fork); - sem_destroy2((*s_etat_processus).semaphore_fork, sem_fork); -# endif + pthread_mutex_unlock(&((*s_etat_processus).mutex_fork)); + pthread_mutex_destroy(&((*s_etat_processus).mutex_fork)); free((*s_etat_processus).localisation); -# ifndef SEMAPHORES_NOMMES - sem_destroy(&semaphore_liste_threads); -# else - sem_destroy2(semaphore_liste_threads, sem_liste_threads); -# endif + pthread_mutex_destroy(&mutex_liste_threads); + pthread_mutex_destroy(&mutex_gestionnaires_signaux_atomique); + # ifndef SEMAPHORES_NOMMES sem_post(&semaphore_gestionnaires_signaux); sem_destroy(&semaphore_gestionnaires_signaux); - sem_destroy(&semaphore_gestionnaires_signaux_atomique); # else sem_post(semaphore_gestionnaires_signaux); sem_destroy2(semaphore_gestionnaires_signaux, sem_gestionnaires_signaux); - sem_destroy2(semaphore_gestionnaires_signaux_atomique, - sem_gestionnaires_signaux_atomique); -# endif - -# ifdef _BROKEN_SIGINFO - destruction_fifos_signaux(s_etat_processus); -# undef return # endif + destruction_queue_signaux(s_etat_processus); liberation_contexte_cas(s_etat_processus); free((*s_etat_processus).chemin_fichiers_temporaires);