#include "common_impl.h" #include /* variables globales */ /* un tableau gerant les infos d'identification */ /* des processus dsm */ dsm_proc_t *proc_array = NULL; /* le nombre de processus effectivement crees */ volatile int num_procs_creat = 0; void usage(void) { fprintf(stdout,"Usage : dsmexec machine_file executable arg1 arg2 ...\n"); fflush(stdout); exit(EXIT_FAILURE); } void sigchld_handler(int sig) { wait(NULL); num_procs_creat--; } //traitant de signal obligatoire pour appel reseaux int main(int argc, char *argv[]) { if (argc < 4){ usage(); } else { pid_t pid; int num_procs = 0; FILE *fichier =NULL; int size_max=256; char **tab_nom; char **argv_ssh=NULL; int sockfd; char hostname[256]; int i=0,j=0,h=0,c=0; int port; int fd_out[2]; int fd_err[2]; struct sigaction action; struct hostent * host; struct sockaddr_in sock_serv; char *buf= malloc(sizeof(char)*size_max); char *buf1= malloc(sizeof(char)*size_max); struct pollfd *list_poll; char *port_char=malloc(sizeof(char)*size_max); int size_list_poll; char *mess=malloc(sizeof(char)*size_max); /* Mise en place d'un traitant pour recuperer les fils zombies*/ memset(&action,0,sizeof(struct sigaction)); action.sa_handler=sigchld_handler; action.sa_flags=SA_RESTART; sigaction(SIGCHLD,&action,NULL); /* lecture du fichier de machines */ /* 1- on recupere le nombre de processus a lancer */ printf("yolo\n"); fichier=fopen( argv[1],"r+"); if (fichier!=NULL){ while((c=fgetc(fichier)) != EOF) { if(c=='\n'){ num_procs++; } } printf("[dsmexec]:: nombre de processus: %i\n",num_procs); /*2- on recupere les noms des machines : le nom de */ rewind(fichier); tab_nom=(char **) malloc(sizeof(char)*size_max*num_procs); tab_nom = malloc(sizeof(char)*size_max*num_procs); for (i = 0; i < num_procs; i++) { tab_nom[i] = malloc(sizeof(char)*size_max); } while(fscanf(fichier, "%s", tab_nom[j])!=-1){ j++; } for (i=0;ih_addr); printf("[dsmexec]:: my ip address :%s\n",name); /* creation de la socket d'ecoute */ /* + ecoute effective */ sockfd=creer_socket(SOCK_STREAM,&port); do_listen(sockfd,num_procs); printf("[dsmexec]:: la socket a été créé avec le port %i & le fd : %i\n",port,sockfd); sprintf(port_char,"%i",port); /* creation des fils */ for(i = 0; i < num_procs ; i++) { pid = fork(); if(pid == -1) { ERROR_EXIT("fork"); } if (pid == 0) { /* fils */ printf("je suis le fils \n"); argv_ssh=(char **) malloc(sizeof(char)*size_max*10); argv_ssh[0]="ssh"; argv_ssh[1]=tab_nom[i]; argv_ssh[2]="/net/t/mlostanlen/Phase1b/bin/dsmwrap"; argv_ssh[3]=port_char; argv_ssh[4]=hostname; argv_ssh[5]=argv[2]; argv_ssh[6]=argv[3]; argv_ssh[7]=argv[4]; argv_ssh[8]=NULL; /* jump to new prog : */ printf("[dsmexec]:: execution ssh\n"); execvp("ssh",argv_ssh); printf("verif execvp\n"); } else if(pid > 0) { /* pere */ printf("Je suis dans le pere\n"); proc_array[i].pid=pid; num_procs_creat++; list_poll=malloc(sizeof(struct pollfd)*2*num_procs); list_poll[2*i].fd=fd_out[0]; list_poll[2*i].events=POLLIN | POLLHUP; list_poll[2*i+1].fd=fd_err[0]; list_poll[2*i+1].events=POLLIN | POLLHUP; } } for(i = 0; i < num_procs ; i++){ /* on accepte les connexions des processus dsm */ int lo; printf("[dsmexec]:: En attente de accept\n"); do{ lo=do_accept(sockfd, &sock_serv); }while(lo==-1 && errno==EINTR); perror(accept); proc_array[i].connect_info.rank = i; printf("[dsmexec]:: On accepte la connexion avec le processus %i \n",i); } /* on attend les processus fils */ for (h=0;h