|  | @@ -24,10 +24,12 @@
 | 
	
		
			
				|  |  |  /* --- Extern --- */
 | 
	
		
			
				|  |  |  extern Error error;
 | 
	
		
			
				|  |  |  extern boolean exitsh;
 | 
	
		
			
				|  |  | +extern pid_t active;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /* --- Global --- */
 | 
	
		
			
				|  |  |  pid_list pidlist;
 | 
	
		
			
				|  |  | -pid_node* active = NULL;
 | 
	
		
			
				|  |  | +boolean fond = false;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  int job = 1;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /* --- Fonctions privées --- */
 | 
	
	
		
			
				|  | @@ -170,6 +172,8 @@ int main(int argc, char* argv[]) {
 | 
	
		
			
				|  |  |          clean_pid(&pidlist);
 | 
	
		
			
				|  |  |          error.exit_err();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +    //Gestion interuption
 | 
	
		
			
				|  |  | +    signal(SIGINT, handler);
 | 
	
		
			
				|  |  |      //Boucle infini de lecture
 | 
	
		
			
				|  |  |      while(!exitsh){
 | 
	
		
			
				|  |  |          //On regarde si un fils en fond est mort
 | 
	
	
		
			
				|  | @@ -182,9 +186,8 @@ int main(int argc, char* argv[]) {
 | 
	
		
			
				|  |  |          show_current_dir(before, ">\x1b[0m ");      
 | 
	
		
			
				|  |  |          //Lecture ligne
 | 
	
		
			
				|  |  |          if(get_line(line) == SHELL_ERR){
 | 
	
		
			
				|  |  | -            error.print("Impossible de lire les commandes\n");
 | 
	
		
			
				|  |  | -            clean_pid(&pidlist);
 | 
	
		
			
				|  |  | -            error.exit_err();
 | 
	
		
			
				|  |  | +            //error.print("Impossible de lire les commandes\n");
 | 
	
		
			
				|  |  | +            continue;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //Parse la ligne et commandes
 | 
	
		
			
				|  |  |          result = parse_line(&ct, line);
 | 
	
	
		
			
				|  | @@ -234,6 +237,7 @@ int run(CommandTab ct, int* status){
 | 
	
		
			
				|  |  |          if(pid == 0){
 | 
	
		
			
				|  |  |              int stat = 0;
 | 
	
		
			
				|  |  |              ct.bck = 0;
 | 
	
		
			
				|  |  | +            fond = true;
 | 
	
		
			
				|  |  |              result = run(ct, &stat);
 | 
	
		
			
				|  |  |              //Message de fin + retour
 | 
	
		
			
				|  |  |              if(result == SHELL_FAIL){
 | 
	
	
		
			
				|  | @@ -366,4 +370,46 @@ int run(CommandTab ct, int* status){
 | 
	
		
			
				|  |  |          return SHELL_FAIL;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      return SHELL_OK;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +void handler(int sig){
 | 
	
		
			
				|  |  | +    char reponse = ' ';
 | 
	
		
			
				|  |  | +    pid_node* pn;
 | 
	
		
			
				|  |  | +    //Repositionne le gestionnaire (Ne marche plus apres 1 utilisation)
 | 
	
		
			
				|  |  | +    signal(SIGINT, handler);
 | 
	
		
			
				|  |  | +    //Si on est en fond on est non concerné
 | 
	
		
			
				|  |  | +    if(fond){
 | 
	
		
			
				|  |  | +        return;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    //Si il y a un process actif on le coupe
 | 
	
		
			
				|  |  | +    printf("Active : %d\n", active);
 | 
	
		
			
				|  |  | +    if(active != -1){
 | 
	
		
			
				|  |  | +        if(kill(active, SIGINT) == ERR){
 | 
	
		
			
				|  |  | +            addperror("Impossible de tuer le processus en cours");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        active = -1;
 | 
	
		
			
				|  |  | +        return;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    //Sinon demande comfirmation pour finir le programme
 | 
	
		
			
				|  |  | +    while(reponse != 'o' && reponse != 'O' && reponse != 'n' && reponse != 'N'){
 | 
	
		
			
				|  |  | +        printf("Voulez vous vraiment quitter ? [O/N] ");
 | 
	
		
			
				|  |  | +        if(scanf("%c", &reponse) == 0){
 | 
	
		
			
				|  |  | +            reponse = ' ';
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    //Si oui
 | 
	
		
			
				|  |  | +    if(reponse == 'n' || reponse == 'N'){
 | 
	
		
			
				|  |  | +        return;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    //Coupe tous les processus en fond
 | 
	
		
			
				|  |  | +    pn = pidlist.first;
 | 
	
		
			
				|  |  | +    while(pn != NULL){
 | 
	
		
			
				|  |  | +        if(kill(pn->pid, SIGINT) == ERR){
 | 
	
		
			
				|  |  | +            addperror("Impossible de tuer le processus en fond");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        pn = pn->next;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    //Termine l'execution
 | 
	
		
			
				|  |  | +    clean_pid(&pidlist);
 | 
	
		
			
				|  |  | +    error.exit();
 | 
	
		
			
				|  |  |  }
 |