void drive_frontend(){ //printf("drive_frontend\n"); set_option("follow_path", "true"); set_option("single_step", "true"); set<PathAndConds> frontier; load_heuristics(); int n = 0; do { PathAndConds first; if(frontier.size()){ bool pick_random = cmd_option_bool("random_branching"); //bool pick_random = true; if(pick_random){ int pick = rand() % frontier.size() - 1; set<PathAndConds>::iterator it = frontier.begin(); it++; while(pick > 0){ it++; pick--; } first = *(it); frontier.erase(it); } else { first = *(frontier.begin()); frontier.erase(frontier.begin()); } } set_option("path", first.path); set_option("file_initializations", first.file_initializations); options_to_file(); db_command("delete from frontend;"); db_command("delete from results;"); db_command("delete from last_bb;"); db_command("delete from variables;"); // Run resulting file stringstream cmd; cmd << "./" << cmd_option_str("output_file"); systm(cmd.str().c_str()); add_paths(frontier); if(n++ == cmd_option_int("max_depth")) exit(0); if(cmd_option_bool("show_frontier")){ printf("last_bb %s\n", get_last_bb().c_str() ); // last one executed. // frontier contains the constraints to get to last_bb + the last constraint if(get_last_bb() == cmd_option_str("target_node")){ printf("Node hitted\n"); //exit(0); break; } print_frontier(frontier); if(cmd_option_bool("stop_in_frontier")) getchar(); } } while(frontier.size()); }
/* * Use the heuristics to check for a filesystem on the slice. */ int inuse_fs(char *slice, nvlist_t *attrs, int *errp) { struct heuristic *hp; time_t curr_time; int found = 0; *errp = 0; if (slice == NULL) { return (0); } /* * We get the list of heuristic programs one time. */ (void) mutex_lock(&init_lock); if (!initialized) { *errp = load_heuristics(); if (*errp == 0) { initialized = 1; } } (void) mutex_unlock(&init_lock); /* Run each of the heuristics. */ for (hp = hlist; hp; hp = hp->next) { if (has_fs(hp->prog, slice)) { libdiskmgt_add_str(attrs, DM_USED_BY, DM_USE_FS, errp); libdiskmgt_add_str(attrs, DM_USED_NAME, hp->type, errp); found = 1; } } if (*errp != 0) return (found); /* * Second heuristic used is the check for an entry in vfstab */ (void) mutex_lock(&vfstab_lock); curr_time = time(NULL); if (timestamp < curr_time && (curr_time - timestamp) > 60) { free_vfstab(vfstab_listp); *errp = load_vfstab(); timestamp = curr_time; } if (*errp == 0) { struct vfstab_list *listp; listp = vfstab_listp; while (listp != NULL) { if (strcmp(slice, listp->special) == 0) { char *mountp = ""; if (listp->mountp != NULL) mountp = listp->mountp; libdiskmgt_add_str(attrs, DM_USED_BY, DM_USE_VFSTAB, errp); libdiskmgt_add_str(attrs, DM_USED_NAME, mountp, errp); found = 1; } listp = listp->next; } } (void) mutex_unlock(&vfstab_lock); return (found); }