Diff for /rpl/src/interruptions.c between versions 1.27 and 1.34

version 1.27, 2010/08/06 15:26:50 version 1.34, 2010/08/23 08:04:40
Line 1724  deverrouillage_gestionnaire_signaux() Line 1724  deverrouillage_gestionnaire_signaux()
     return;      return;
 }  }
   
   #ifdef _BROKEN_SIGINFO
   
   #define longueur_queue  256
   #define nombre_queues   13
   
   static int              *fifos;
   static int              segment;
   static sem_t            *semaphores[nombre_queues];
   static sem_t            *semaphore_global;
   
   #ifdef IPCS_SYSV
   static unsigned char    *chemin = NULL;
   #endif
   
   unsigned char *
   nom_segment(unsigned char *chemin, pid_t pid)
   {
       unsigned char               *fichier;
   
   #   ifdef IPCS_SYSV
       if ((fichier = malloc((strlen(chemin) + 1 + 256 + 1) *
               sizeof(unsigned char))) == NULL)
       {
           return(NULL);
       }
   
       sprintf(fichier, "%s/RPL-SIGQUEUES-%d", chemin, (int) pid);
   #   else
       if ((fichier = malloc((1 + 256 + 1) *
               sizeof(unsigned char))) == NULL)
       {
           return(NULL);
       }
   
       sprintf(fichier, "/RPL-SIGQUEUES-%d", (int) pid);
   #   endif
   
       return(fichier);
   }
   
   unsigned char *
   nom_semaphore(pid_t pid, int queue)
   {
       unsigned char               *fichier;
   
       if ((fichier = malloc((256 + 1) * sizeof(unsigned char))) == NULL)
       {
           return(NULL);
       }
   
       sprintf(fichier, "/RPL-SIGESMAPHORES-%d-%d", (int) pid, queue);
   
       return(fichier);
   }
   
   inline int
   queue_de_signal(int signal)
   {
       switch(signal)
       {
           case SIGINT:
               return(0);
           case SIGTSTP:
               return(1);
           case SIGCONT:
               return(2);
           case SIGURG:
               return(3);
           case SIGPIPE:
               return(4);
           case SIGALRM:
               return(5);
           case SIGFSTOP:
               return(6);
           case SIGSTART:
               return(7);
           case SIGINJECT:
               return(8);
           case SIGABORT:
               return(9);
           case SIGFABORT:
               return(10);
           case SIGSEGV:
               return(11);
           case SIGBUS:
               return(12);
       }
   
       return(-1);
   }
   
   void
   creation_fifos_signaux(struct_processus *s_etat_processus)
   {
       /*
        * Signaux utilisés
        * SIGINT, SIGTSTP, SIGCONT, SIGURG, SIGPIPE, SIGALRM, SIGFSTOP,
        * SIGSTART, SIGINJECT, SIGABORT, SIGFABORT
        */
   
   #   ifndef IPCS_SYSV // POSIX
   #   else // SystemV
   
       file                            *desc;
   
       int                             i;
   
       key_t                           clef;
   
       unsigned char                   *nom;
   
       // Création d'un segment de données associé au PID du processus courant
   
       chemin = (*s_etat_processus).chemin_fichiers_temporaires;
   
       if ((nom = nom_segment((*s_etat_processus).chemin_fichiers_temporaires,
               getpid())) == NULL)
       {
           (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
           return;
       }
   
       if ((desc = fopen(nom, "w")) == NULL)
       {
           (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
           return;
       }
   
       fclose(desc);
   
       if ((clef = ftok(nom, 1)) == -1)
       {
           (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
           return;
       }
   
       free(nom);
   
       if ((segment = shmget(clef,
               nombre_queues * (longueur_queue + 4) * sizeof(int),
               IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR)) == -1)
       {
           (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
           return;
       }
   
       fifos = shmat(segment, NULL, 0);
   
       if (((void *) fifos) == ((void *) -1))
       {
           if (shmctl(segment, IPC_RMID, 0) == -1)
           {
               (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
               return;
           }
   
           (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
           return;
       }
   
   #   endif
   
       /*
        * Structure d'une queue
        * 0 : pointeur en lecture sur le premier emplacement libre (int)
        * 1 : pointeur en écriture sur le premier emplacement à lire (int)
        * 2 : longueur de la queue (int)
        * 3 : éléments restants (int)
        * 4 à 4 + (2) : queue (int)
        */
   
       for(i = 0; i < nombre_queues; i++)
       {
           fifos[(i * (longueur_queue + 4))] = 0;
           fifos[(i * (longueur_queue + 4)) + 1] = 0;
           fifos[(i * (longueur_queue + 4)) + 2] = longueur_queue;
           fifos[(i * (longueur_queue + 4)) + 3] = longueur_queue;
       }
   
       // Création des sémaphores : un sémaphore par signal et par queue
       // plus un sémaphore global pour tous les threads.
   
       for(i = 0; i < nombre_queues; i++)
       {
           if ((nom = nom_semaphore(getpid(), i)) == NULL)
           {
               (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
               return;
           }
   
           // Le sémaphore est créé en écrasant si nécessaire un sémaphore
           // préexistant. Comme le nom du sémaphore contient l'identifiant du
           // processus, il est anormal d'avoir un sémaphore de même nom
           // préexistant.
   
           if ((semaphores[i] = sem_open(nom, O_CREAT, S_IRUSR | S_IWUSR,
                   1)) == SEM_FAILED)
           {
               (*s_etat_processus).erreur_systeme = d_es_semaphore;
               return;
           }
   
           free(nom);
       }
   
   
       if ((nom = nom_semaphore(getpid(), nombre_queues)) == NULL)
       {
           (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
           return;
       }
   
       if ((semaphore_global = sem_open(nom, O_CREAT, S_IRUSR | S_IWUSR,
               1)) == SEM_FAILED)
       {
           (*s_etat_processus).erreur_systeme = d_es_semaphore;
           return;
       }
   
       free(nom);
   
       return;
   }
   
   void
   liberation_fifos_signaux(struct_processus *s_etat_processus)
   {
       int                 i;
   
       if (shmdt(fifos) == -1)
       {
           (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
           return;
       }
   
       for(i = 0; i < nombre_queues; i++)
       {
           if (sem_close(semaphores[i]) != 0)
           {
               (*s_etat_processus).erreur_systeme = d_es_semaphore;
               return;
           }
       }
   
       if (sem_close(semaphore_global) != 0)
       {
           (*s_etat_processus).erreur_systeme = d_es_semaphore;
           return;
       }
   
       return;
   }
   
 void  void
 interruption1(int signal, siginfo_t *siginfo, void *context)  destruction_fifos_signaux(struct_processus *s_etat_processus)
   {
       int                 i;
   
       unsigned char       *nom;
   
       if (shmdt(fifos) == -1)
       {
           (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
           return;
       }
   
       if (shmctl(segment, IPC_RMID, 0) == -1)
       {
           (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
           return;
       }
   
       if ((nom = nom_segment((*s_etat_processus).chemin_fichiers_temporaires,
               getpid())) == NULL)
       {
           (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
           return;
       }
   
       unlink(nom);
       free(nom);
   
       for(i = 0; i < nombre_queues; i++)
       {
           if ((nom = nom_semaphore(getpid(), i)) == NULL)
           {
               (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
               return;
           }
   
           if (sem_unlink(nom) != 0)
           {
               (*s_etat_processus).erreur_systeme = d_es_semaphore;
               return;
           }
   
           free(nom);
       }
   
       if ((nom = nom_semaphore(getpid(), nombre_queues)) == NULL)
       {
           (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
           return;
       }
   
       if (sem_unlink(nom) != 0)
       {
           (*s_etat_processus).erreur_systeme = d_es_semaphore;
           return;
       }
   
       free(nom);
   
       return;
   }
   
   int
   queue_in(pid_t pid, int signal)
 {  {
   #undef printf
   // Transformer ce truc en POSIX ! On ne fait du SysV que si on n'a pas le choix
   
   #   ifndef IPCS_SYSV
   #   else // Traitement à l'aide d'IPCS SystemV
   
       int             *base;
       int             *buffer;
       int             *projection_fifos;
       int             queue;
       int             identifiant;
   
       key_t           clef;
   
       sem_t           *semaphore;
   
       struct stat     s_stat;
   
       unsigned char   *nom;
   
       queue = queue_de_signal(signal);
   
       // Ouverture des projections
   
       if ((nom = nom_segment(chemin, pid)) == NULL)
       {
           return(-1);
       }
   
       // Dans le cas de SIGSTART, premier signal envoyé à un processus fils,
       // il convient d'attendre que le fichier support soit effectivement
       // accessible. Dans tous les autres cas, ce fichier doit exister. S'il
       // n'existe plus, le processus associé n'existe plus.
   
       if (signal == SIGSTART)
       {
           // On attend que le fichier sois présent
   
           while(stat(nom, &s_stat) != 0);
       }
   
       if ((clef = ftok(nom, 1)) == -1)
       {
           return(-1);
       }
   
       free(nom);
   
       if (signal == SIGSTART)
       {
           while((identifiant = shmget(clef,
                   nombre_queues * (longueur_queue + 4) * sizeof(int),
                   S_IRUSR | S_IWUSR)) == -1);
       }
       else
       {
           if ((identifiant = shmget(clef,
                   nombre_queues * (longueur_queue + 4) * sizeof(int),
                   S_IRUSR | S_IWUSR)) == -1)
           {
               return(-1);
           }
       }
   
       projection_fifos = shmat(identifiant, NULL, 0);
   
       if (((void *) projection_fifos) == ((void *) -1))
       {
           return(-1);
       }
   
       if ((nom = nom_semaphore(pid, queue)) == NULL)
       {
           shmdt(projection_fifos);
           return(-1);
       }
   
       while((semaphore = sem_open(nom, 0)) == SEM_FAILED);
   
       if (sem_wait(semaphore) != 0)
       {
           shmdt(projection_fifos);
           return(-1);
       }
   
       // Il ne faut pas empiler plusieurs SIGSTART car SIGSTART peut provenir
       // de l'instruction SWI. Plusieurs threads peuvent interrompre de façon
       // asynchrone le processus père durant une phase de signaux masqués.
   
       base = &(projection_fifos[(longueur_queue + 4) * queue]);
       buffer = &(base[4]);
   
       // base[3] contient le nombre d'éléments restants
   
       if (base[3] <= 0)
       {
           sem_post(semaphore);
           sem_close(semaphore);
           shmdt(projection_fifos);
           return(-1);
       }
   
       base[3]--;
   
       // base[1] contient le prochain élément à écrire
       buffer[base[1]++] = (int) pid;
       base[1] %= base[2];
   
       if (sem_post(semaphore) != 0)
       {
           shmdt(projection_fifos);
           sem_close(semaphore);
           return(-1);
       }
   
       sem_close(semaphore);
   
       // Fermeture des projections
       shmdt(projection_fifos);
   
   #   endif
   
       return(0);
   }
   
   pid_t
   origine_signal(int signal)
   {
       int             *base;
       int             *buffer;
       int             pid;
       int             queue;
   
       queue = queue_de_signal(signal);
   
       BUG(queue == -1, uprintf("[%d] Unknown signal %d in this context\n",
               (int) getpid(), signal));
   
       if (sem_wait(semaphores[queue]) != 0)
       {
           return(-1);
       }
   
       // Le signal SIGCONT peut être envoyé de façon totalement asynchrone.
       // Il peut y avoir plus de signaux envoyés que d'interruptions traitées.
       // Il convient donc de rectifier la queue lors du traitement de
       // l'interruption correspondante. Le gestionnaire étant installé sans
       // l'option NODEFER, la queue reste cohérente.
   
       if (signal == SIGCONT)
       {
           base = &(fifos[(longueur_queue + 4) * queue]);
           buffer = &(base[4]);
           base[0] = (base[1] - 1) % base[2];
           pid = buffer[base[0]++];
           base[3] = base[2];
       }
       else
       {
           base = &(fifos[(longueur_queue + 4) * queue]);
           buffer = &(base[4]);
           pid = buffer[base[0]++];
           base[0] %= base[2];
           base[3]++;
       }
   
       if (base[3] > base[2])
       {
           sem_post(semaphores[queue]);
           return(-1);
       }
   
       if (sem_post(semaphores[queue]) != 0)
       {
           return(-1);
       }
   
       return((pid_t) pid);
   }
   
   #endif
   
   void
   interruption1(SIGHANDLER_ARGS)
   {
       pid_t                   pid;
   
     pthread_t               thread;      pthread_t               thread;
   
     struct_processus        *s_etat_processus;      struct_processus        *s_etat_processus;
Line 1735  interruption1(int signal, siginfo_t *sig Line 2238  interruption1(int signal, siginfo_t *sig
   
     verrouillage_gestionnaire_signaux();      verrouillage_gestionnaire_signaux();
   
   #   ifdef _BROKEN_SIGINFO
       if (signal == SIGINT)
       {
           // Si l'interruption provient du clavier, il n'y a pas eu d'appel
           // à queue_in().
   
           pid = getpid();
       }
       else
       {
           pid = origine_signal(signal);
       }
   #   else
       pid = (*siginfo).si_pid;
   #   endif
   
     switch(signal)      switch(signal)
     {      {
         case SIGALRM :          case SIGALRM :
         {          {
             if ((*siginfo).si_pid == getpid())              if (pid == getpid())
             {              {
                 if ((s_etat_processus = recherche_thread(getpid(),                  if ((s_etat_processus = recherche_thread(getpid(),
                         pthread_self())) == NULL)                          pthread_self())) == NULL)
                 {                  {
                     deverrouillage_gestionnaire_signaux();                      deverrouillage_gestionnaire_signaux();
                     return;                       return;
                 }                  }
   
                 if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)                  if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
Line 1784  interruption1(int signal, siginfo_t *sig Line 2303  interruption1(int signal, siginfo_t *sig
              * Solaris suit en particulier cette spécification.               * Solaris suit en particulier cette spécification.
              */               */
   
   #           ifndef _BROKEN_SIGINFO
             if (siginfo == NULL)              if (siginfo == NULL)
             {              {
                 kill(getpid(), signal);                  kill(getpid(), signal);
             }              }
             else if ((*siginfo).si_pid == getpid())              else
   #           endif
               if (pid == getpid())
             {              {
                 if ((s_etat_processus = recherche_thread(getpid(),                  if ((s_etat_processus = recherche_thread(getpid(),
                         pthread_self())) == NULL)                          pthread_self())) == NULL)
Line 1863  interruption1(int signal, siginfo_t *sig Line 2385  interruption1(int signal, siginfo_t *sig
 }  }
   
 void  void
 interruption2(int signal, siginfo_t *siginfo, void *context)  interruption2(SIGHANDLER_ARGS)
 {  {
       pid_t                   pid;
   
     pthread_t               thread;      pthread_t               thread;
   
     struct_processus        *s_etat_processus;      struct_processus        *s_etat_processus;
   
     verrouillage_gestionnaire_signaux();      verrouillage_gestionnaire_signaux();
   
   #   ifdef _BROKEN_SIGINFO
       pid = origine_signal(signal);
   #   else
       pid = (*siginfo).si_pid;
   #   endif
   
   #   ifndef _BROKEN_SIGINFO
     if (siginfo == NULL)      if (siginfo == NULL)
     {      {
         /*          /*
Line 1887  interruption2(int signal, siginfo_t *sig Line 2419  interruption2(int signal, siginfo_t *sig
             return;              return;
         }          }
     }      }
     else if ((*siginfo).si_pid == getpid())      else
   #   endif
       if (pid == getpid())
     {      {
         if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))          if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))
                 == NULL)                  == NULL)
Line 1935  interruption2(int signal, siginfo_t *sig Line 2469  interruption2(int signal, siginfo_t *sig
 }  }
   
 void  void
 interruption3(int signal, siginfo_t *siginfo, void *context)  interruption3(SIGHANDLER_ARGS)
 {  {
       pid_t                   pid;
   
     struct_processus        *s_etat_processus;      struct_processus        *s_etat_processus;
   
     static int              compteur = 0;      static int              compteur = 0;
   
     verrouillage_gestionnaire_signaux();      verrouillage_gestionnaire_signaux();
   
   #   ifdef _BROKEN_SIGINFO
       pid = origine_signal(signal);
   #   else
       pid = (*siginfo).si_pid;
   #   endif
   
     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)      if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
     {      {
         deverrouillage_gestionnaire_signaux();          deverrouillage_gestionnaire_signaux();
Line 1995  interruption3(int signal, siginfo_t *sig Line 2537  interruption3(int signal, siginfo_t *sig
 }  }
   
 void  void
 interruption4(int signal, siginfo_t *siginfo, void *context)  interruption4(SIGHANDLER_ARGS)
 {  {
       pid_t                   pid;
   
     struct_processus        *s_etat_processus;      struct_processus        *s_etat_processus;
   
     verrouillage_gestionnaire_signaux();      verrouillage_gestionnaire_signaux();
   
   #   ifdef _BROKEN_SIGINFO
       pid = origine_signal(signal);
   #   else
       pid = (*siginfo).si_pid;
   #   endif
   
     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)      if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
     {      {
         deverrouillage_gestionnaire_signaux();          deverrouillage_gestionnaire_signaux();
Line 2023  interruption4(int signal, siginfo_t *sig Line 2573  interruption4(int signal, siginfo_t *sig
 }  }
   
 void  void
 interruption5(int signal, siginfo_t *siginfo, void *context)  interruption5(SIGHANDLER_ARGS)
 {  {
       pid_t                   pid;
   
     pthread_t               thread;      pthread_t               thread;
   
     struct_processus        *s_etat_processus;      struct_processus        *s_etat_processus;
   
     verrouillage_gestionnaire_signaux();      verrouillage_gestionnaire_signaux();
   
     if ((*siginfo).si_pid == getpid())  #   ifdef _BROKEN_SIGINFO
       pid = origine_signal(signal);
   #   else
       pid = (*siginfo).si_pid;
   #   endif
   
       if (pid == getpid())
     {      {
         if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))          if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))
                 == NULL)                  == NULL)
Line 2086  interruption5(int signal, siginfo_t *sig Line 2645  interruption5(int signal, siginfo_t *sig
 }  }
   
 void  void
 interruption6(int signal, siginfo_t *siginfo, void *context)  interruption6(SIGHANDLER_ARGS)
 {  {
       pid_t                   pid;
   
     struct_processus        *s_etat_processus;      struct_processus        *s_etat_processus;
   
     verrouillage_gestionnaire_signaux();      verrouillage_gestionnaire_signaux();
   
   #   ifdef _BROKEN_SIGINFO
       pid = origine_signal(signal);
   #   else
       pid = (*siginfo).si_pid;
   #   endif
   
     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)      if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
     {      {
         deverrouillage_gestionnaire_signaux();          deverrouillage_gestionnaire_signaux();
Line 2110  interruption6(int signal, siginfo_t *sig Line 2677  interruption6(int signal, siginfo_t *sig
 }  }
   
 void  void
 interruption7(int signal, siginfo_t *siginfo, void *context)  interruption7(SIGHANDLER_ARGS)
 {  {
       pid_t                   pid;
   
     struct_processus        *s_etat_processus;      struct_processus        *s_etat_processus;
   
     verrouillage_gestionnaire_signaux();      verrouillage_gestionnaire_signaux();
   
   #   ifdef _BROKEN_SIGINFO
       pid = origine_signal(signal);
   #   else
       pid = (*siginfo).si_pid;
   #   endif
   
     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)      if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
     {      {
         deverrouillage_gestionnaire_signaux();          deverrouillage_gestionnaire_signaux();
Line 2137  interruption7(int signal, siginfo_t *sig Line 2712  interruption7(int signal, siginfo_t *sig
 }  }
   
 void  void
 interruption8(int signal, siginfo_t *siginfo, void *context)  interruption8(SIGHANDLER_ARGS)
 {  {
       pid_t                   pid;
   
     pthread_t               thread;      pthread_t               thread;
   
     struct_processus        *s_etat_processus;      struct_processus        *s_etat_processus;
   
     verrouillage_gestionnaire_signaux();      verrouillage_gestionnaire_signaux();
   
     if ((*siginfo).si_pid == getpid())  #   ifdef _BROKEN_SIGINFO
       pid = origine_signal(signal);
   #   else
       pid = (*siginfo).si_pid;
   #   endif
   
       if (pid == getpid())
     {      {
         if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))          if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))
                 == NULL)                  == NULL)
Line 2180  interruption8(int signal, siginfo_t *sig Line 2764  interruption8(int signal, siginfo_t *sig
 }  }
   
 void  void
 interruption9(int signal, siginfo_t *siginfo, void *context)  interruption9(SIGHANDLER_ARGS)
 {  {
       pid_t                   pid;
   
     struct_processus        *s_etat_processus;      struct_processus        *s_etat_processus;
   
     verrouillage_gestionnaire_signaux();      verrouillage_gestionnaire_signaux();
   
   #   ifdef _BROKEN_SIGINFO
       pid = origine_signal(signal);
   #   else
       pid = (*siginfo).si_pid;
   #   endif
   
     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)      if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
     {      {
         deverrouillage_gestionnaire_signaux();          deverrouillage_gestionnaire_signaux();
Line 2199  interruption9(int signal, siginfo_t *sig Line 2791  interruption9(int signal, siginfo_t *sig
         fflush(stdout);          fflush(stdout);
     }      }
   
   #   ifdef _BROKEN_SIGINFO
       if (queue_in(getpid(), signal) != 0)
       {
           return;
       }
   
       deverrouillage_gestionnaire_signaux();
       interruption11(signal);
   #   else
     deverrouillage_gestionnaire_signaux();      deverrouillage_gestionnaire_signaux();
     interruption11(signal, siginfo, context);      interruption11(signal, siginfo, context);
   #   endif
     return;      return;
 }  }
   
 void  void
 interruption10(int signal, siginfo_t *siginfo, void *context)  interruption10(SIGHANDLER_ARGS)
 {  {
     file                    *fichier;      file                    *fichier;
   
       pid_t                   pid;
   
     struct_processus        *s_etat_processus;      struct_processus        *s_etat_processus;
   
     unsigned char           nom[8 + 64 + 1];      unsigned char           nom[8 + 64 + 1];
   
     verrouillage_gestionnaire_signaux();      verrouillage_gestionnaire_signaux();
   
   #   ifdef _BROKEN_SIGINFO
       pid = origine_signal(signal);
   #   else
       pid = (*siginfo).si_pid;
   #   endif
   
     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)      if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
     {      {
         deverrouillage_gestionnaire_signaux();          deverrouillage_gestionnaire_signaux();
Line 2246  interruption10(int signal, siginfo_t *si Line 2856  interruption10(int signal, siginfo_t *si
 }  }
   
 void  void
 interruption11(int signal, siginfo_t *siginfo, void *context)  interruption11(SIGHANDLER_ARGS)
 {  {
       pid_t                   pid;
   
     pthread_t               thread;      pthread_t               thread;
   
     struct_processus        *s_etat_processus;      struct_processus        *s_etat_processus;
   
     verrouillage_gestionnaire_signaux();      verrouillage_gestionnaire_signaux();
   
     if ((*siginfo).si_pid == getpid())  #   ifdef _BROKEN_SIGINFO
       pid = origine_signal(signal);
   #   else
       pid = (*siginfo).si_pid;
   #   endif
   
       if (pid == getpid())
     {      {
         if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))          if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))
                 == NULL)                  == NULL)
Line 2331  traitement_exceptions_gsl(const char *re Line 2950  traitement_exceptions_gsl(const char *re
     return;      return;
 }  }
   
   #ifdef _BROKEN_SIGINFO
   
   #undef kill
   #undef pthread_kill
   
   int
   kill_broken_siginfo(pid_t pid, int signal)
   {
       int                 ios;
   
       sem_t               *semaphore;
   
       unsigned char       *nom;
   
       /*
        * Lorsqu'on veut interrompre le processus pid, on ouvre le segment
        * correspondant au processus en question et ou ajoute le pid dans la
        * queue.
        *
        * Le sémaphore global à tous les threads d'un même processus sert
        * à garantir que les signaux seront traités dans l'ordre de ce qui est
        * effectivement mis dans la queue.
        */
   
       // Sémaphore acquis
   
       if ((nom = nom_semaphore(getpid(), nombre_queues)) == NULL)
       {
           return(-1);
       }
   
       if ((semaphore = sem_open(nom, 0)) == SEM_FAILED)
       {
           free(nom);
           return(-1);
       }
   
       free(nom);
   
       if (sem_wait(semaphore) == -1)
       {
           return(-1);
       }
   
       if ((signal != 0) && (signal != SIGINT))
       {
           if (queue_in(pid, signal) != 0)
           {
               sem_post(semaphore);
               sem_close(semaphore);
               return(-1);
           }
       }
   
       ios = kill(pid, signal);
   
       // Sémaphore relâché
   
       sem_post(semaphore);
       sem_close(semaphore);
   
       return(ios);
   }
   
   int
   pthread_kill_broken_siginfo(pthread_t tid, int signal)
   {
       int                 ios;
   
       sem_t               *semaphore;
   
       unsigned char       *nom;
   
       if ((nom = nom_semaphore(getpid(), nombre_queues)) == NULL)
       {
           return(-1);
       }
   
       if ((semaphore = sem_open(nom, 0)) == SEM_FAILED)
       {
           free(nom);
           return(-1);
       }
   
       free(nom);
   
       if (sem_wait(semaphore) == -1)
       {
           return(-1);
       }
   
       if ((signal != 0) && (signal != SIGINT))
       {
           if (queue_in(getpid(), signal) != 0)
           {
               sem_post(semaphore);
               sem_close(semaphore);
               return(-1);
           }
       }
   
       ios = pthread_kill(tid, signal);
   
       sem_post(semaphore);
       sem_close(semaphore);
   
       return(ios);
   }
   
   #endif
   
 // vim: ts=4  // vim: ts=4

Removed from v.1.27  
changed lines
  Added in v.1.34


CVSweb interface <joel.bertrand@systella.fr>