int load_obj_struct_from_file(int num, object *obj_ptr ) { int fd; int n; char file[256]; int ret = -1; zero( obj_ptr, sizeof(object ) ); #ifdef TC sprintf(file, "%s\\o%02d", get_object_path(), num/OFILESIZE); #else sprintf(file, "%s/o%02d", get_object_path(), num/OFILESIZE); #endif fd = open(file, O_RDONLY | O_BINARY ); if(fd >= 0) { n = lseek(fd, (long)((num%OFILESIZE)*sizeof(object)), 0); if(n >= 0L) { n = read( fd, obj_ptr, sizeof(object) ); if ( n == sizeof(object) ) { ret = 0; } } close( fd ); } return(ret); }
int save_obj_to_file(int num, object *obj_ptr) { int fd; long n; char file[256]; sprintf(file, "%s/o%02d", get_object_path(), num/OFILESIZE); fd = open(file, O_RDWR | O_BINARY ); if(fd < 0) { fd = open(file, O_RDWR | O_CREAT | O_BINARY, ACC); if(fd < 0) return(-1); } n = lseek(fd, (long)((num%OFILESIZE)*sizeof(object)), 0); if(n < 0L) { close(fd); return(-1); } n = write(fd, obj_ptr, sizeof(object)); if(n < sizeof(object)) { close(fd); return(-1); } close(fd); return(0); }
/* * analyze_object * Look at a library loaded into the current process, and determine as much as * possible about it. The disassembling, allocations are initiated here. * * This is a callback function, passed to dl_iterate_phdr(3). * data and size are just unused callback arguments. * * * From dl_iterate_phdr(3) man page: * * struct dl_phdr_info * { * ElfW(Addr) dlpi_addr; Base address of object * const char *dlpi_name; (Null-terminated) name of object * const ElfW(Phdr) *dlpi_phdr; Pointer to array of ELF program headers * ElfW(Half) dlpi_phnum; # of items in dlpi_phdr * ... * } * */ static int analyze_object(struct dl_phdr_info *info, size_t size, void *data) { (void) data; (void) size; const char *path; debug_dump("analyze_object called on \"%s\" at 0x%016" PRIxPTR "\n", info->dlpi_name, info->dlpi_addr); if ((path = get_object_path(info)) == NULL) return 0; debug_dump("analyze %s\n", path); if (!should_patch_object(info->dlpi_addr, path)) return 0; struct intercept_desc *patches = allocate_next_obj_desc(); patches->base_addr = (unsigned char *)info->dlpi_addr; patches->path = path; find_syscalls(patches); allocate_trampoline_table(patches); create_patch_wrappers(patches); return 0; }
static void force_local_option(xmlNode *xml, const char *attr_name, const char *attr_value) { int max = 0; int lpc = 0; char *xpath_string = NULL; xmlXPathObjectPtr xpathObj = NULL; xpath_string = crm_strdup_printf("%.128s//%s//nvpair[@name='%.128s']", get_object_path(XML_CIB_TAG_CRMCONFIG), XML_CIB_TAG_PROPSET, attr_name); xpathObj = xpath_search(xml, xpath_string); max = numXpathResults(xpathObj); free(xpath_string); for (lpc = 0; lpc < max; lpc++) { xmlNode *match = getXpathResult(xpathObj, lpc); crm_trace("Forcing %s/%s = %s", ID(match), attr_name, attr_value); crm_xml_add(match, XML_NVPAIR_ATTR_VALUE, attr_value); } if(max == 0) { xmlNode *configuration = NULL; xmlNode *crm_config = NULL; xmlNode *cluster_property_set = NULL; crm_trace("Creating %s-%s for %s=%s", CIB_OPTIONS_FIRST, attr_name, attr_name, attr_value); configuration = find_entity(xml, XML_CIB_TAG_CONFIGURATION, NULL); if (configuration == NULL) { configuration = create_xml_node(xml, XML_CIB_TAG_CONFIGURATION); } crm_config = find_entity(configuration, XML_CIB_TAG_CRMCONFIG, NULL); if (crm_config == NULL) { crm_config = create_xml_node(configuration, XML_CIB_TAG_CRMCONFIG); } cluster_property_set = find_entity(crm_config, XML_CIB_TAG_PROPSET, NULL); if (cluster_property_set == NULL) { cluster_property_set = create_xml_node(crm_config, XML_CIB_TAG_PROPSET); crm_xml_add(cluster_property_set, XML_ATTR_ID, CIB_OPTIONS_FIRST); } xml = create_xml_node(cluster_property_set, XML_CIB_TAG_NVPAIR); crm_xml_set_id(xml, "%s-%s", CIB_OPTIONS_FIRST, attr_name); crm_xml_add(xml, XML_NVPAIR_ATTR_NAME, attr_name); crm_xml_add(xml, XML_NVPAIR_ATTR_VALUE, attr_value); } freeXpathObject(xpathObj); }
int load_obj_from_file(int num, object **obj_ptr ) { int fd; long n; char file[256]; int ret = 0; #ifdef TC sprintf(file, "%s\\o%02d", get_object_path(), num/OFILESIZE); #else sprintf(file, "%s/o%02d", get_object_path(), num/OFILESIZE); #endif fd = open(file, O_RDONLY | O_BINARY ); if(fd < 0) return(-1); *obj_ptr = (object *)malloc(sizeof(object)); if(!*obj_ptr) merror("load_obj", FATAL); n = lseek(fd, (long)((num%OFILESIZE)*sizeof(object)), 0); if(n < 0L) { close(fd); return(-1); } if ( read_single_obj(fd, *obj_ptr ) != 0 ) { free(*obj_ptr); *obj_ptr = 0; ret = -1; } close(fd); return(ret); }
gint ConnmanManager::create_manager_sync() { gint ret = 0; DBG3(); DBG("Creating proxy of object path '%s'", get_object_path()); ret = create_proxy_sync(); if(ret != 0) { ERR("creating proxy."); return -1; } return 0; }
int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1) { int ret; void *buf; struct siocb iocb = {}; uint32_t length; bool is_readonly_obj = oid_is_readonly(oid); char path[PATH_MAX]; ret = get_object_path(oid, epoch, path, sizeof(path)); if (ret != SD_RES_SUCCESS) return ret; if (is_readonly_obj) { if (get_object_sha1(path, sha1) == 0) { sd_debug("use cached sha1 digest %s", sha1_to_hex(sha1)); return SD_RES_SUCCESS; } } length = get_store_objsize(oid); buf = valloc(length); if (buf == NULL) return SD_RES_NO_MEM; iocb.epoch = epoch; iocb.buf = buf; iocb.length = length; ret = default_read_from_path(oid, path, &iocb); if (ret != SD_RES_SUCCESS) { free(buf); return ret; } get_buffer_sha1(buf, length, sha1); free(buf); sd_debug("the message digest of %"PRIx64" at epoch %d is %s", oid, epoch, sha1_to_hex(sha1)); if (is_readonly_obj) set_object_sha1(path, sha1); return ret; }
void write_all_obj() { HFINDFILE hff; char filename[256]; object *obj; int num; int index; FILE *fp; fp = fopen( object_file, "w"); if ( fp != NULL ) { hff = find_first_file(get_object_path(), filename, 256); if ( hff ) { do { if ( filename[0] != '.' && toupper(filename[0]) == 'O' && strlen(filename) == 3) { index = OFILESIZE * atoi(&filename[1]); for (num=0; num < OFILESIZE ; num++) { if (load_obj_from_file(index + num, &obj ) == 0 ) { write_object(fp, index+num,obj); free_obj(obj); } } } } while( find_next_file( hff, filename, 256 )); close_find_file(hff); } fclose(fp); } return; }
int err_to_sderr(uint64_t oid, int err) { struct stat s; switch (err) { case ENOENT: if (stat(get_object_path(oid), &s) < 0) { sd_eprintf("corrupted"); return SD_RES_EIO; } sd_dprintf("object %016" PRIx64 " not found locally", oid); return SD_RES_NO_OBJ; case ENOSPC: /* TODO: stop automatic recovery */ sd_eprintf("diskfull, oid=%"PRIx64, oid); return SD_RES_NO_SPACE; default: sd_eprintf("oid=%"PRIx64", %m", oid); return SD_RES_EIO; } }
// Tries to update all items from subscribe_map to object_map, and after this // listens for stream restore entry signals coming from entries with object paths // in object_map. // If object_map is incomplete (doesn't contain all items from subscribe_map), then // object_map_complete is FALSE. static void update_object_map_listen () { const char **obj_paths; GList *subscription_items, *i; int j = 0; if (!volume_bus || !subscribe_map || !object_map) return; g_hash_table_remove_all (object_map); obj_paths = g_malloc0 (sizeof (char*) * (g_hash_table_size (subscribe_map) + 1)); subscription_items = g_hash_table_get_values (subscribe_map); for (i = g_list_first (subscription_items); i; i = g_list_next (i)) { SubscribeItem *item = (SubscribeItem*) i->data; if (!item->object_path) item->object_path = get_object_path (item->stream_name); if (item->object_path) { g_hash_table_insert (object_map, item->object_path, item); obj_paths[j++] = item->object_path; } } obj_paths[j] = NULL; g_list_free (subscription_items); listen_for_signal (VOLUME_UPDATED_SIGNAL, obj_paths); if (g_hash_table_size (subscribe_map) == g_hash_table_size (object_map)) object_map_complete = TRUE; else object_map_complete = FALSE; g_free (obj_paths); }
extern int find_nvpair_attr_delegate(cib_t * the_cib, const char *attr, const char *section, const char *node_uuid, const char *attr_set_type, const char *set_name, const char *attr_id, const char *attr_name, gboolean to_console, char **value, const char *user_name) { int offset = 0; static int xpath_max = 1024; int rc = pcmk_ok; char *xpath_string = NULL; xmlNode *xml_search = NULL; const char *set_type = NULL; const char *node_type = NULL; if (attr_set_type) { set_type = attr_set_type; } else { set_type = XML_TAG_ATTR_SETS; } CRM_ASSERT(value != NULL); *value = NULL; if (safe_str_eq(section, XML_CIB_TAG_CRMCONFIG)) { node_uuid = NULL; set_type = XML_CIB_TAG_PROPSET; } else if (safe_str_eq(section, XML_CIB_TAG_OPCONFIG) || safe_str_eq(section, XML_CIB_TAG_RSCCONFIG)) { node_uuid = NULL; set_type = XML_TAG_META_SETS; } else if (safe_str_eq(section, XML_CIB_TAG_TICKETS)) { node_uuid = NULL; section = XML_CIB_TAG_STATUS; node_type = XML_CIB_TAG_TICKETS; } else if (node_uuid == NULL) { return -EINVAL; } xpath_string = calloc(1, xpath_max); offset += snprintf(xpath_string + offset, xpath_max - offset, "%s", get_object_path(section)); if (safe_str_eq(node_type, XML_CIB_TAG_TICKETS)) { offset += snprintf(xpath_string + offset, xpath_max - offset, "//%s", node_type); } else if (node_uuid) { const char *node_type = XML_CIB_TAG_NODE; if (safe_str_eq(section, XML_CIB_TAG_STATUS)) { node_type = XML_CIB_TAG_STATE; set_type = XML_TAG_TRANSIENT_NODEATTRS; } offset += snprintf(xpath_string + offset, xpath_max - offset, "//%s[@id='%s']", node_type, node_uuid); } if (set_name) { offset += snprintf(xpath_string + offset, xpath_max - offset, "//%s[@id='%s']", set_type, set_name); } else { offset += snprintf(xpath_string + offset, xpath_max - offset, "//%s", set_type); } offset += snprintf(xpath_string + offset, xpath_max - offset, "//nvpair["); if (attr_id) { offset += snprintf(xpath_string + offset, xpath_max - offset, "@id='%s'", attr_id); } if (attr_name) { if (attr_id) { offset += snprintf(xpath_string + offset, xpath_max - offset, " and "); } offset += snprintf(xpath_string + offset, xpath_max - offset, "@name='%s'", attr_name); } offset += snprintf(xpath_string + offset, xpath_max - offset, "]"); rc = cib_internal_op(the_cib, CIB_OP_QUERY, NULL, xpath_string, NULL, &xml_search, cib_sync_call | cib_scope_local | cib_xpath, user_name); if (rc != pcmk_ok) { crm_trace("Query failed for attribute %s (section=%s, node=%s, set=%s, xpath=%s): %s", attr_name, section, crm_str(node_uuid), crm_str(set_name), xpath_string, pcmk_strerror(rc)); goto done; } crm_log_xml_debug(xml_search, "Match"); if (xml_has_children(xml_search)) { xmlNode *child = NULL; rc = -EINVAL; attr_msg(LOG_WARNING, "Multiple attributes match name=%s", attr_name); for (child = __xml_first_child(xml_search); child != NULL; child = __xml_next(child)) { attr_msg(LOG_INFO, " Value: %s \t(id=%s)", crm_element_value(child, XML_NVPAIR_ATTR_VALUE), ID(child)); } } else { const char *tmp = crm_element_value(xml_search, attr); if (tmp) { *value = strdup(tmp); } } done: free(xpath_string); free_xml(xml_search); return rc; }
static int get_stale_obj_path(uint64_t oid, uint32_t epoch, char *path) { return snprintf(path, PATH_MAX, "%s/.stale/%016"PRIx64".%"PRIu32, get_object_path(oid), oid, epoch); }
static int get_tmp_obj_path(uint64_t oid, char *path) { return snprintf(path, PATH_MAX, "%s/%016"PRIx64".tmp", get_object_path(oid), oid); }