/* load_tiles: for all tiles, load it's bitmap and create a item in the * element list so we can select it and add it to a map */ void load_tiles(void) { size_t len, old_sz; size_t y; int passable; char buffer[NAME_LN]; char tile_filename[NAME_LN]; BITMAP *bmp = NULL; FILE *fsock = NULL; if (tile_elem_lst) return; /*already lodad */ fsock = fopen(TILE_LIST, "rt"); if (!fsock) return; while (!feof(fsock)) { /* get a filename from the list */ /*fgets(buffer, NAME_LN, fsock);*/ fscanf(fsock, "%s %i\n", buffer, &passable); len = strlen(buffer); /* remove the newline */ if (buffer[len - 1] == '\n') buffer[len - 1] = '\0'; /* build the filename and load the bitmap */ sprintf(tile_filename, "%s%s%s", WORLD_GFX_DIR, buffer, GFX_EXT); bmp = load_bitmap(tile_filename, NULL); /* save the size so we can see if it's really appended */ old_sz = gfx_list_sz; gfx_list = append_bmp_to_gfx_list(buffer, bmp, gfx_list, &gfx_list_sz); if (old_sz == gfx_list_sz) { /* the bitmap wasn't appended, destroy it */ destroy_bitmap(bmp); continue; } /* build the coordinate for the new item */ if (tile_elem_lst_sz == 0) { y = TILE_WIN.y; } else { y = TILE_WIN.y + tile_elem_lst_sz * LIST_ELEM_H; } /* finally add the list element to the list */ tile_elem_lst = add_list_element(rec(TILE_WIN.x, y, LIST_ELEM_W, LIST_ELEM_H), passable, DEFAULT_COLOR, SEL_COLOR, buffer, bmp, tile_elem_lst, &tile_elem_lst_sz); } fclose(fsock); }
void add_breakpoint(uint32_t breakpoint_pc) { static uint32_t *new_element; if (story_has_been_loaded == false) { if (pcs == NULL) pcs = create_list(); new_element = malloc(sizeof(uint32_t)); *new_element = breakpoint_pc; add_list_element(pcs, new_element); } else { if (breakpoints == NULL) breakpoints = create_list(); add_list_element(breakpoints, z_mem + breakpoint_pc); } }
/* load_sprite: load all the sprites in SPRITE_INDEX and their graphics */ void load_sprites(void) { size_t i, y; char bmpname[NAME_LN]; scew_tree *t = NULL; scew_parser *p = NULL; scew_element *e = NULL; scew_element *r = NULL; SPRITE *s = NULL; /* setup the parser */ p = scew_parser_create(); scew_parser_ignore_whitespaces(p, 1); if (!scew_parser_load_file(p, SPRITE_INDEX)) { printf("%s\n", scew_error_expat_string(scew_error_code())); return; } t = scew_parser_tree(p); r = scew_tree_root(t); s = create_sprite(); /* read all the sprites from SPRITE_INDEX */ /* parse the SPRITE_INDEX file and outline the list with their names */ e = scew_element_next(r, e); while (e) { strncpy(s->long_name, (char *) scew_element_name(e), LONG_NAME_LN); s->x = s->y = 0; sprite_list = append_sprite_list(s, sprite_list, &sprite_list_sz); e = scew_element_next(r, e); } /* load all their graphics and the sprite data */ gfx_list = complete_sprite_list(sprite_list, sprite_list_sz, gfx_list, &gfx_list_sz); /* create a list_element for each of them and put them in a list */ y = SPRITE_WIN.y; for (i = 0; i < sprite_list_sz; i++) { sprintf(bmpname, "%s0", sprite_list[i].name); spr_elem_lst = add_list_element(rec(SPRITE_WIN.x, y, LIST_ELEM_W, LIST_ELEM_H), 0, DEFAULT_COLOR, SEL_COLOR, sprite_list[i].name, search_gfx_list(bmpname, gfx_list, gfx_list_sz), spr_elem_lst, &spr_elem_lst_sz); y += LIST_ELEM_H; } /* cleanup */ scew_element_free(r); destroy_sprite(s); scew_element_free(e); scew_parser_free(p); }
int execute_and_create_process(struct subprocess* process, struct inotify_event* event, char *command) { //Execute command using wrapper function. process->start_time=(char*)malloc(sizeof(char)*9); strcpy(process->start_time,get_time_string()); int pid=exec_pipe(command,0); if (pid==-1) { return -1; } process->pid=pid; process->retries=0; process->command=(char *)malloc(sizeof(char)*strlen(command)); process->event=event; process->prev=NULL; process->next=NULL; strcpy(process->command,command); process->path=(char *)malloc(sizeof(char)*(strlen(global_wd_list[event->wd]->path)+strlen(event->name)+2)); sprintf(process->path,"%s/%s",global_wd_list[event->wd]->path,event->name); add_list_element(process); return pid; }
static void print_cluster_status(pe_working_set_t * data_set, long options) { char *online_nodes = NULL; char *online_remote_nodes = NULL; char *online_remote_containers = NULL; char *offline_nodes = NULL; char *offline_remote_nodes = NULL; GListPtr gIter = NULL; for (gIter = data_set->nodes; gIter != NULL; gIter = gIter->next) { node_t *node = (node_t *) gIter->data; const char *node_mode = NULL; char *node_name = NULL; if (is_container_remote_node(node)) { node_name = crm_strdup_printf("%s:%s", node->details->uname, node->details->remote_rsc->container->id); } else { node_name = crm_strdup_printf("%s", node->details->uname); } if (node->details->unclean) { if (node->details->online && node->details->unclean) { node_mode = "UNCLEAN (online)"; } else if (node->details->pending) { node_mode = "UNCLEAN (pending)"; } else { node_mode = "UNCLEAN (offline)"; } } else if (node->details->pending) { node_mode = "pending"; } else if (node->details->standby_onfail && node->details->online) { node_mode = "standby (on-fail)"; } else if (node->details->standby) { if (node->details->online) { node_mode = "standby"; } else { node_mode = "OFFLINE (standby)"; } } else if (node->details->maintenance) { if (node->details->online) { node_mode = "maintenance"; } else { node_mode = "OFFLINE (maintenance)"; } } else if (node->details->online) { if (is_container_remote_node(node)) { online_remote_containers = add_list_element(online_remote_containers, node_name); } else if (is_baremetal_remote_node(node)) { online_remote_nodes = add_list_element(online_remote_nodes, node_name); } else { online_nodes = add_list_element(online_nodes, node_name); } free(node_name); continue; } else { if (is_baremetal_remote_node(node)) { offline_remote_nodes = add_list_element(offline_remote_nodes, node_name); } else if (is_container_remote_node(node)) { /* ignore offline container nodes */ } else { offline_nodes = add_list_element(offline_nodes, node_name); } free(node_name); continue; } if (is_container_remote_node(node)) { printf("ContainerNode %s: %s\n", node_name, node_mode); } else if (is_baremetal_remote_node(node)) { printf("RemoteNode %s: %s\n", node_name, node_mode); } else if (safe_str_eq(node->details->uname, node->details->id)) { printf("Node %s: %s\n", node_name, node_mode); } else { printf("Node %s (%s): %s\n", node_name, node->details->id, node_mode); } free(node_name); } if (online_nodes) { printf("Online: [%s ]\n", online_nodes); free(online_nodes); } if (offline_nodes) { printf("OFFLINE: [%s ]\n", offline_nodes); free(offline_nodes); } if (online_remote_nodes) { printf("RemoteOnline: [%s ]\n", online_remote_nodes); free(online_remote_nodes); } if (offline_remote_nodes) { printf("RemoteOFFLINE: [%s ]\n", offline_remote_nodes); free(offline_remote_nodes); } if (online_remote_containers) { printf("Containers: [%s ]\n", online_remote_containers); free(online_remote_containers); } fprintf(stdout, "\n"); for (gIter = data_set->resources; gIter != NULL; gIter = gIter->next) { resource_t *rsc = (resource_t *) gIter->data; if (is_set(rsc->flags, pe_rsc_orphan) && rsc->role == RSC_ROLE_STOPPED) { continue; } rsc->fns->print(rsc, NULL, pe_print_printf | options, stdout); } fprintf(stdout, "\n"); }
static void print_synapse(unsigned int log_level, crm_graph_t * graph, synapse_t * synapse) { GListPtr lpc = NULL; char *pending = NULL; const char *state = "Pending"; if (synapse->failed) { state = "Failed"; } else if (synapse->confirmed) { state = "Completed"; } else if (synapse->executed) { state = "In-flight"; } else if (synapse->ready) { state = "Ready"; } if (synapse->executed == FALSE) { for (lpc = synapse->inputs; lpc != NULL; lpc = lpc->next) { crm_action_t *input = (crm_action_t *) lpc->data; const char *id_string = crm_element_value(input->xml, XML_ATTR_ID); if (input->failed) { pending = add_list_element(pending, id_string); } else if (input->confirmed) { /* Confirmed, skip */ } else if (find_action(graph, input->id)) { /* In-flight or pending */ pending = add_list_element(pending, id_string); } } } for (lpc = synapse->actions; lpc != NULL; lpc = lpc->next) { crm_action_t *action = (crm_action_t *) lpc->data; const char *key = crm_element_value(action->xml, XML_LRM_ATTR_TASK_KEY); const char *host = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); char *desc = crm_strdup_printf("%s %s op %s", state, actiontype2text(action->type), key); do_crm_log(log_level, "[Action %4d]: %-50s on %s (priority: %d, waiting: %s)", action->id, desc, host ? host : "N/A", synapse->priority, pending ? pending : "none"); free(desc); } if (synapse->executed == FALSE) { for (lpc = synapse->inputs; lpc != NULL; lpc = lpc->next) { crm_action_t *input = (crm_action_t *) lpc->data; const char *key = crm_element_value(input->xml, XML_LRM_ATTR_TASK_KEY); const char *host = crm_element_value(input->xml, XML_LRM_ATTR_TARGET); if (find_action(graph, input->id) == NULL) { if (host == NULL) { do_crm_log(log_level, " * [Input %2d]: Unresolved dependency %s op %s", input->id, actiontype2text(input->type), key); } else { do_crm_log(log_level, " * [Input %2d]: Unresolved dependency %s op %s on %s", input->id, actiontype2text(input->type), key, host); } } } } free(pending); }
void debugger_story_has_been_loaded() { size_t index, len; uint32_t *element; char prefix_string[] = { FIZMO_COMMAND_PREFIX, 0 }; int flags; //add_breakpoint(0x200d0); story_has_been_loaded = true; if (pcs != NULL) { len = get_list_size(pcs); breakpoints = create_list(); for (index=0; index<len; index++) { element = (uint32_t*)get_list_element(pcs, index); // TODO: Verify breakpoints. add_list_element(breakpoints, z_mem + *element); free(element); } delete_list(pcs); pcs = NULL; } sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) exit(-1); bzero((char *) &serv_addr, sizeof(struct sockaddr_in)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(DEBUGGER_PORT); inet_pton(AF_INET, DEBUGGER_IP_ADDRESS, &serv_addr.sin_addr.s_addr); if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) exit(-1); listen(sockfd,5); clilen = sizeof(cli_addr); streams_latin1_output("\nPlease connect to "); streams_latin1_output(DEBUGGER_IP_ADDRESS); sprintf(buffer, ":%d", DEBUGGER_PORT); streams_latin1_output(buffer); streams_latin1_output(" to start.\n"); while (newsockfd < 0) { if ((newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen)) >= 0) break; if (errno != EINTR) { perror("accept"); exit(-1); } } flags = fcntl(newsockfd, F_GETFL, 0); fcntl(newsockfd, F_SETFL, flags | O_NONBLOCK); debugger_output(newsockfd, "\nFizmo debugger, libfizmo version "); debugger_output(newsockfd, LIBFIZMO_VERSION); debugger_output(newsockfd, ".\n"); debugger_output(newsockfd, "Enter \""); debugger_output(newsockfd, prefix_string); debugger_output(newsockfd, "debug\" as story input to start debugging.\n\n"); }
static locale_module *parse_locale_file(z_ucs *module_name, char* locale_dir_name, char* module_name_utf8) { char *filename; z_file *in; z_ucs *locale_data; locale_module *result; char in_char; long nof_zucs_chars; z_ucs input; z_ucs *linestart; list *lines; TRACE_LOG("locale_dir_name: \"%s\".\n", locale_dir_name); TRACE_LOG("module_name_utf8: \"%s\".\n", module_name_utf8); // open-resource: if ((filename = malloc(strlen(locale_dir_name) + strlen(module_name_utf8) + 2)) == NULL) { // exit-point: TRACE_LOG("malloc() returned NULL.\n"); return NULL; } TRACE_LOG("locale_dir_name: \"%s\".\n", locale_dir_name); TRACE_LOG("module_name_utf8: \"%s\".\n", module_name_utf8); strcpy(filename, locale_dir_name); strcat(filename, "/"); strcat(filename, module_name_utf8); TRACE_LOG("Parsing locale file \"%s\".\n", filename); // open-resource: if ((in = fsi->openfile(filename, FILETYPE_DATA, FILEACCESS_READ)) == NULL) { // exit-point: TRACE_LOG("openfile(\"%s\") returned NULL.\n", filename); free(filename); return NULL; } nof_zucs_chars = 0; while ((parse_utf8_char_from_file(in)) != UEOF) nof_zucs_chars++; nof_zucs_chars++; // Add space for terminating zero (yes, really required). if (fsi->setfilepos(in, 0, SEEK_SET) == -1) { // exit-point: TRACE_LOG("setfilepos() returned -1.\n"); fsi->closefile(in); free(filename); return NULL; } TRACE_LOG("Allocating space for %ld z_ucs chars.\n", nof_zucs_chars); // open-resource: if ((locale_data = malloc(nof_zucs_chars * sizeof(z_ucs))) == NULL) { // exit-point: TRACE_LOG("malloc(%ld) returned NULL.\n", nof_zucs_chars * sizeof(z_ucs)); fsi->closefile(in); free(filename); return NULL; } TRACE_LOG("Locale data at %p, ends at %p.\n", locale_data, locale_data+nof_zucs_chars); // open-resource: if ((result = malloc(sizeof(locale_module))) == NULL) { // exit-point: free(locale_data); fsi->closefile(in); free(filename); return NULL; } TRACE_LOG("New module at %p.\n", result); result->locale_data = locale_data; TRACE_LOG("Locale data starts at %p.\n", locale_data); /* --- */ // open-resource: lines = create_list(); //printf("new list created: %p\n", lines); in_char = fsi->getchar(in); while (in_char != EOF) { linestart = locale_data; // Found a new line. fsi->ungetchar(in_char, in); for (;;) { input = input_char(in); if (input == Z_UCS_BACKSLASH) { //*locale_data++ = input; input = input_char(in); if (input == Z_UCS_BACKSLASH) { *locale_data++ = Z_UCS_BACKSLASH; } else if (input == 'n') { *locale_data++ = Z_UCS_NEWLINE; } else if (input == '{') { *locale_data++ = Z_UCS_BACKSLASH; *locale_data++ = (z_ucs)'{'; input = input_char(in); if ((input < 0x30) && (input > 0x39)) { fprintf(stderr, "Variable number expected.\n"); exit(EXIT_FAILURE); } *locale_data++ = input; input = input_char(in); if ( (input != (z_ucs)'s') && (input != (z_ucs)'d') && (input != (z_ucs)'x') && (input != (z_ucs)'z') ) { fprintf(stderr, "Invalid parameter type.\n"); exit(EXIT_FAILURE); } *locale_data++ = input; input = input_char(in); if (input != (z_ucs)'}') { fprintf(stderr, "Expected '}'.\n"); exit(EXIT_FAILURE); } *locale_data++ = (z_ucs)'}'; } else { fprintf(stderr, "Undefined control sequence \\%c.\n",(char)input); exit(EXIT_FAILURE); } } else if (input == Z_UCS_NEWLINE) { *locale_data++ = 0; TRACE_LOG("New line at %p.\n", linestart); add_list_element(lines, (void*)linestart); //TRACE_LOG_Z_UCS(linestart); break; } else { // Here we've found some "normal" output. *locale_data++ = (z_ucs)input; } } //messages_processed++; in_char = fsi->getchar(in); } *locale_data = 0; TRACE_LOG("Wirte last byte at %p.\n", locale_data); /* --- */ TRACE_LOG("Read %d lines.\n", get_list_size(lines)); // close-resource(l), open-resource(result->messages): result->nof_messages = get_list_size(lines); result->messages = (z_ucs**)delete_list_and_get_ptrs(lines); TRACE_LOG("Messages at %p.\n", result->messages); TRACE_LOG("First msg at %p.\n", result->messages[0]); if ((result->module_name = malloc(sizeof(z_ucs) * (z_ucs_len(module_name)+1))) == NULL) { // exit-point: free(result->messages); free(result); free(locale_data); fsi->closefile(in); free(filename); return NULL; } z_ucs_cpy(result->module_name, module_name); // close-resource: fsi->closefile(in); // close-resource: free(filename); TRACE_LOG("Returning new module at %p.\n", result); return result; }
void clone_print(resource_t * rsc, const char *pre_text, long options, void *print_data) { char *list_text = NULL; char *child_text = NULL; char *stopped_list = NULL; const char *type = "Clone"; GListPtr master_list = NULL; GListPtr started_list = NULL; GListPtr gIter = rsc->children; clone_variant_data_t *clone_data = NULL; int active_instances = 0; if (pre_text == NULL) { pre_text = " "; } if (options & pe_print_xml) { clone_print_xml(rsc, pre_text, options, print_data); return; } get_clone_variant_data(clone_data, rsc); child_text = crm_concat(pre_text, " ", ' '); if (rsc->variant == pe_master) { type = "Master/Slave"; } status_print("%s%s Set: %s [%s]%s%s", pre_text ? pre_text : "", type, rsc->id, ID(clone_data->xml_obj_child), is_set(rsc->flags, pe_rsc_unique) ? " (unique)" : "", is_set(rsc->flags, pe_rsc_managed) ? "" : " (unmanaged)"); if (options & pe_print_html) { status_print("\n<ul>\n"); } else if ((options & pe_print_log) == 0) { status_print("\n"); } for (; gIter != NULL; gIter = gIter->next) { gboolean print_full = FALSE; resource_t *child_rsc = (resource_t *) gIter->data; if (options & pe_print_clone_details) { print_full = TRUE; } if (child_rsc->fns->active(child_rsc, FALSE) == FALSE) { /* Inactive clone */ if (is_set(child_rsc->flags, pe_rsc_orphan)) { continue; } else if (is_set(rsc->flags, pe_rsc_unique)) { print_full = TRUE; } else if (is_not_set(options, pe_print_clone_active)) { stopped_list = add_list_element(stopped_list, child_rsc->id); } } else if (is_set_recursive(child_rsc, pe_rsc_unique, TRUE) || is_set_recursive(child_rsc, pe_rsc_orphan, TRUE) || is_set_recursive(child_rsc, pe_rsc_managed, FALSE) == FALSE || is_set_recursive(child_rsc, pe_rsc_failed, TRUE)) { /* Unique, unmanaged or failed clone */ print_full = TRUE; } else if (is_set(options, pe_print_pending) && child_rsc->pending_task != NULL) { /* In a pending state */ print_full = TRUE; } else if (child_rsc->fns->active(child_rsc, TRUE)) { /* Fully active anonymous clone */ node_t *location = child_rsc->fns->location(child_rsc, NULL, TRUE); if (location) { enum rsc_role_e a_role = child_rsc->fns->state(child_rsc, TRUE); if (location->details->online == FALSE && location->details->unclean) { print_full = TRUE; } else if (a_role > RSC_ROLE_SLAVE) { /* And active on a single node as master */ master_list = g_list_append(master_list, location); } else { /* And active on a single node as started/slave */ started_list = g_list_append(started_list, location); } } else { /* uncolocated group - bleh */ print_full = TRUE; } } else { /* Partially active anonymous clone */ print_full = TRUE; } if (print_full) { if (options & pe_print_html) { status_print("<li>\n"); } child_rsc->fns->print(child_rsc, child_text, options, print_data); if (options & pe_print_html) { status_print("</li>\n"); } } } /* Masters */ master_list = g_list_sort(master_list, sort_node_uname); for (gIter = master_list; gIter; gIter = gIter->next) { node_t *host = gIter->data; list_text = add_list_element(list_text, host->details->uname); active_instances++; } short_print(list_text, child_text, "Masters", NULL, options, print_data); g_list_free(master_list); free(list_text); list_text = NULL; /* Started/Slaves */ started_list = g_list_sort(started_list, sort_node_uname); for (gIter = started_list; gIter; gIter = gIter->next) { node_t *host = gIter->data; list_text = add_list_element(list_text, host->details->uname); active_instances++; } if(rsc->variant == pe_master) { enum rsc_role_e role = configured_role(rsc); if(role > RSC_ROLE_STOPPED && role < RSC_ROLE_MASTER) { short_print(list_text, child_text, "Slaves (target-role)", NULL, options, print_data); } else { short_print(list_text, child_text, "Slaves", NULL, options, print_data); } } else { short_print(list_text, child_text, "Started", NULL, options, print_data); } g_list_free(started_list); free(list_text); list_text = NULL; if (is_not_set(options, pe_print_clone_active)) { const char *state = "Stopped"; enum rsc_role_e role = configured_role(rsc); if (role == RSC_ROLE_STOPPED) { state = "Stopped (disabled)"; } if (is_not_set(rsc->flags, pe_rsc_unique) && (clone_data->clone_max > active_instances)) { GListPtr nIter; GListPtr list = g_hash_table_get_values(rsc->allowed_nodes); /* Custom stopped list for non-unique clones */ free(stopped_list); stopped_list = NULL; if (g_list_length(list) == 0) { /* Clusters with symmetrical=false haven't calculated allowed_nodes yet * If we've not probed for them yet, the Stopped list will be empty */ list = g_hash_table_get_values(rsc->known_on); } list = g_list_sort(list, sort_node_uname); for (nIter = list; nIter != NULL; nIter = nIter->next) { node_t *node = (node_t *)nIter->data; if (pe_find_node(rsc->running_on, node->details->uname) == NULL) { stopped_list = add_list_element(stopped_list, node->details->uname); } } g_list_free(list); } short_print(stopped_list, child_text, state, NULL, options, print_data); free(stopped_list); } if (options & pe_print_html) { status_print("</ul>\n"); } free(child_text); }