/** * Traite la connection avec le client. */ void process_client() { char buffer[MESSAGE_BUFFER_SIZE]; char host[HOST_SIZE]; /* Le client vient de se connecter */ client_open_connection(); if (gethostname(host, sizeof host) == -1 && errno == EINVAL) host[sizeof host - 1] = '\0'; /* On envoie un message de bienvenue et le prompt */ snprintf(buffer, sizeof buffer, "%s [ %s ]\n", welcome, host); send_basic(client_socket, buffer, strlen(buffer)); send_basic(client_socket, prompt_client, strlen(prompt_client)); /* On traite tous les messages du client */ while (recv(client_socket, buffer, MESSAGE_BUFFER_SIZE, 0) > 0) { verbose("Client # %s\n", buffer); /* On traite la commande */ if (parse_client_line(client_socket, buffer) == MSG_QUIT) break; send_basic(client_socket, prompt_client, strlen(prompt_client)); } /* Si on arrive ici, c'est que le client a quitté. */ client_close_connection(); }
static int init_server_connection() { char *connection, *rankinfo_s, *opts_s, *cachesize_s; debug_printf("Initializing connection to server\n"); if (ldcsid != -1) return 0; if (!use_ldcs) return 0; location = getenv("LDCS_LOCATION"); number = atoi(getenv("LDCS_NUMBER")); connection = getenv("LDCS_CONNECTION"); rankinfo_s = getenv("LDCS_RANKINFO"); opts_s = getenv("LDCS_OPTIONS"); cachesize_s = getenv("LDCS_CACHESIZE"); opts = atol(opts_s); shm_cachesize = atoi(cachesize_s) * 1024; if (strchr(location, '$')) { location = parse_location(location); } if (!(opts & OPT_FOLLOWFORK)) { debug_printf("Disabling environment variables because we're not following forks\n"); unsetenv("LD_AUDIT"); unsetenv("LDCS_LOCATION"); unsetenv("LDCS_NUMBER"); unsetenv("LDCS_CONNECTION"); unsetenv("LDCS_RANKINFO"); unsetenv("LDCS_OPTIONS"); } if (opts & OPT_SHMCACHE) { assert(shm_cachesize); #if defined(COMM_BITER) shm_cache_limit = shm_cachesize > 512*1024 ? shm_cachesize - 512*1024 : 0; #else shm_cache_limit = shm_cachesize; #endif shmcache_init(location, number, shm_cachesize, shm_cache_limit); } if (connection) { /* boostrapper established the connection for us. Reuse it. */ debug_printf("Recreating existing connection to server\n"); debug_printf3("location = %s, number = %d, connection = %s, rankinfo = %s\n", location, number, connection, rankinfo_s); ldcsid = client_register_connection(connection); if (ldcsid == -1) return -1; assert(rankinfo_s); sscanf(rankinfo_s, "%d %d %d %d", rankinfo+0, rankinfo+1, rankinfo+2, rankinfo+3); unsetenv("LDCS_CONNECTION"); } else { /* Establish a new connection */ debug_printf("open connection to ldcs %s %d\n", location, number); ldcsid = client_open_connection(location, number); if (ldcsid == -1) return -1; send_pid(ldcsid); send_location(ldcsid, location); send_rankinfo_query(ldcsid, rankinfo+0, rankinfo+1, rankinfo+2, rankinfo+3); } snprintf(debugging_name, 32, "Client.%d", rankinfo[0]); LOGGING_INIT(debugging_name); sync_cwd(); if (opts & OPT_RELOCPY) parse_python_prefixes(ldcsid); return 0; }