int load_conf_ip_hash_mmap_connect() { if (load_conf() == -1) //读取配置 return -1; if (build_dir() == -1) //创建cdn测速的待发文件目录,idc和cdn的mmap文件所在目录 return -1; if (load_ip() == -1) //读入ip库 return -1; if (load_hash() == -1) //创建hash表,用以记录mmap中每一条记录在mmap中的偏移 return -1; if (load_mmap() == -1) //创建mmap文件 return -1; if (load_linkip(link_ip_config_file) == -1) return -1; DEBUG_LOG("GET from ip:ip_ready\t:[%u]",idc_test_ip_mmap.ready_num); DEBUG_LOG("GET from area:area_ready\t:[%u]",idc_test_area_mmap.ready_num); set_hash_for_area_mmap();//从ip库中读出每一条"省市运营商"记录,写入mmap,并相应建立area的hash表 int data; backup_mmap_file(0, &data); if (connect_2_dbserver() == -1) return 0; return 0; }
static int process_file(const char *path, const char *suffix, struct selabel_handle *rec, const char *prefix) { FILE *fp; struct stat sb; unsigned int lineno; size_t line_len = 0; char *line_buf = NULL; int rc; char stack_path[PATH_MAX + 1]; /* append the path suffix if we have one */ if (suffix) { rc = snprintf(stack_path, sizeof(stack_path), "%s.%s", path, suffix); if (rc >= (int)sizeof(stack_path)) { errno = ENAMETOOLONG; return -1; } path = stack_path; } /* Open the specification file. */ if ((fp = fopen(path, "r")) == NULL) return -1; __fsetlocking(fp, FSETLOCKING_BYCALLER); if (fstat(fileno(fp), &sb) < 0) return -1; if (!S_ISREG(sb.st_mode)) { errno = EINVAL; return -1; } rc = load_mmap(rec, path, &sb); if (rc == 0) goto out; /* * Then do detailed validation of the input and fill the spec array */ lineno = 0; rc = 0; while (getline(&line_buf, &line_len, fp) > 0) { rc = process_line(rec, path, prefix, line_buf, ++lineno); if (rc) goto out; } out: free(line_buf); fclose(fp); return rc; }
static int process_file(const char *path, const char *suffix, struct selabel_handle *rec, const char *prefix, struct selabel_digest *digest) { FILE *fp; struct stat sb; unsigned int lineno; size_t line_len = 0; char *line_buf = NULL; int rc; char stack_path[PATH_MAX + 1]; bool isbinary = false; uint32_t magic; /* append the path suffix if we have one */ if (suffix) { rc = snprintf(stack_path, sizeof(stack_path), "%s.%s", path, suffix); if (rc >= (int)sizeof(stack_path)) { errno = ENAMETOOLONG; return -1; } path = stack_path; } /* Open the specification file. */ fp = fopen(path, "r"); if (fp) { __fsetlocking(fp, FSETLOCKING_BYCALLER); if (fstat(fileno(fp), &sb) < 0) return -1; if (!S_ISREG(sb.st_mode)) { errno = EINVAL; return -1; } magic = 0; if (fread(&magic, sizeof magic, 1, fp) != 1) { if (ferror(fp)) { errno = EINVAL; fclose(fp); return -1; } clearerr(fp); } if (magic == SELINUX_MAGIC_COMPILED_FCONTEXT) { /* file_contexts.bin format */ fclose(fp); fp = NULL; isbinary = true; } else { rewind(fp); } } else { /* * Text file does not exist, so clear the timestamp * so that we will always pass the timestamp comparison * with the bin file in load_mmap(). */ sb.st_mtime = 0; } rc = load_mmap(rec, path, &sb, isbinary, digest); if (rc == 0) goto out; if (!fp) return -1; /* no text or bin file */ /* * Then do detailed validation of the input and fill the spec array */ lineno = 0; rc = 0; while (getline(&line_buf, &line_len, fp) > 0) { rc = process_line(rec, path, prefix, line_buf, ++lineno); if (rc) goto out; } rc = digest_add_specfile(digest, fp, NULL, sb.st_size, path); out: free(line_buf); if (fp) fclose(fp); return rc; }