int build_graph(const char *depfile, struct node_list **headp) { FILE *f; int err; unsigned int nnodes = 0; struct trie nodes; trie_init(&nodes); f = fopen(depfile, "r"); if (!f) { perror("failed to open dependency file"); return -1; } err = read_depfile(f, &nodes, &nnodes); fclose(f); if (err) { trie_free(&nodes); return -1; } err = trie_iter(&nodes, add_to_list_from_trie, headp); if (err) { free_node_list(*headp); nnodes = -1; } trie_free(&nodes); return nnodes; }
void hashtable_free(void) { unsigned int i; for (i = 0; i < HASHTABLE_SIZE; i++) { hash_node *root = hashtable[i]; if (root != NULL) { free_node_list(root); } } }
void node_info_unref (NodeInfo *info) { info->base.refcount -= 1; if (info->base.refcount == 0) { free_interface_list (&info->interfaces); free_node_list (&info->nodes); base_info_free (info); } }
void run_test() { total = 0; node* head = new_node(42); append_node(head, new_node(24)); append_node(head, new_node(89)); append_node(head, new_node(11)); walk_nodes(total_nodes, head); free_node_list(head); if (total == 166) { printf("passed\n"); } else { printf("expected total = 166, got %d\n", total); } }
struct node_list *init_node_list(struct daemon *daemon, struct config *cfg) { struct node_list *node_list; struct server_config *server_cfg; struct node *node; int idx; node_list = create_node_list(cfg->server_num); if (!node_list) { log_error("failed to create %d server nodes", cfg->server_num); return NULL; } node_list->ping = cfg->ping; node_list->pingtimeout = cfg->pingtimeout; for (idx = 0; idx < cfg->server_num; idx++) { server_cfg = &cfg->servers[idx]; node = make_node(server_cfg->id, "server", server_cfg->localipaddr, server_cfg->remoteipaddr, server_cfg->localport, server_cfg->remoteport); if (!node) { log_error("failed to create node %d", server_cfg->id); goto err; } node_set_daemon(node, daemon); node_set_share_node_bits(node, cfg); node_list_put(node_list, node); } node_list_set_local(node_list); if (node_list->local_node_id < 0) { log_error("can not find local node ip"); goto err; } return node_list; err: free_node_list(node_list); return NULL; }
static int add_fan_nodes_and_props(picl_nodehdl_t plath) { int err; char *pname, *nodename, *devfs_path; env_fan_t *fanp; fan_node_t *fnodep; picl_nodehdl_t nodeh, cnodeh; picl_prophdl_t proph; node_list_t *node_list, *listp; node_list = get_node_list_by_class(plath, PICL_CLASS_FAN_CONTROL, NULL); if (node_list == NULL) return (PICL_FAILURE); for (listp = node_list; listp != NULL; listp = listp->next) { /* * Add various fan nodes and properties */ nodeh = listp->nodeh; err = PICL_SUCCESS; for (fnodep = fan_nodes; fnodep->fan_name != NULL; fnodep++) { /* Skip if already initialized or no fan info */ if (fnodep->nodeh != NULL || fnodep->fanp == NULL) continue; /* * Create "fan" class node and save node handle */ nodename = fnodep->fan_name; err = ptree_create_and_add_node(nodeh, nodename, PICL_CLASS_FAN, &cnodeh); if (env_debug) envd_log(LOG_INFO, "Creating PICL fan node '%s' err:%d\n", nodename, err); if (err != PICL_SUCCESS) break; fnodep->nodeh = cnodeh; /* * Add "devfs_path" property in child node */ fanp = fnodep->fanp; devfs_path = fanp->devfs_path; pname = PICL_PROP_DEVFS_PATH; err = add_regular_prop(cnodeh, pname, PICL_PTYPE_CHARSTRING, PICL_READ, strlen(devfs_path)+1, (void *)devfs_path, &proph); if (err != PICL_SUCCESS) break; /* * Add "Speed" volatile property in this "fan" * class node and save prop handle. */ pname = PROP_FAN_SPEED; err = add_volatile_prop(cnodeh, pname, PICL_PTYPE_INT, PICL_READ, sizeof (fanspeed_t), get_current_speed, NULL, &proph); if (err != PICL_SUCCESS) break; fnodep->proph = proph; /* * Add other "fan" class properties */ pname = PROP_FAN_SPEED_UNIT, err = add_regular_prop(cnodeh, pname, PICL_PTYPE_CHARSTRING, PICL_READ, strlen(fnodep->speed_unit)+1, (void *)fnodep->speed_unit, &proph); if (err != PICL_SUCCESS) break; } if (err != PICL_SUCCESS) { delete_fan_nodes_and_props(); free_node_list(node_list); if (env_debug) envd_log(LOG_WARNING, "Can't create prop/node for fan '%s'\n", nodename); return (err); } } free_node_list(node_list); return (PICL_SUCCESS); }
static int add_sensor_nodes_and_props(picl_nodehdl_t plath) { int err; char *pname, *nodename, *refnode, *devfs_path; node_list_t *node_list, *listp; sensor_node_t *snodep; sensor_thresh_t *threshp; picl_nodehdl_t nodeh, refnodeh, cnodeh; picl_prophdl_t proph; char unitaddr[UNITADDR_LEN_MAX]; env_sensor_t *sensorp; node_list = get_node_list_by_class(plath, PICL_CLASS_TEMP_DEVICE, NULL); if (node_list == NULL) return (PICL_FAILURE); for (listp = node_list; listp != NULL; listp = listp->next) { /* * Get "reg" property. Skip if no "reg" property found. */ nodeh = listp->nodeh; err = get_unit_address_prop(nodeh, (void *)unitaddr, sizeof (unitaddr)); if (err != PICL_SUCCESS) continue; for (snodep = sensor_nodes; snodep->sensor_name != NULL; snodep++) { /* Match "UnitAddress" property */ if (strcasecmp(unitaddr, snodep->unitaddr) != 0) continue; /* * Skip if already initialized or no sensor info */ sensorp = snodep->sensorp; if (snodep->nodeh != NULL || sensorp == NULL) continue; /* * Create temperature-sensor node */ nodename = snodep->sensor_name; err = ptree_create_and_add_node(nodeh, nodename, PICL_CLASS_TEMP_SENSOR, &cnodeh); if (env_debug) envd_log(LOG_INFO, "Creating PICL sensor node '%s' err:%d\n", nodename, err); if (err != PICL_SUCCESS) break; /* save node handle */ snodep->nodeh = cnodeh; /* * Add "devfs_path" property in child node */ devfs_path = sensorp->devfs_path; pname = PICL_PROP_DEVFS_PATH; err = add_regular_prop(cnodeh, pname, PICL_PTYPE_CHARSTRING, PICL_READ, strlen(devfs_path)+1, (void *)devfs_path, &proph); if (err != PICL_SUCCESS) break; /* * Now add volatile "temperature" volatile property * in this "temperature-sensor" class node. */ pname = PROP_TEMPERATURE; err = add_volatile_prop(cnodeh, pname, PICL_PTYPE_INT, PICL_READ, sizeof (tempr_t), get_current_temp, NULL, &proph); if (err != PICL_SUCCESS) break; /* Save prop handle */ snodep->proph = proph; /* * Add threshold related properties */ threshp = sensorp->temp_thresh; if (threshp != NULL) add_sensor_thresh_props(cnodeh, threshp); /* * Finally create property in the sensed device * (if one specified) */ refnode = snodep->sdev_node; pname = snodep->sdev_pname; if (refnode == NULL || pname == NULL) continue; err = ptree_get_node_by_path(refnode, &refnodeh); if (err == PICL_SUCCESS) { err = add_volatile_prop(refnodeh, pname, PICL_PTYPE_INT, PICL_READ, sizeof (tempr_t), get_current_temp, NULL, &proph); } if (err != PICL_SUCCESS) break; /* Save prop handle */ snodep->sdev_proph = proph; } if (err != PICL_SUCCESS) { delete_sensor_nodes_and_props(); free_node_list(node_list); if (env_debug) envd_log(LOG_INFO, "Can't create prop/node for sensor '%s'\n", nodename); return (err); } } free_node_list(node_list); return (PICL_SUCCESS); }