static int do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc ) { int rc = 0; int n, i; IOBUF a = iobuf_temp(); write_version( a, ctb ); if ( enc->throw_keyid ) { write_32(a, 0 ); /* Don't tell Eve who can decrypt the message. */ write_32(a, 0 ); } else { write_32(a, enc->keyid[0] ); write_32(a, enc->keyid[1] ); } iobuf_put(a,enc->pubkey_algo ); n = pubkey_get_nenc( enc->pubkey_algo ); if ( !n ) write_fake_data( a, enc->data[0] ); for (i=0; i < n && !rc ; i++ ) rc = mpi_write(a, enc->data[i] ); if (!rc) { write_header(out, ctb, iobuf_get_temp_length(a) ); rc = iobuf_write_temp( out, a ); } iobuf_close(a); return rc; }
int main(int argc, char *argv[]) { program_name = os_GetBasename(argv[0]); logger_set_level(-1, LOG_WARNING); if (argc < 1) die("not enough parameters"); if (argc == 2) { if (!strcmp(argv[1], "--help")) { write_help(); } else if (!strcmp(argv[1], "--version")) { write_version(); } } #if defined EJUDGE_XML_PATH if (!ejudge_xml_path) ejudge_xml_path = EJUDGE_XML_PATH; #endif /* EJUDGE_XML_PATH */ if (!ejudge_xml_path) die("ejudge.xml path is not specified"); if (!(ejudge_config = ejudge_cfg_parse(ejudge_xml_path, 1))) return 1; if (!ejudge_config->contests_dir) die("<contests_dir> tag is not set!"); if (contests_set_directory(ejudge_config->contests_dir) < 0) die("contests directory is invalid"); load_mysql_plugin(); /* consult the main compilation configuration */ compile_cfg_path[0] = 0; if (ejudge_config->compile_home_dir) { snprintf(compile_cfg_path, sizeof(compile_cfg_path), "%s/conf/compile.cfg", ejudge_config->compile_home_dir); } if (!compile_cfg_path[0] && ejudge_config->contests_home_dir) { snprintf(compile_cfg_path, sizeof(compile_cfg_path), "%s/compile/conf/compile.cfg", ejudge_config->contests_home_dir); } #if defined EJUDGE_CONTESTS_HOME_DIR if (!compile_cfg_path[0]) { snprintf(compile_cfg_path, sizeof(compile_cfg_path), "%s/compile/conf/compile.cfg", EJUDGE_CONTESTS_HOME_DIR); } #endif cs_config = prepare_parse_config_file(compile_cfg_path, 0); if (!cs_config) { die("failed to parse compilation configuration file %s", compile_cfg_path); } handle_cs_config(); process_all_contests(); return 0; }
static void *logwriter_thread(void *arg) { /* set name */ prctl(PR_SET_NAME, "sdlog2_writer", 0); int log_fd = open_log_file(); if (log_fd < 0) { return NULL; } struct logbuffer_s *logbuf = (struct logbuffer_s *)arg; /* write log messages formats, version and parameters */ log_bytes_written += write_formats(log_fd); log_bytes_written += write_version(log_fd); log_bytes_written += write_parameters(log_fd); fsync(log_fd); int poll_count = 0; void *read_ptr; int n = 0; bool should_wait = false; bool is_part = false; while (true) { /* make sure threads are synchronized */ pthread_mutex_lock(&logbuffer_mutex); /* update read pointer if needed */ if (n > 0) { logbuffer_mark_read(&lb, n); } /* only wait if no data is available to process */ if (should_wait && !logwriter_should_exit) { /* blocking wait for new data at this line */ pthread_cond_wait(&logbuffer_cond, &logbuffer_mutex); } /* only get pointer to thread-safe data, do heavy I/O a few lines down */ int available = logbuffer_get_ptr(logbuf, &read_ptr, &is_part); /* continue */ pthread_mutex_unlock(&logbuffer_mutex); if (available > 0) { /* do heavy IO here */ if (available > MAX_WRITE_CHUNK) { n = MAX_WRITE_CHUNK; } else { n = available; } n = write(log_fd, read_ptr, n); should_wait = (n == available) && !is_part; if (n < 0) { main_thread_should_exit = true; err(1, "error writing log file"); } if (n > 0) { log_bytes_written += n; } } else { n = 0; /* exit only with empty buffer */ if (main_thread_should_exit || logwriter_should_exit) { break; } should_wait = true; } if (++poll_count == 10) { fsync(log_fd); poll_count = 0; } } fsync(log_fd); close(log_fd); return NULL; }
int main(int argc, char **argv) { struct rsa_session ctx; struct rsa_session_info info; struct rsa_public_key key; mpz_t x; int c; const char *random_name = NULL; enum { OPT_HELP = 300 }; static const struct option options[] = { /* Name, args, flag, val */ { "help", no_argument, NULL, OPT_HELP }, { "random", required_argument, NULL, 'r' }, { NULL, 0, NULL, 0} }; while ( (c = getopt_long(argc, argv, "o:r:", options, NULL)) != -1) switch (c) { case 'r': random_name = optarg; break; case '?': return EXIT_FAILURE; case OPT_HELP: usage(stdout); return EXIT_SUCCESS; default: abort(); } argv += optind; argc -= optind; if (argc != 1) { usage (stderr); return EXIT_FAILURE; } rsa_public_key_init(&key); if (!read_rsa_key(argv[0], &key, NULL)) { werror("Invalid key\n"); return EXIT_FAILURE; } /* NOTE: No sources */ yarrow256_init(&ctx.yarrow, 0, NULL); /* Read some data to seed the generator */ if (!simple_random(&ctx.yarrow, random_name)) { werror("Initialization of randomness generator failed.\n"); return EXIT_FAILURE; } WRITE_UINT32(SESSION_VERSION(&info), RSA_VERSION); yarrow256_random(&ctx.yarrow, sizeof(info.key) - 4, info.key + 4); rsa_session_set_encrypt_key(&ctx, &info); #ifdef WIN32 _setmode(0, O_BINARY); _setmode(1, O_BINARY); #endif write_version(stdout); mpz_init(x); if (!rsa_encrypt(&key, &ctx.yarrow, (nettle_random_func *) yarrow256_random, sizeof(info.key), info.key, x)) { werror("RSA encryption failed.\n"); return EXIT_FAILURE; } write_bignum(stdout, x); mpz_clear (x); if (!process_file(&ctx, stdin, stdout)) return EXIT_FAILURE; rsa_public_key_clear(&key); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int i = 1, r = 0; const char *command = 0; const char *ejudge_xml_path = 0; struct ejudge_cfg *config = 0; int cmd = 0; int super_serve_fd = -1; int signum = 0; const unsigned char *signame = ""; int pid; program_name = os_GetBasename(argv[0]); if (argc < 2) startup_error("not enough parameters"); if (!strcmp(argv[i], "--help")) { write_help(); } else if (!strcmp(argv[i], "--version")) { write_version(); } command = argv[i]; i++; if (i < argc) { ejudge_xml_path = argv[i]; i++; } if (i < argc) startup_error("too many parameters"); #if defined EJUDGE_XML_PATH if (!ejudge_xml_path) ejudge_xml_path = EJUDGE_XML_PATH; #endif /* EJUDGE_XML_PATH */ if (!ejudge_xml_path) startup_error("ejudge.xml path is not specified"); if (!(config = ejudge_cfg_parse(ejudge_xml_path))) return 1; if (!strcmp(command, "stop")) { cmd = SSERV_CMD_STOP; signum = START_STOP; signame = "TERM"; } else if (!strcmp(command, "restart")) { cmd = SSERV_CMD_RESTART; signum = START_RESTART; signame = "HUP"; } else { startup_error("invalid command"); } (void) signame; (void) signum; if (!(pid = start_find_process("ej-super-server", 0))) { op_error("ej-super-server is not running"); } else if (pid > 0) { /* fprintf(stderr, "%s: ej-super-server is running as pid %d\n", program_name, pid); fprintf(stderr, "%s: sending it the %s signal\n", program_name, signame); if (start_kill(pid, signum) < 0) op_error("failed: %s", os_ErrorMsg()); return 0; */ } if ((super_serve_fd = super_clnt_open(config->super_serve_socket)) < 0) op_error("ej-super-server is not running"); r = super_clnt_control(super_serve_fd, cmd); if (r < 0) op_error("%s", super_proto_strerror(-r)); return 0; }
int main(int argc, char *argv[]) { int i; BOOL verbose = TRUE; BOOL very_verbose = TRUE; F64 start_time = 0.0; F64 full_start_time = 0.0; const CHAR* xml_output_file = 0; BOOL one_report_per_file = FALSE; U32 num_pass = 0; U32 num_fail = 0; U32 num_warning = 0; fprintf(stderr, "This is version '%s' of the LAS validator. Please contact\n", "GRiD-1"); fprintf(stderr, "me at '*****@*****.**' if you disagree with\n"); fprintf(stderr, "validation reports, want additional checks, or find bugs as\n"); fprintf(stderr, "the software is still under development. Your feedback will\n"); fprintf(stderr, "help to finish it sooner.\n"); LASreadOpener lasreadopener; if (argc == 1) { fprintf(stderr,"lasvalidate.exe is best run with arguments in the command line\n"); char file_name[256]; fprintf(stderr,"enter input LAS file name: "); fgets(file_name, 256, stdin); file_name[strlen(file_name)-1] = '\0'; lasreadopener.set_file_name(file_name); fprintf(stderr,"enter output XML file name: "); fgets(file_name, 256, stdin); file_name[strlen(file_name)-1] = '\0'; xml_output_file = strdup(file_name); } for (i = 1; i < argc; i++) { if (strcmp(argv[i],"-version") == 0) { fprintf(stderr, "\nlasvalidate %d with LASread (v %d.%d %d) and LAScheck (v %d.%d %d) by rapidlasso GmbH\n", VALIDATE_VERSION, LASREAD_VERSION_MAJOR, LASREAD_VERSION_MINOR, LASREAD_BUILD_DATE, LASCHECK_VERSION_MAJOR, LASCHECK_VERSION_MINOR, LASCHECK_BUILD_DATE); byebye(LAS_VALIDATE_SUCCESS); } else if (strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"-help") == 0) { lasreadopener.usage(); usage(LAS_VALIDATE_SUCCESS); } else if (strcmp(argv[i],"-v") == 0 || strcmp(argv[i],"-verbose") == 0) { verbose = TRUE; } else if (strcmp(argv[i],"-vv") == 0 || strcmp(argv[i],"-very_verbose") == 0) { verbose = TRUE; very_verbose = TRUE; } else if (strcmp(argv[i],"-i") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs at least 1 argument: file_name or wild_card\n", argv[i]); usage(LAS_VALIDATE_WRONG_COMMAND_LINE_SYNTAX); } i+=1; do { lasreadopener.add_file_name(argv[i]); i+=1; } while (i < argc && *argv[i] != '-'); i-=1; } else if (strcmp(argv[i],"-irec") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs at least 1 argument: directory_name\n", argv[i]); usage(LAS_VALIDATE_WRONG_COMMAND_LINE_SYNTAX); } i+=1; do { lasreadopener.add_directory(argv[i], TRUE); i+=1; } while (i < argc && *argv[i] != '-'); i-=1; } else if (strcmp(argv[i],"-stdin") == 0) { lasreadopener.set_piped(TRUE); } else if (strcmp(argv[i],"-lof") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: list_of_files\n", argv[i]); usage(LAS_VALIDATE_WRONG_COMMAND_LINE_SYNTAX); } FILE* file = fopen(argv[i+1], "r"); if (file == 0) { fprintf(stderr, "ERROR: cannot open '%s'\n", argv[i+1]); return FALSE; } char line[1024]; while (fgets(line, 1024, file)) { // find end of line int len = strlen(line) - 1; // remove extra white spaces and line return at the end while (len > 0 && ((line[len] == '\n') || (line[len] == ' ') || (line[len] == '\t') || (line[len] == '\012'))) { line[len] = '\0'; len--; } lasreadopener.add_file_name(line); } fclose(file); i+=1; } else if (strcmp(argv[i],"-o") == 0) { i++; xml_output_file = argv[i]; } else if (strcmp(argv[i],"-oxml") == 0) { one_report_per_file = TRUE; } else { fprintf(stderr, "ERROR: cannot understand argument '%s'\n", argv[i]); usage(LAS_VALIDATE_WRONG_COMMAND_LINE_SYNTAX); } } // in verbose mode we measure the total time if (verbose) full_start_time = taketime(); // check input if (!lasreadopener.is_active()) { fprintf(stderr,"ERROR: no input specified\n"); byebye(LAS_VALIDATE_NO_INPUT_SPECIFIED, argc == 1); } // output logging XMLwriter xmlwriter; if (lasreadopener.is_active()) { if (xml_output_file) { one_report_per_file = FALSE; } else if (!one_report_per_file) { xml_output_file = "validate.xml"; } } // maybe we are doing one summary report if (xml_output_file) { if (!xmlwriter.open(xml_output_file, "LASvalidator")) { byebye(LAS_VALIDATE_WRITE_PERMISSION_ERROR, argc == 1); } } // accumulated pass U32 total_pass = VALIDATE_PASS; // possibly loop over multiple input files while (lasreadopener.is_active()) { // in very verbose mode we measure the time for each file if (very_verbose) start_time = taketime(); // open lasreader LASreader* lasreader = lasreadopener.open(); if (lasreader == 0) { fprintf(stderr, "ERROR: could not open lasreader\n"); byebye(LAS_VALIDATE_INPUT_FILE_NOT_FOUND, argc == 1); } // get a pointer to the header LASheader* lasheader = &lasreader->header; // maybe we are doing one report per file if (one_report_per_file) { int len = strlen(lasreadopener.get_path()); CHAR* current_xml_output_file = (CHAR*)malloc(len + 5); strcpy(current_xml_output_file, lasreadopener.get_path()); current_xml_output_file[len-4] = '_'; current_xml_output_file[len-3] = 'L'; current_xml_output_file[len-2] = 'V'; current_xml_output_file[len-1] = 'S'; current_xml_output_file[len ] = '.'; current_xml_output_file[len+1] = 'x'; current_xml_output_file[len+2] = 'm'; current_xml_output_file[len+3] = 'l'; current_xml_output_file[len+4] = '\0'; if (!xmlwriter.open(current_xml_output_file, "LASvalidator")) { byebye(LAS_VALIDATE_WRITE_PERMISSION_ERROR, argc == 1); } free(current_xml_output_file); } // start a new report xmlwriter.begin("report"); // report description of file xmlwriter.beginsub("file"); xmlwriter.write("name", lasreadopener.get_file_name()); xmlwriter.write("path", lasreadopener.get_path()); CHAR temp[32]; sprintf(temp, "%d.%d", lasheader->version_major, lasheader->version_minor); xmlwriter.write("version", temp); strncpy(temp, lasheader->system_identifier, 32); temp[31] = '\0'; xmlwriter.write("system_identifier", temp); strncpy(temp, lasheader->generating_software, 32); temp[31] = '\0'; xmlwriter.write("generating_software", temp); xmlwriter.write("point_data_format", lasheader->point_data_format); CHAR crsdescription[512]; strcpy(crsdescription, "not valid or not specified"); if (lasheader->fails == 0) { // header was loaded. now parse and check. LAScheck lascheck(lasheader); while (lasreader->read_point()) { lascheck.parse(&lasreader->point); } // check header and points and get CRS description lascheck.check(lasheader, crsdescription); } xmlwriter.write("CRS", crsdescription); xmlwriter.endsub("file"); // report the verdict U32 pass = (lasheader->fails ? VALIDATE_FAIL : VALIDATE_PASS); if (lasheader->warnings) pass |= VALIDATE_WARNING; xmlwriter.beginsub("summary"); xmlwriter.write((pass == VALIDATE_PASS ? "pass" : ((pass & VALIDATE_FAIL) ? "fail" : "warning"))); xmlwriter.endsub("summary"); // report details (if necessary) if (pass != VALIDATE_PASS) { xmlwriter.beginsub("details"); for (i = 0; i < lasheader->fail_num; i+=2) { xmlwriter.write(lasheader->fails[i], "fail", lasheader->fails[i+1]); } for (i = 0; i < lasheader->warning_num; i+=2) { xmlwriter.write(lasheader->warnings[i], "warning", lasheader->warnings[i+1]); } xmlwriter.endsub("details"); total_pass |= pass; if (pass & VALIDATE_FAIL) { num_fail++; } else { num_warning++; } } else { num_pass++; } // end the report xmlwriter.end("report"); // maybe we are doing one report per file if (one_report_per_file) { // report the total verdict xmlwriter.begin("total"); xmlwriter.write((total_pass == VALIDATE_PASS ? "pass" : ((total_pass & VALIDATE_FAIL) ? "fail" : "warning"))); xmlwriter.beginsub("details"); xmlwriter.write("pass", num_pass); xmlwriter.write("warning", num_warning); xmlwriter.write("fail", num_fail); xmlwriter.endsub("details"); xmlwriter.end("total"); num_pass = 0; num_warning = 0; num_fail = 0; // write which validator was used write_version(xmlwriter); // write which command line was used write_command_line(xmlwriter, argc, argv); // close the LASvalidator XML output file xmlwriter.close("LASvalidator"); } lasreader->close(); delete lasreader; // in very verbose mode we report the time for each file if (very_verbose) { fprintf(stderr,"needed %.2f sec for '%s'\n", taketime()-start_time, lasreadopener.get_file_name()); start_time = taketime(); } } // maybe we are doing one summary report if (!one_report_per_file) { // report the total verdict xmlwriter.begin("total"); xmlwriter.write((total_pass == 0 ? "pass" : ((total_pass & 1) ? "fail" : "warning"))); xmlwriter.beginsub("details"); xmlwriter.write("pass", num_pass); xmlwriter.write("warning", num_warning); xmlwriter.write("fail", num_fail); xmlwriter.endsub("details"); xmlwriter.end("total"); // write which validator was used write_version(xmlwriter); // write which command line was used write_command_line(xmlwriter, argc, argv); // close the LASvalidator XML output file xmlwriter.close("LASvalidator"); } // in verbose mode we report the total time if (verbose && (lasreadopener.get_file_name_number() > 1)) { fprintf(stderr,"done. total time %.2f sec.\n", taketime()-full_start_time); } byebye(argc==1); return 0; }
int main(int argc, char **argv) { int i, n_valid, do_write, do_scrub; char *c, *dname, *name; DIR *dir; FILE *fp; pdf_t *pdf; pdf_flag_t flags; if (argc < 2) usage(); /* Args */ do_write = do_scrub = flags = 0; name = NULL; for (i=1; i<argc; i++) { if (strncmp(argv[i], "-w", 2) == 0) do_write = 1; else if (strncmp(argv[i], "-i", 2) == 0) flags |= PDF_FLAG_DISP_CREATOR; else if (strncmp(argv[i], "-q", 2) == 0) flags |= PDF_FLAG_QUIET; else if (strncmp(argv[i], "-s", 2) == 0) do_scrub = 1; else if (argv[i][0] != '-') name = argv[i]; else if (argv[i][0] == '-') usage(); } if (!name) usage(); if (!(fp = fopen(name, "r"))) { ERR("Could not open file '%s'\n", argv[1]); return -1; } else if (!pdf_is_pdf(fp)) { ERR("'%s' specified is not a valid PDF\n", name); fclose(fp); return -1; } /* Load PDF */ if (!(pdf = init_pdf(fp, name))) { fclose(fp); return -1; } /* Count valid xrefs */ for (i=0, n_valid=0; i<pdf->n_xrefs; i++) if (pdf->xrefs[i].version) ++n_valid; /* Bail if we only have 1 valid */ if (n_valid < 2) { if (!(flags & (PDF_FLAG_QUIET | PDF_FLAG_DISP_CREATOR))) printf("%s: There is only one version of this PDF\n", pdf->name); if (do_write) { fclose(fp); pdf_delete(pdf); return 0; } } dname = NULL; if (do_write) { /* Create directory to place the various versions in */ if ((c = strrchr(name, '/'))) name = c + 1; if ((c = strrchr(name, '.'))) *c = '\0'; dname = malloc(strlen(name) + 16); sprintf(dname, "%s-versions", name); if (!(dir = opendir(dname))) mkdir(dname, S_IRWXU); else { ERR("This directory already exists, PDF version extraction will " "not occur\n"); fclose(fp); closedir(dir); free(dname); pdf_delete(pdf); return -1; } /* Write the pdf as a pervious version */ for (i=0; i<pdf->n_xrefs; i++) if (pdf->xrefs[i].version) write_version(fp, name, dname, &pdf->xrefs[i]); } /* Generate a per-object summary */ pdf_summarize(fp, pdf, dname, flags); /* Have we been summoned to scrub history from this PDF */ if (do_scrub) scrub_document(fp, pdf); /* Display extra information */ if (flags & PDF_FLAG_DISP_CREATOR) display_creator(fp, pdf); fclose(fp); free(dname); pdf_delete(pdf); return 0; }
static void run_linker_config_smoke_test(bool is_asan) { const std::vector<std::string> kExpectedDefaultSearchPath = resolve_paths(is_asan ? std::vector<std::string>({ "/data", "/vendor/lib" ARCH_SUFFIX }) : std::vector<std::string>({ "/vendor/lib" ARCH_SUFFIX })); const std::vector<std::string> kExpectedDefaultPermittedPath = resolve_paths(is_asan ? std::vector<std::string>({ "/data", "/vendor" }) : std::vector<std::string>({ "/vendor/lib" ARCH_SUFFIX })); const std::vector<std::string> kExpectedSystemSearchPath = resolve_paths(is_asan ? std::vector<std::string>({ "/data", "/system/lib" ARCH_SUFFIX }) : std::vector<std::string>({ "/system/lib" ARCH_SUFFIX })); const std::vector<std::string> kExpectedSystemPermittedPath = resolve_paths(is_asan ? std::vector<std::string>({ "/data", "/system" }) : std::vector<std::string>({ "/system/lib" ARCH_SUFFIX })); const std::vector<std::string> kExpectedVndkSearchPath = resolve_paths(is_asan ? std::vector<std::string>({ "/data", "/system/lib" ARCH_SUFFIX "/vndk"}) : std::vector<std::string>({ "/system/lib" ARCH_SUFFIX "/vndk"})); TemporaryFile tmp_file; close(tmp_file.fd); tmp_file.fd = -1; android::base::WriteStringToFile(config_str, tmp_file.path); TemporaryDir tmp_dir; std::string executable_path = std::string(tmp_dir.path) + "/some-binary"; std::string version_file = std::string(tmp_dir.path) + "/.version"; auto file_guard = android::base::make_scope_guard([&version_file] { unlink(version_file.c_str()); }); ASSERT_TRUE(write_version(version_file, 113U)) << strerror(errno); // read config const Config* config = nullptr; std::string error_msg; ASSERT_TRUE(Config::read_binary_config(tmp_file.path, executable_path.c_str(), is_asan, &config, &error_msg)) << error_msg; ASSERT_TRUE(config != nullptr); ASSERT_TRUE(error_msg.empty()); ASSERT_EQ(113U, config->target_sdk_version()); const NamespaceConfig* default_ns_config = config->default_namespace_config(); ASSERT_TRUE(default_ns_config != nullptr); ASSERT_TRUE(default_ns_config->isolated()); ASSERT_FALSE(default_ns_config->visible()); ASSERT_EQ(kExpectedDefaultSearchPath, default_ns_config->search_paths()); ASSERT_EQ(kExpectedDefaultPermittedPath, default_ns_config->permitted_paths()); const auto& default_ns_links = default_ns_config->links(); ASSERT_EQ(2U, default_ns_links.size()); ASSERT_EQ("system", default_ns_links[0].ns_name()); ASSERT_EQ("libc.so:libm.so:libdl.so:libstdc++.so", default_ns_links[0].shared_libs()); ASSERT_FALSE(default_ns_links[0].allow_all_shared_libs()); ASSERT_EQ("vndk", default_ns_links[1].ns_name()); ASSERT_EQ("libcutils.so:libbase.so", default_ns_links[1].shared_libs()); ASSERT_FALSE(default_ns_links[1].allow_all_shared_libs()); auto& ns_configs = config->namespace_configs(); ASSERT_EQ(3U, ns_configs.size()); // find second namespace const NamespaceConfig* ns_system = nullptr; const NamespaceConfig* ns_vndk = nullptr; for (auto& ns : ns_configs) { std::string ns_name = ns->name(); ASSERT_TRUE(ns_name == "system" || ns_name == "default" || ns_name == "vndk") << "unexpected ns name: " << ns->name(); if (ns_name == "system") { ns_system = ns.get(); } else if (ns_name == "vndk") { ns_vndk = ns.get(); } } ASSERT_TRUE(ns_system != nullptr) << "system namespace was not found"; ASSERT_TRUE(ns_system->isolated()); ASSERT_TRUE(ns_system->visible()); ASSERT_EQ(kExpectedSystemSearchPath, ns_system->search_paths()); ASSERT_EQ(kExpectedSystemPermittedPath, ns_system->permitted_paths()); ASSERT_TRUE(ns_vndk != nullptr) << "vndk namespace was not found"; ASSERT_FALSE(ns_vndk->isolated()); // malformed bool property ASSERT_FALSE(ns_vndk->visible()); // undefined bool property ASSERT_EQ(kExpectedVndkSearchPath, ns_vndk->search_paths()); const auto& ns_vndk_links = ns_vndk->links(); ASSERT_EQ(1U, ns_vndk_links.size()); ASSERT_EQ("default", ns_vndk_links[0].ns_name()); ASSERT_TRUE(ns_vndk_links[0].allow_all_shared_libs()); }
void initialize() { time_t now = time(NULL); srand(now); startup_ts = now; if (init_log() == -1) { fprintf(stderr, "Failed to initialzie log module.\n"); exit(EXIT_FAILURE); } int ver = read_version(); if (ver < VERSION) { log_info("Previous version %d, current version %d", ver, VERSION); // this is a version update! if (need_to_delete_redis_db) { log_info("Deleting redis DB due to version update."); delete_redis_db(); } } else log_info("Current version: %d", VERSION); write_version(VERSION); start_redis_server(); if (init_socket() == -1) { log_error("Failed to initialize socket module."); exit(EXIT_FAILURE); } log_debug("Adding iptables rules."); if (add_iptables_rules() == -1) { log_error("Failed to add iptables rules."); exit(EXIT_FAILURE); } register_signal_handlers(); if (setup_nfq() == -1) { log_error("unable to setup netfilter_queue"); exit(EXIT_FAILURE); } log_debug("Init DNS client."); if (init_dns_cli() == -1) { log_error("Failed to initialize DNS module"); exit(EXIT_FAILURE); } log_debug("Init ev watchers."); init_ev_watchers(); // Begin to intercept packets //if (setup_strategy() == -1) { // log_error("Failed to setup strategy"); // exit(EXIT_FAILURE); //} log_debug("Loading TTL from file."); load_ttl_from_file("ttl"); // start a debug thread //pthread_t thread_dbg; //if (pthread_create(&thread_dbg, NULL, debug_main, NULL) != 0) { // log_error("Fail to create debug thread."); // exit(EXIT_FAILURE); //} // start a thread to handle communications with redis pthread_t thread_cache; if (pthread_create(&thread_cache, NULL, cache_main, NULL) != 0){ log_error("Fail to create caching thread."); exit(EXIT_FAILURE); } // start the DNS proxy thread pthread_t thread_dns; if (pthread_create(&thread_dns, NULL, dns_main, NULL) != 0){ log_error("Fail to create DNS thread."); exit(EXIT_FAILURE); } // Uploading diagnostic log is disabled. (2017.4.26) // start a thread to send feedback log //pthread_t thread_fb; //if (pthread_create(&thread_fb, NULL, feedback_main, NULL) != 0){ // log_error("Fail to create feedback thread."); // exit(EXIT_FAILURE); //} }
int main(int argc, char *argv[]) { int i = 1; char *eptr = 0; int total_clars, clar_id; struct clar_entry_v2 clar; unsigned char *text = 0; size_t size = 0; program_name = os_GetBasename(argv[0]); if (argc <= 1) die("not enough parameters"); if (!strcmp(argv[1], "--help")) { write_help(); } else if (!strcmp(argv[1], "--version")) { write_version(); } i = 1; while (i < argc) { if (!strcmp(argv[i], "-f")) { if (i + 1 >= argc) die("argument expected for `-f'"); ejudge_xml_path = argv[i + 1]; i += 2; } else if (!strcmp(argv[i], "--")) { i++; break; } else if (argv[i][0] == '-') { die("invalid option `%s'", argv[i]); } else { break; } } #if defined EJUDGE_XML_PATH if (!ejudge_xml_path) ejudge_xml_path = EJUDGE_XML_PATH; #endif /* EJUDGE_XML_PATH */ if (!ejudge_xml_path) die("ejudge.xml path is not specified"); if (!(config = ejudge_cfg_parse(ejudge_xml_path))) return 1; if (!config->contests_dir) die("<contests_dir> tag is not set!"); if (contests_set_directory(config->contests_dir) < 0) die("contests directory is invalid"); if (i >= argc) die("contest-id is expected"); if (!argv[i][0]) die("contest-id is not specified"); errno = 0; contest_id = strtol(argv[i], &eptr, 10); if (*eptr || errno || contest_id <= 0 || contest_id > EJ_MAX_CONTEST_ID) die("contest-id is invalid"); i++; if (i >= argc) die("source plugin name is expected"); src_plugin_name = argv[i]; i++; if (i >= argc) die("destination plugin name is expected"); dst_plugin_name = argv[i]; i++; if (i < argc) die("extra parameters"); if (!src_plugin_name || !*src_plugin_name) src_plugin_name = "file"; if (!dst_plugin_name || !*dst_plugin_name) dst_plugin_name = "file"; if (!strcmp(src_plugin_name, dst_plugin_name)) die("plugins are the same"); if (contests_get(contest_id, &cnts) < 0 || !cnts) die("cannot load contest %d", contest_id); if (!(src_clarlog = clar_init())) die("cannot open the source clarlog"); if (!(dst_clarlog = clar_init())) die("cannot open the destination clarlog"); if (clar_open(src_clarlog, config, cnts, 0, src_plugin_name, 0) < 0) die("cannot open the source clarlog"); if (clar_open(dst_clarlog, config, cnts, 0, dst_plugin_name, 0) < 0) die("cannot open the destination clarlog"); total_clars = clar_get_total(src_clarlog); for (clar_id = 0; clar_id < total_clars; clar_id++) { if (clar_get_record(src_clarlog, clar_id, &clar) < 0) continue; if (clar.id < 0) continue; if (!ej_uuid_is_nonempty(clar.uuid)) { ej_uuid_generate(&clar.uuid); } clar_put_record(dst_clarlog, clar_id, &clar); if (clar_get_raw_text(src_clarlog, clar_id, &text, &size) < 0) continue; clar_add_text(dst_clarlog, clar_id, &clar.uuid, text, size); xfree(text); text = 0; size = 0; } return 0; }