version 1.35, 2010/08/25 09:06:49
|
version 1.63, 2011/09/03 10:31:50
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.0.18 |
RPL/2 (R) version 4.1.3 |
Copyright (C) 1989-2010 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 183 insertion_thread_surveillance(struct_pro
|
Line 183 insertion_thread_surveillance(struct_pro
|
} |
} |
} |
} |
|
|
pthread_mutex_lock(&((*s_argument_thread).mutex)); |
pthread_mutex_lock(&((*s_argument_thread).mutex_nombre_references)); |
(*s_argument_thread).nombre_references++; |
(*s_argument_thread).nombre_references++; |
pthread_mutex_unlock(&((*s_argument_thread).mutex)); |
pthread_mutex_unlock(&((*s_argument_thread).mutex_nombre_references)); |
|
|
(*l_nouvel_objet).suivant = liste_threads_surveillance; |
(*l_nouvel_objet).suivant = liste_threads_surveillance; |
(*l_nouvel_objet).donnee = (void *) s_argument_thread; |
(*l_nouvel_objet).donnee = (void *) s_argument_thread; |
Line 378 retrait_thread_surveillance(struct_proce
|
Line 378 retrait_thread_surveillance(struct_proce
|
(*l_element_precedent).suivant = (*l_element_courant).suivant; |
(*l_element_precedent).suivant = (*l_element_courant).suivant; |
} |
} |
|
|
if (pthread_mutex_lock(&((*s_argument_thread).mutex)) != 0) |
if (pthread_mutex_lock(&((*s_argument_thread).mutex_nombre_references)) |
|
!= 0) |
{ |
{ |
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
Line 400 retrait_thread_surveillance(struct_proce
|
Line 401 retrait_thread_surveillance(struct_proce
|
|
|
if ((*s_argument_thread).nombre_references == 0) |
if ((*s_argument_thread).nombre_references == 0) |
{ |
{ |
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) |
if (pthread_mutex_unlock(&((*s_argument_thread) |
|
.mutex_nombre_references)) != 0) |
{ |
{ |
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
Line 415 retrait_thread_surveillance(struct_proce
|
Line 417 retrait_thread_surveillance(struct_proce
|
} |
} |
|
|
pthread_mutex_destroy(&((*s_argument_thread).mutex)); |
pthread_mutex_destroy(&((*s_argument_thread).mutex)); |
|
pthread_mutex_destroy(&((*s_argument_thread).mutex_nombre_references)); |
free(s_argument_thread); |
free(s_argument_thread); |
} |
} |
else |
else |
{ |
{ |
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) |
if (pthread_mutex_unlock(&((*s_argument_thread) |
|
.mutex_nombre_references)) != 0) |
{ |
{ |
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
Line 676 liberation_threads(struct_processus *s_e
|
Line 680 liberation_threads(struct_processus *s_e
|
s_argument_thread = (struct_descripteur_thread *) |
s_argument_thread = (struct_descripteur_thread *) |
(*((struct_liste_chainee *) element_courant)).donnee; |
(*((struct_liste_chainee *) element_courant)).donnee; |
|
|
if (pthread_mutex_lock(&((*s_argument_thread).mutex)) != 0) |
if (pthread_mutex_lock(&((*s_argument_thread) |
|
.mutex_nombre_references)) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
Line 700 liberation_threads(struct_processus *s_e
|
Line 705 liberation_threads(struct_processus *s_e
|
close((*s_argument_thread) |
close((*s_argument_thread) |
.pipe_nombre_interruptions_attente[0]); |
.pipe_nombre_interruptions_attente[0]); |
|
|
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) |
if (pthread_mutex_unlock(&((*s_argument_thread) |
!= 0) |
.mutex_nombre_references)) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
Line 709 liberation_threads(struct_processus *s_e
|
Line 714 liberation_threads(struct_processus *s_e
|
} |
} |
|
|
pthread_mutex_destroy(&((*s_argument_thread).mutex)); |
pthread_mutex_destroy(&((*s_argument_thread).mutex)); |
|
pthread_mutex_destroy(&((*s_argument_thread) |
|
.mutex_nombre_references)); |
|
|
if ((*s_argument_thread).processus_detache == d_faux) |
if ((*s_argument_thread).processus_detache == d_faux) |
{ |
{ |
Line 723 liberation_threads(struct_processus *s_e
|
Line 730 liberation_threads(struct_processus *s_e
|
} |
} |
else |
else |
{ |
{ |
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) |
if (pthread_mutex_unlock(&((*s_argument_thread) |
!= 0) |
.mutex_nombre_references)) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
Line 796 liberation_threads(struct_processus *s_e
|
Line 803 liberation_threads(struct_processus *s_e
|
} |
} |
} |
} |
|
|
for(i = 0; i < (*s_etat_processus).nombre_variables; i++) |
liberation_arbre_variables(s_etat_processus, |
{ |
(*s_etat_processus).s_arbre_variables, d_faux); |
pthread_mutex_trylock(&((*(*s_etat_processus) |
|
.s_liste_variables[i].objet).mutex)); |
|
pthread_mutex_unlock(&((*(*s_etat_processus) |
|
.s_liste_variables[i].objet).mutex)); |
|
|
|
// Les variables de niveau 0 sont des définitions qui |
|
// ne sont pas copiées entre threads. |
|
if ((*s_etat_processus).s_liste_variables[i].niveau > 0) |
|
{ |
|
liberation(s_etat_processus, |
|
(*s_etat_processus).s_liste_variables[i].objet); |
|
} |
|
|
|
free((*s_etat_processus).s_liste_variables[i].nom); |
|
} |
|
|
|
free((*s_etat_processus).s_liste_variables); |
|
|
|
for(i = 0; i < (*s_etat_processus).nombre_variables_statiques; i++) |
for(i = 0; i < (*s_etat_processus).nombre_variables_statiques; i++) |
{ |
{ |
Line 1328 liberation_threads(struct_processus *s_e
|
Line 1318 liberation_threads(struct_processus *s_e
|
sem_destroy2((*s_etat_processus).semaphore_fork, sem_fork); |
sem_destroy2((*s_etat_processus).semaphore_fork, sem_fork); |
# endif |
# endif |
|
|
|
liberation_contexte_cas(s_etat_processus); |
free(s_etat_processus); |
free(s_etat_processus); |
|
|
s_etat_processus = candidat; |
s_etat_processus = candidat; |
Line 1350 liberation_threads(struct_processus *s_e
|
Line 1341 liberation_threads(struct_processus *s_e
|
s_argument_thread = (struct_descripteur_thread *) |
s_argument_thread = (struct_descripteur_thread *) |
(*l_element_courant).donnee; |
(*l_element_courant).donnee; |
|
|
if (pthread_mutex_lock(&((*s_argument_thread).mutex)) != 0) |
if (pthread_mutex_lock(&((*s_argument_thread).mutex_nombre_references)) |
|
!= 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
Line 1373 liberation_threads(struct_processus *s_e
|
Line 1365 liberation_threads(struct_processus *s_e
|
close((*s_argument_thread).pipe_interruptions[0]); |
close((*s_argument_thread).pipe_interruptions[0]); |
close((*s_argument_thread).pipe_nombre_interruptions_attente[0]); |
close((*s_argument_thread).pipe_nombre_interruptions_attente[0]); |
|
|
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) |
if (pthread_mutex_unlock(&((*s_argument_thread) |
|
.mutex_nombre_references)) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
Line 1381 liberation_threads(struct_processus *s_e
|
Line 1374 liberation_threads(struct_processus *s_e
|
} |
} |
|
|
pthread_mutex_destroy(&((*s_argument_thread).mutex)); |
pthread_mutex_destroy(&((*s_argument_thread).mutex)); |
|
pthread_mutex_destroy(&((*s_argument_thread) |
|
.mutex_nombre_references)); |
|
|
if ((*s_argument_thread).processus_detache == d_faux) |
if ((*s_argument_thread).processus_detache == d_faux) |
{ |
{ |
Line 1394 liberation_threads(struct_processus *s_e
|
Line 1389 liberation_threads(struct_processus *s_e
|
} |
} |
else |
else |
{ |
{ |
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) |
if (pthread_mutex_unlock(&((*s_argument_thread) |
|
.mutex_nombre_references)) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
Line 1592 verrouillage_gestionnaire_signaux()
|
Line 1588 verrouillage_gestionnaire_signaux()
|
// ce que ce soit possible. |
// ce que ce soit possible. |
|
|
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
while(sem_trywait(&semaphore_liste_threads) == -1) |
while(sem_wait(&semaphore_liste_threads) == -1) |
# else |
# else |
while(sem_trywait(semaphore_liste_threads) == -1) |
while(sem_wait(semaphore_liste_threads) == -1) |
# endif |
# endif |
{ |
{ |
if ((errno != EINTR) && (errno != EAGAIN)) |
if (errno != EINTR) |
{ |
{ |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
|
|
Line 1613 verrouillage_gestionnaire_signaux()
|
Line 1609 verrouillage_gestionnaire_signaux()
|
BUG(1, uprintf("Lock error !\n")); |
BUG(1, uprintf("Lock error !\n")); |
return; |
return; |
} |
} |
|
|
sched_yield(); |
|
} |
} |
} |
} |
|
|
Line 1724 deverrouillage_gestionnaire_signaux()
|
Line 1718 deverrouillage_gestionnaire_signaux()
|
return; |
return; |
} |
} |
|
|
#ifdef _BROKEN_SIGINFO |
|
|
|
#define longueur_queue 256 |
|
#define nombre_queues 13 |
|
|
|
static int *fifos; |
|
static int markov; |
|
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 |
|
*/ |
|
|
|
int i; |
|
|
|
unsigned char *nom; |
|
|
|
# ifndef IPCS_SYSV // POSIX |
|
|
|
if ((nom = nom_segment((*s_etat_processus).chemin_fichiers_temporaires, |
|
getpid())) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if ((segment = shm_open(nom, O_RDWR | O_CREAT | O_EXCL, |
|
S_IRUSR | S_IWUSR)) == -1) |
|
{ |
|
free(nom); |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (ftruncate(segment, nombre_queues * ((2 * longueur_queue) + 4) * |
|
sizeof(int)) == -1) |
|
{ |
|
free(nom); |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
fifos = mmap(NULL, nombre_queues * ((2 * longueur_queue) + 4) * sizeof(int), |
|
PROT_READ | PROT_WRITE, MAP_SHARED, segment, 0); |
|
close(segment); |
|
|
|
if (((void *) fifos) == ((void *) -1)) |
|
{ |
|
if (shm_unlink(nom) == -1) |
|
{ |
|
free(nom); |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
free(nom); |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
free(nom); |
|
|
|
# else // SystemV |
|
|
|
file *desc; |
|
|
|
key_t clef; |
|
|
|
// 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 * ((2 * 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) |
|
* 4 + (2) + 1 ) 4 + 2 * (2) : horodatage en centième de secondes. |
|
*/ |
|
|
|
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); |
|
|
|
markov = 0; |
|
|
|
return; |
|
} |
|
|
|
void |
|
liberation_fifos_signaux(struct_processus *s_etat_processus) |
|
{ |
|
int i; |
|
|
|
# ifdef IPCS_SYSV // SystemV |
|
|
|
if (shmdt(fifos) == -1) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
# else // POSIX |
|
|
|
if (munmap(fifos, nombre_queues * ((2 * longueur_queue) + 4) * sizeof(int)) |
|
!= 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
# endif |
|
|
|
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 |
|
destruction_fifos_signaux(struct_processus *s_etat_processus) |
|
{ |
|
int i; |
|
|
|
unsigned char *nom; |
|
|
|
# ifdef IPCS_SYSV // SystemV |
|
|
|
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); |
|
|
|
# else // POSIX |
|
|
|
if (munmap(fifos, nombre_queues * ((2 * longueur_queue) + 4) * sizeof(int)) |
|
!= 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if ((nom = nom_segment(NULL, getpid())) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (shm_unlink(nom) != 0) |
|
{ |
|
free(nom); |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
free(nom); |
|
|
|
# endif |
|
|
|
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; |
|
} |
|
|
|
inline int |
|
horodatage() |
|
{ |
|
int ts; |
|
|
|
struct timeval tv; |
|
|
|
gettimeofday(&tv, NULL); |
|
ts = (int) ((tv.tv_sec * 100) + (tv.tv_usec / 10000)); |
|
|
|
return(ts); |
|
} |
|
|
|
int |
|
queue_in(pid_t pid, int signal) |
|
{ |
|
int queue; |
|
int *base; |
|
int *buffer; |
|
int horodatage_initial; |
|
int identifiant; |
|
int *projection_fifos; |
|
|
|
sem_t *semaphore; |
|
|
|
queue = queue_de_signal(signal); |
|
|
|
unsigned char *nom; |
|
|
|
# ifndef IPCS_SYSV |
|
|
|
// Ouverture des projections |
|
|
|
if ((nom = nom_segment(NULL, 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) |
|
{ |
|
horodatage_initial = horodatage(); |
|
|
|
while((identifiant = shm_open(nom, O_RDWR, S_IRUSR | S_IWUSR)) == -1) |
|
{ |
|
if (abs(horodatage_initial - horodatage()) > 500) |
|
{ |
|
return(-1); |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
if ((identifiant = shm_open(nom, O_RDWR, S_IRUSR | S_IWUSR)) == -1) |
|
{ |
|
return(-1); |
|
} |
|
} |
|
|
|
projection_fifos = mmap(NULL, nombre_queues * ((2 * longueur_queue) + 4) |
|
* sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, identifiant, 0); |
|
close(identifiant); |
|
|
|
if (((void *) projection_fifos) == ((void *) -1)) |
|
{ |
|
return(-1); |
|
} |
|
|
|
# else // Traitement à l'aide d'IPCS SystemV |
|
|
|
key_t clef; |
|
|
|
struct stat s_stat; |
|
|
|
// 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 |
|
|
|
horodatage_initial = horodatage(); |
|
|
|
while(stat(nom, &s_stat) != 0) |
|
{ |
|
if (abs(horodatage_initial - horodatage()) > 500) |
|
{ |
|
return(-1); |
|
} |
|
} |
|
} |
|
|
|
if ((clef = ftok(nom, 1)) == -1) |
|
{ |
|
return(-1); |
|
} |
|
|
|
free(nom); |
|
|
|
if (signal == SIGSTART) |
|
{ |
|
while((identifiant = shmget(clef, |
|
nombre_queues * ((2 * longueur_queue) + 4) * sizeof(int), |
|
S_IRUSR | S_IWUSR)) == -1); |
|
} |
|
else |
|
{ |
|
if ((identifiant = shmget(clef, |
|
nombre_queues * ((2 * 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); |
|
} |
|
|
|
# endif |
|
|
|
if ((nom = nom_semaphore(pid, queue)) == NULL) |
|
{ |
|
# ifdef IPCS_SYSV |
|
shmdt(projection_fifos); |
|
# else |
|
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
|
* sizeof(int)); |
|
# endif |
|
return(-1); |
|
} |
|
|
|
while((semaphore = sem_open(nom, 0)) == SEM_FAILED); |
|
free(nom); |
|
|
|
while(sem_wait(semaphore) != 0) |
|
{ |
|
if (errno != EINTR) |
|
{ |
|
# ifdef IPCS_SYSV |
|
shmdt(projection_fifos); |
|
# else |
|
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
|
* sizeof(int)); |
|
# endif |
|
return(-1); |
|
} |
|
} |
|
|
|
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); |
|
# ifdef IPCS_SYSV |
|
shmdt(projection_fifos); |
|
# else |
|
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
|
* sizeof(int)); |
|
# endif |
|
return(-1); |
|
} |
|
|
|
base[3]--; |
|
|
|
// base[1] contient le prochain élément à écrire |
|
|
|
buffer[base[1] + (nombre_queues * base[2])] = horodatage(); |
|
buffer[base[1]++] = (int) pid; |
|
base[1] %= base[2]; |
|
|
|
if (sem_post(semaphore) != 0) |
|
{ |
|
# ifdef IPCS_SYSV |
|
shmdt(projection_fifos); |
|
# else |
|
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
|
* sizeof(int)); |
|
# endif |
|
sem_close(semaphore); |
|
return(-1); |
|
} |
|
|
|
sem_close(semaphore); |
|
|
|
// Fermeture des projections |
|
# ifdef IPCS_SYSV |
|
shmdt(projection_fifos); |
|
# else |
|
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
|
* sizeof(int)); |
|
# endif |
|
|
|
return(0); |
|
} |
|
|
|
inline int |
|
chaine_markov(int markov, int delta) |
|
{ |
|
double memoire = 0.9; |
|
int valeur; |
|
|
|
valeur = (int) ((memoire * markov) + ((1 - memoire) * delta)); |
|
valeur = (valeur < 10) ? 10 : valeur; |
|
|
|
return(valeur); |
|
} |
|
|
|
pid_t |
|
origine_signal(int signal) |
|
{ |
|
logical1 drapeau; |
|
|
|
int *base; |
|
int *buffer; |
|
int delta; |
|
int pid; |
|
int queue; |
|
|
|
queue = queue_de_signal(signal); |
|
|
|
BUG(queue == -1, uprintf("[%d] Unknown signal %d in this context\n", |
|
(int) getpid(), signal)); |
|
|
|
while(sem_wait(semaphores[queue]) != 0) |
|
{ |
|
if (errno != EINTR) |
|
{ |
|
return(-1); |
|
} |
|
} |
|
|
|
// On retire les interruptions anciennes qui ont été ratées sauf s'il |
|
// s'agit de la dernière dans la queue. |
|
|
|
base = &(fifos[(longueur_queue + 4) * queue]); |
|
buffer = &(base[4]); |
|
|
|
if (base[3] == (base[2] - 1)) |
|
{ |
|
delta = abs(horodatage() - |
|
buffer[base[0] + (nombre_queues * base[2])]); |
|
// Une seule interruption dans la queue. |
|
pid = buffer[base[0]++]; |
|
base[0] %= base[2]; |
|
base[3]++; |
|
|
|
markov = chaine_markov(markov, delta); |
|
} |
|
else if (base[3] >= base[2]) |
|
{ |
|
// Aucune interruption n'est dans la queue. |
|
// On a retiré trop d'interruptions de la queue. |
|
|
|
// (base[3] - base[2]) + 1 : nombre d'interruptions manquantes |
|
// base[0] - 1 : dernière interruption lue |
|
pid = buffer[((((base[0] + base[2] - 1) % base[2]) |
|
- ((base[3] - base[2]) + 1)) + base[2]) % base[2]]; |
|
} |
|
else |
|
{ |
|
// Plusieurs interruptions à distribuer. |
|
drapeau = d_vrai; |
|
|
|
do |
|
{ |
|
delta = abs(horodatage() - |
|
buffer[base[0] + (nombre_queues * base[2])]); |
|
pid = buffer[base[0]++]; |
|
base[0] %= base[2]; |
|
base[3]++; |
|
|
|
if ((delta > (2 * markov)) && (base[3] < base[2])) |
|
{ |
|
drapeau = d_vrai; |
|
} |
|
else |
|
{ |
|
drapeau = d_faux; |
|
} |
|
} while(drapeau == d_vrai); |
|
|
|
markov = chaine_markov(markov, delta); |
|
} |
|
|
|
if (sem_post(semaphores[queue]) != 0) |
|
{ |
|
return(-1); |
|
} |
|
|
|
return((pid_t) pid); |
|
} |
|
|
|
#endif |
|
|
|
void |
void |
interruption1(SIGHANDLER_ARGS) |
interruption1(SIGHANDLER_ARGS) |
{ |
{ |
Line 2458 interruption1(SIGHANDLER_ARGS)
|
Line 1732 interruption1(SIGHANDLER_ARGS)
|
verrouillage_gestionnaire_signaux(); |
verrouillage_gestionnaire_signaux(); |
|
|
# ifdef _BROKEN_SIGINFO |
# ifdef _BROKEN_SIGINFO |
if (signal == SIGINT) |
if ((signal == SIGINT) || (signal == SIGTERM)) |
{ |
{ |
// Si l'interruption provient du clavier, il n'y a pas eu d'appel |
// Si l'interruption provient du clavier, il n'y a pas eu d'appel |
// à queue_in(). |
// à queue_in(). |
Line 2470 interruption1(SIGHANDLER_ARGS)
|
Line 1744 interruption1(SIGHANDLER_ARGS)
|
pid = origine_signal(signal); |
pid = origine_signal(signal); |
} |
} |
# else |
# else |
pid = (*siginfo).si_pid; |
if (siginfo != NULL) |
|
{ |
|
pid = (*siginfo).si_pid; |
|
} |
|
else |
|
{ |
|
pid = getpid(); |
|
} |
# endif |
# endif |
|
|
switch(signal) |
switch(signal) |
Line 2515 interruption1(SIGHANDLER_ARGS)
|
Line 1796 interruption1(SIGHANDLER_ARGS)
|
} |
} |
|
|
case SIGINT : |
case SIGINT : |
|
case SIGTERM : |
{ |
{ |
/* |
/* |
* Une vieille spécification POSIX permet au pointeur siginfo |
* Une vieille spécification POSIX permet au pointeur siginfo |
Line 2540 interruption1(SIGHANDLER_ARGS)
|
Line 1822 interruption1(SIGHANDLER_ARGS)
|
|
|
if (((*s_etat_processus).type_debug & d_debug_signaux) != 0) |
if (((*s_etat_processus).type_debug & d_debug_signaux) != 0) |
{ |
{ |
printf("[%d] SIGINT (thread %llu)\n", (int) getpid(), |
if (signal == SIGINT) |
(unsigned long long) pthread_self()); |
{ |
|
printf("[%d] SIGINT (thread %llu)\n", (int) getpid(), |
|
(unsigned long long) pthread_self()); |
|
} |
|
else |
|
{ |
|
printf("[%d] SIGTERM (thread %llu)\n", (int) getpid(), |
|
(unsigned long long) pthread_self()); |
|
} |
|
|
fflush(stdout); |
fflush(stdout); |
} |
} |
|
|
Line 2563 interruption1(SIGHANDLER_ARGS)
|
Line 1854 interruption1(SIGHANDLER_ARGS)
|
return; |
return; |
} |
} |
|
|
if (strncmp(getenv("LANG"), "fr", 2) == 0) |
if (signal == SIGINT) |
{ |
{ |
printf("+++Interruption\n"); |
if (strncmp(getenv("LANG"), "fr", 2) == 0) |
} |
{ |
else |
printf("+++Interruption\n"); |
{ |
} |
printf("+++Interrupt\n"); |
else |
} |
{ |
|
printf("+++Interrupt\n"); |
|
} |
|
|
fflush(stdout); |
fflush(stdout); |
|
} |
|
|
(*s_etat_processus).var_volatile_requete_arret = -1; |
(*s_etat_processus).var_volatile_requete_arret = -1; |
(*s_etat_processus).var_volatile_alarme = -1; |
(*s_etat_processus).var_volatile_alarme = -1; |
Line 2617 interruption2(SIGHANDLER_ARGS)
|
Line 1911 interruption2(SIGHANDLER_ARGS)
|
# ifdef _BROKEN_SIGINFO |
# ifdef _BROKEN_SIGINFO |
pid = origine_signal(signal); |
pid = origine_signal(signal); |
# else |
# else |
pid = (*siginfo).si_pid; |
if (siginfo != NULL) |
|
{ |
|
pid = (*siginfo).si_pid; |
|
} |
|
else |
|
{ |
|
pid = getpid(); |
|
} |
# endif |
# endif |
|
|
# ifndef _BROKEN_SIGINFO |
# ifndef _BROKEN_SIGINFO |
Line 2690 interruption2(SIGHANDLER_ARGS)
|
Line 1991 interruption2(SIGHANDLER_ARGS)
|
void |
void |
interruption3(SIGHANDLER_ARGS) |
interruption3(SIGHANDLER_ARGS) |
{ |
{ |
pid_t pid; |
pthread_t thread; |
|
|
struct_processus *s_etat_processus; |
struct_processus *s_etat_processus; |
|
|
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 2728 interruption3(SIGHANDLER_ARGS)
|
Line 2021 interruption3(SIGHANDLER_ARGS)
|
// Segfault dans une routine interne |
// Segfault dans une routine interne |
if (strncmp(getenv("LANG"), "fr", 2) == 0) |
if (strncmp(getenv("LANG"), "fr", 2) == 0) |
{ |
{ |
printf("+++Système : Violation d'accès (dépassement de pile)\n"); |
printf("+++Système : Violation d'accès\n"); |
} |
} |
else |
else |
{ |
{ |
printf("+++System : Access violation (stack overflow)\n"); |
printf("+++System : Access violation\n"); |
} |
} |
|
|
fflush(stdout); |
fflush(stdout); |
|
|
compteur++; |
(*s_etat_processus).compteur_violation_d_acces++; |
|
|
if (compteur > 1) |
if ((*s_etat_processus).compteur_violation_d_acces > 1) |
{ |
{ |
|
// On vient de récupérer plus d'une erreur de segmentation |
|
// dans le même processus ou le même thread. L'erreur n'est pas |
|
// récupérable et on sort autoritairement du programme. Il peut |
|
// rester des processus orphelins en attente ! |
|
|
|
if (strncmp(getenv("LANG"), "fr", 2) == 0) |
|
{ |
|
printf("+++Système : Violation d'accès\n"); |
|
} |
|
else |
|
{ |
|
printf("+++System : Access violation\n"); |
|
} |
|
|
|
fflush(stdout); |
|
|
deverrouillage_gestionnaire_signaux(); |
deverrouillage_gestionnaire_signaux(); |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
} |
} |
else |
else |
{ |
{ |
|
// Première erreur de segmentation. On essaie de terminer |
|
// proprement le thread ou le processus. Le signal ne peut être |
|
// envoyé que depuis le même processus. |
|
|
|
if (recherche_thread_principal(getpid(), &thread) == d_vrai) |
|
{ |
|
if (pthread_equal(thread, pthread_self()) != 0) |
|
{ |
|
deverrouillage_gestionnaire_signaux(); |
|
|
|
if ((*s_etat_processus).pid_processus_pere != getpid()) |
|
{ |
|
// On est dans le thread principal d'un processus. |
|
|
|
longjmp(contexte_processus, -1); |
|
} |
|
else |
|
{ |
|
// On est dans le thread principal du processus |
|
// père. |
|
|
|
longjmp(contexte_initial, -1); |
|
} |
|
} |
|
else |
|
{ |
|
// On est dans un thread fils d'un thread principal. |
|
|
|
deverrouillage_gestionnaire_signaux(); |
|
longjmp(contexte_thread, -1); |
|
} |
|
} |
|
|
|
// Là, on ramasse les miettes puisque le thread n'existe plus |
|
// dans la base (corruption de la mémoire). |
|
|
deverrouillage_gestionnaire_signaux(); |
deverrouillage_gestionnaire_signaux(); |
longjmp(contexte_initial, -1); |
longjmp(contexte_initial, -1); |
} |
} |
Line 2758 interruption3(SIGHANDLER_ARGS)
|
Line 2103 interruption3(SIGHANDLER_ARGS)
|
void |
void |
interruption4(SIGHANDLER_ARGS) |
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 2866 interruption5(SIGHANDLER_ARGS)
|
Line 2203 interruption5(SIGHANDLER_ARGS)
|
void |
void |
interruption6(SIGHANDLER_ARGS) |
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 2898 interruption6(SIGHANDLER_ARGS)
|
Line 2227 interruption6(SIGHANDLER_ARGS)
|
void |
void |
interruption7(SIGHANDLER_ARGS) |
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 2985 interruption8(SIGHANDLER_ARGS)
|
Line 2306 interruption8(SIGHANDLER_ARGS)
|
void |
void |
interruption9(SIGHANDLER_ARGS) |
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 3030 interruption10(SIGHANDLER_ARGS)
|
Line 2343 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 3169 traitement_exceptions_gsl(const char *re
|
Line 2474 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); |
|
} |
|
|
|
while((semaphore = sem_open(nom, 0)) == SEM_FAILED); |
|
free(nom); |
|
|
|
while(sem_wait(semaphore) != 0) |
|
{ |
|
if (errno != EINTR) |
|
{ |
|
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); |
|
} |
|
|
|
while((semaphore = sem_open(nom, 0)) == SEM_FAILED); |
|
free(nom); |
|
|
|
while(sem_wait(semaphore) != 0) |
|
{ |
|
if (errno != EINTR) |
|
{ |
|
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 |