strncpy(port, name, 8); *traffic = value->u.integer; } } } json_value_free(obj); return 0; } static void add_server(struct manager_ctx *manager, struct server *server) { bool new = false; cork_hash_table_put(server_table, (void *)server->port, (void *)server, &new, NULL, NULL); char *cmd = construct_command_line(manager, server); if (system(cmd) == -1) { ERROR("add_server_system"); } } static void kill_server(char *prefix, char *pid_file) { char *path = NULL; int pid, path_size = strlen(prefix) + strlen(pid_file) + 2; path = malloc(path_size); snprintf(path, path_size, "%s/%s", prefix, pid_file); FILE *f = fopen(path, "r"); if (f == NULL) { if (verbose) { LOGE("unable to open pid file");
/*--------------------------------------------------------------*/ int main( int main_argc, char **main_argv) { clock_t startClock = clock(); /*--------------------------------------------------------------*/ /* Non-function definitions. */ /*--------------------------------------------------------------*/ struct command_line_object *command_line; struct tec_object *tec; struct world_object *world; struct world_output_file_object *output; struct world_output_file_object *growth_output; char *prefix; /*--------------------------------------------------------------*/ /* Local Function declarations */ /*--------------------------------------------------------------*/ struct command_line_object *construct_command_line( int, char **); struct world_object *construct_world( struct command_line_object *); struct world_output_file_object *construct_output_files( char *, struct command_line_object *); struct tec_object *construct_tec( struct command_line_object *, struct world_object * ); void execute_tec( struct tec_object *, struct command_line_object *, struct world_output_file_object *, struct world_output_file_object *, struct world_object *); void destroy_tec( struct tec_object * ); void destroy_output_files( struct command_line_object *, struct world_output_file_object *); void destroy_world( struct command_line_object *, struct world_object *); void destroy_command_line( struct command_line_object * ); void add_headers( struct world_output_file_object *, struct command_line_object * ); void add_growth_headers( struct world_output_file_object *, struct command_line_object * ); srand((unsigned)(time(0))); /*--------------------------------------------------------------*/ /* Command line parsing. */ /*--------------------------------------------------------------*/ command_line = construct_command_line(main_argc, main_argv); /*--------------------------------------------------------------*/ /* Check if print version flag was set. If so, just print out */ /* the version and return. */ /*--------------------------------------------------------------*/ if (command_line[0].version_flag > 0 ) { printf("RHESSys Version: %s\n", RHESSYS_VERSION); return(EXIT_SUCCESS); } if (command_line[0].verbose_flag > 0 ) fprintf(stderr,"FINISHED CON COMMAND LINE ***\n"); /*--------------------------------------------------------------*/ /* Construct the world object. */ /*--------------------------------------------------------------*/ world = construct_world( command_line ); if (command_line[0].verbose_flag > 0 ) fprintf(stderr,"FINISHED CON WORLD ***\n"); /*--------------------------------------------------------------*/ /* Construct the output file objects. */ /*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/ /* Make up the prefix for the output files. */ /*--------------------------------------------------------------*/ prefix = (char *)calloc(256, sizeof(char)); if ( command_line[0].output_prefix != NULL ){ strcpy(prefix,command_line[0].output_prefix); } else{ strcpy(prefix,PRE); } output = construct_output_files( prefix, command_line ); if (command_line[0].grow_flag > 0) { strcat(prefix,"_grow"); growth_output = construct_output_files(prefix, command_line ); } else growth_output = NULL; add_headers(output, command_line); if (command_line[0].grow_flag > 0) add_growth_headers(growth_output, command_line); if(command_line[0].verbose_flag > 0 ) fprintf(stderr,"FINISHED CON OUTPUT\n"); /*--------------------------------------------------------------*/ /* Create the tec object (temporal event control) */ /* */ /* This object specifies temporal events such as output. */ /*--------------------------------------------------------------*/ tec = construct_tec( command_line, world); if (command_line[0].verbose_flag > 0 ) fprintf(stderr,"FINISHED CON TEC\n"); /*--------------------------------------------------------------*/ /* AN EVENT LOOP WOULD GO HERE. */ /*--------------------------------------------------------------*/ fprintf(stderr,"Beginning Simulation\n"); execute_tec( tec, command_line, output, growth_output, world ); if (command_line[0].verbose_flag > 0 ) fprintf(stderr,"FINISHED EXE TEC\n"); /*--------------------------------------------------------------*/ /* Destroy the tec object. */ /*--------------------------------------------------------------*/ destroy_tec( tec ); if (command_line[0].verbose_flag > 0 ) fprintf(stderr,"FINISHED DES TEC\n"); /*--------------------------------------------------------------*/ /* Destroy output file objects (close them) */ /*--------------------------------------------------------------*/ destroy_output_files( command_line, output ); if (command_line[0].grow_flag > 0) destroy_output_files( command_line, growth_output ); if (command_line[0].verbose_flag > 0 ) fprintf(stderr,"FINISHED DES OUTPUT FILES\n"); /*--------------------------------------------------------------*/ /* Destroy the world. */ /*--------------------------------------------------------------*/ destroy_world(command_line, world ); if (command_line[0].verbose_flag > 0 ) fprintf(stderr,"FINISHED DES WORLD\n"); /*--------------------------------------------------------------*/ /* Destroy the command_line_object */ /*--------------------------------------------------------------*/ destroy_command_line( command_line ); if (command_line[0].verbose_flag > 0 ) fprintf(stderr,"FINISHED DES COMMAND LINE\n"); /*--------------------------------------------------------------*/ /* The end. */ /*--------------------------------------------------------------*/ clock_t endClock =clock(); printf("\ntime cost = %ld seconds\n",(endClock - startClock)/CLOCKS_PER_SEC); return(EXIT_SUCCESS); } /*end main*/