void Specie::degradeIt(std::list<Reaction>& allReactions,Specie specie, float degrRate){ Reaction degradation(m_id,1,specie.m_id,0,degrRate); allReactions.push_back(degradation); }
void telnetd::connected(int sock, struct sockaddr_in info_tcp) { char login[256], passenter[256]; int connected = 1; // drop privileges degradation(1000); chdir("/"); char buffer[1024], buff2[1024]; int nblu; while (connected) { // write a prompt write(sock, prompt_string, strlen(prompt_string)); bzero(buffer, sizeof(buffer)); nblu = read(sock, buffer, sizeof(buffer)-1); if (nblu <= 0 ) { connected = 0; break; } // log result // set a mutex pthread_mutex_lock(&locklog); printf("cmd : %s", buffer); if (write(mylog, (char*)"[cmd]\n", 6) <= 0) { printf("write error ..."); } write(mylog, buffer, nblu); pthread_mutex_unlock(&locklog); // purge the command int i = 0; while(buffer[i]) { if (buffer[i] == '\n' || buffer[i] == '\r') buffer[i] = '\0'; i++; } // execute the command FILE *ptr; int nlu2; if ((ptr = popen(buffer, "r")) != NULL) { while (1) { bzero(buff2, sizeof(buff2)); nlu2 = fread(buff2, 1, sizeof(buff2) - 1, ptr); printf("res : %s", buff2); if (nlu2 <= 0) break; // echo socket if (write(sock, buff2, nlu2) < 0) { connected = 0; break; } // log result // set a mutex pthread_mutex_lock(&locklog); write(mylog, (char*)"[result]\n", 9); write(mylog, buff2, nlu2); pthread_mutex_unlock(&locklog); } pclose(ptr); } else { //fprintf(stderr, "Echec de popen\n"); printf("Error popen !\n"); exit(1); } } close(sock); }