void unwatch(char *path) { // Retrieve the watch descriptor id from path LIST_NODE *node = get_from_path(path); if (node != NULL) { WD_DATA *wd_data = (WD_DATA *) node->data; // Log Message if (be_verbose || be_syslog) { char *message = malloc(sizeof(char) * MAXPATHLEN); sprintf(message, "UNWATCHING: (fd:%d,wd:%d)\t\t%s", fd, wd_data->wd, path); log_message(message); } // Remove inotify_watch and node // XXX: It's probabily that in newer kernel versions, // the call to inotify_rm_watch is called automatically // when a resource is deleted. // inotify_rm_watch is used when we want to remove explicity // a watch upon an existing watched resource. // int i = inotify_rm_watch(fd, wd_data->wd); list_remove(list_wd, node); } }
static int firmware_preparation_start(struct preparation *preparation) { int ret; struct firmware_preparation *firmware_preparation; struct firmware *firmware = NULL; char buf[0x200] = {0}; char *pbuf = &buf[0]; const char *uuid = buf + 5; const char *id = preparation->identification_string; if (ut_file_is_dir(id)) { ret = get_from_path(&firmware, id); if (ret < 0) return ret; if (firmware == NULL) firmware = firmware_new(id); return preparation->completion(preparation, &firmware->entity); } firmware_preparation = ut_container_of(preparation, struct firmware_preparation, preparation); ret = ut_process_read_from_output(&pbuf, 0x200, "\"%s\" \"%s\" " "\"%s\" \"%s\" \"%s\" \"%s\"", config_get(CONFIG_CURL_HOOK), "uuid", id, config_get(CONFIG_REPOSITORY_PATH), "", /* we don't know uuid yet, of course */ config_get(CONFIG_VERBOSE_HOOK_SCRIPTS)); if (ret < 0) { ULOGE("uuid retrieval failed"); return ret; } ut_string_rstrip(pbuf); /* * the uuid corresponds to an already registered firmware, nothing to * do and we consider it a success */ if (uuid_already_registered(uuid)) { firmware = get_from_uuid(uuid); return preparation->completion(preparation, &firmware->entity); } ret = io_process_init_prepare_and_launch(&firmware_preparation->process, &(struct io_process_parameters){ .stdout_sep_cb = preparation_progress_sep_cb, .out_sep1 = '\n', .out_sep2 = IO_SRC_SEP_NO_SEP2, .stderr_sep_cb = log_warn_src_sep_cb, .err_sep1 = '\n', .err_sep2 = IO_SRC_SEP_NO_SEP2, .timeout = PREPARATION_TIMEOUT, .signum = PREPARATION_TIMEOUT_SIGNAL, },
shared_ptr<Entity> gNMIService::get(gNMIServiceProvider& provider, Entity& filter, const string & operation) const { YLOG_DEBUG("Executing 'get' gRPC on single entity"); gnmi::Path* path = new gnmi::Path; parse_entity_to_path(filter, path); vector<gnmi::Path*> path_list; path_list.push_back(path); auto root_dn = get_from_path(provider, path_list, operation); if (root_dn) { return read_datanode(filter, root_dn->get_children()[0]); } return nullptr; }
void unwatch(char *path) { /* Retrieve the watch descriptor id from path */ LIST_NODE *node = get_from_path(path); if (node != NULL) { WD_DATA *wd_data = (WD_DATA *) node->data; /* Log Message */ if (be_verbose || be_syslog) { char *message = malloc(sizeof(char) * MAXPATHLEN); sprintf(message, "UNWATCHING: (fd:%d,wd:%d)\t\t%s", fd, wd_data->wd, path); log_message(message); } list_remove(list_wd, node); } }
vector<shared_ptr<Entity>> gNMIService::get(gNMIServiceProvider & provider, vector<Entity*> & filter_list, const string & operation) const { YLOG_DEBUG("Executing get gRPC for multiple entities"); vector<gnmi::Path*> path_list; for (auto filter : filter_list) { gnmi::Path* path = new gnmi::Path; parse_entity_to_path(*filter, path); path_list.push_back(path); } auto root_dn = get_from_path(provider, path_list, operation); vector<shared_ptr<Entity>> response_list{}; if (root_dn) { // Build map of data nodes in order to retain filter list order map<string,std::shared_ptr<path::DataNode>> path_to_dn{}; for (auto dn : root_dn->get_children()) { string path = dn->get_path(); if (path.find("/") == 0) path = path.substr(1); path_to_dn[path] = dn; } // Build output list for (auto filter : filter_list) { auto dn = path_to_dn[filter->get_segment_path()]; if (dn) { auto entity = read_datanode(*filter, dn); response_list.push_back(entity); } else { response_list.push_back((std::shared_ptr<Entity>) filter); } } } return response_list; }
void watch(char *path, bool is_link) { // Add initial path to the watch list LIST_NODE *node = get_from_path(path); if (node == NULL) node = add_to_watch_list(path); // Searchs and increments the reference counter // of the link in list_link if (is_link) add_to_link_list(node); // Temporary list to perform breath-first-search LIST *list = list_init(); list_push(list, (void *) path); // Traverse directory DIR *dir_stream; struct dirent *dir; while (list->first != NULL) { // Directory to watch char *p = (char*) list_pop(list); // Traverse directory dir_stream = opendir(p); while (dir = readdir(dir_stream)) { if (dir->d_type == DT_DIR && strcmp(dir->d_name, ".") == 1 && strcmp(dir->d_name, "..") == 1) { char *path_to_watch = (char*) malloc(sizeof(char) * (strlen(p) + strlen(dir->d_name) + 2)); strcpy(path_to_watch, p); strcat(path_to_watch, dir->d_name); strcat(path_to_watch, "/"); // Add to the watch list if (get_from_path(path_to_watch) == NULL) add_to_watch_list(path_to_watch); // Continue directory traversing list_push(list, (void*) path_to_watch); } // Resolve symbolic link else if (dir->d_type == DT_LNK) { char *path_to_watch = (char*) malloc(sizeof(char) * (strlen(p) + strlen(dir->d_name) + 1)); strcpy(path_to_watch, p); strcat(path_to_watch, dir->d_name); char *real_path = resolve_real_path(path_to_watch); // Test for: // 1. is a real path // 2. is a directory if (real_path != NULL && opendir(real_path) != NULL) { // Add to the watch list if it's not present LIST_NODE *node = get_from_path(real_path); if (node == NULL) node = add_to_watch_list(real_path); // Searchs and increments the reference counter // of the link in list_link add_to_link_list(node); // Continue directory traversing list_push(list, (void*) real_path); } } } closedir(dir_stream); } // Free memory list_free(list); }
void watch(char *path, bool is_link) { /* Add initial path to the watch list */ LIST_NODE *node = get_from_path(path); if (node == NULL) node = add_to_watch_list(path, is_link); /* Temporary list to perform breath-first-search */ LIST *list = list_init(); list_push(list, (void *) path); /* Traverse directory */ DIR *dir_stream; struct dirent *dir; while (list->first != NULL) { /* Directory to watch */ char *p = (char*) list_pop(list); /* Traverse directory */ dir_stream = opendir(p); while (dir = readdir(dir_stream)) { if (dir->d_type == DT_DIR && strcmp(dir->d_name, ".") != 0 && strcmp(dir->d_name, "..") != 0) { char *path_to_watch = (char*) malloc(sizeof(char) * (strlen(p) + strlen(dir->d_name) + 2)); strcpy(path_to_watch, p); strcat(path_to_watch, dir->d_name); strcat(path_to_watch, "/"); /* Add to the watch list with is_link = 0 because is a folder */ if (get_from_path(path_to_watch) == NULL) add_to_watch_list(path_to_watch, 0); /** * XXX: [it] prima di inserire path_to_watch * in `list` sarebbe opportuto controllare che * non sia gia' stata inserita in passato da un qualche ln * che, risolto, puntava ad essa * prima di inserire questo controllo bisogna assicurarsi che sia * effettivamente necessario per evetitare spreco di risorse. * Ad ogni modo senza, effettuerebbe cicli inutili ma non dovrebbe essere compromessa * la stabilita'. */ /* Continue directory traversing */ list_push(list, (void*) path_to_watch); } /* Resolve symbolic link */ else if (dir->d_type == DT_LNK) { char *path_to_watch = (char*) malloc(sizeof(char) * (strlen(p) + strlen(dir->d_name) + 1)); strcpy(path_to_watch, p); strcat(path_to_watch, dir->d_name); char *real_path = resolve_real_path(path_to_watch); /** * Test for: * 1. is a real path * 2. is a directory */ if (real_path != NULL && opendir(real_path) != NULL) { /** * If it's not present add to the watch list with is_link = 1, * because is pointed by a symbolic link. */ LIST_NODE *node = get_from_path(real_path); if (node == NULL) node = add_to_watch_list(real_path, 1); /** * Otherwise path_to_watch is a symbolic_link that point * to real_path, so add path_to_watch in links LIST in node->data */ WD_DATA *wd_data = (WD_DATA*) node->data; wd_data->symbolic_link = 1; list_push(wd_data->links, (char*) path_to_watch); /* Continue directory traversing */ list_push(list, (void*) real_path); } } } closedir(dir_stream); } list_free(list); }