bool spawner_new_c::init_runner() { if (!parser.get_program().length()) { if (base_initialized) { return false; } base_options = options; base_restrictions = restrictions; base_initialized = true; return true; //throw exception } runner *secure_runner_instance; options.session << order++ << time(NULL) << runner::get_current_time(); options.add_arguments(parser.get_program_arguments()); if (options.login.length()) { secure_runner_instance = new delegate_runner(parser.get_program(), options, restrictions); } else { secure_runner_instance = new secure_runner(parser.get_program(), options, restrictions); } { //if (!options.session_id.length()) { std::shared_ptr<output_pipe_c> output = std::make_shared<output_pipe_c>(); std::shared_ptr<output_pipe_c> error = std::make_shared<output_pipe_c>(); std::shared_ptr<input_pipe_c> input = std::make_shared<input_pipe_c>(); for (uint i = 0; i < options.stdoutput.size(); ++i) { std::shared_ptr<output_buffer_c> buffer = create_output_buffer(options.stdoutput[i], STD_OUTPUT_PIPE); if (buffer) { output->add_output_buffer(buffer); } } for (uint i = 0; i < options.stderror.size(); ++i) { std::shared_ptr<output_buffer_c> buffer = create_output_buffer(options.stderror[i], STD_ERROR_PIPE); if (buffer) { error->add_output_buffer(buffer); } } for (uint i = 0; i < options.stdinput.size(); ++i) { std::shared_ptr<input_buffer_c> buffer = create_input_buffer(options.stdinput[i]); if (buffer) { input->add_input_buffer(buffer); } } secure_runner_instance->set_pipe(STD_OUTPUT_PIPE, output); secure_runner_instance->set_pipe(STD_ERROR_PIPE, error); secure_runner_instance->set_pipe(STD_INPUT_PIPE, input); } runners.push_back(secure_runner_instance); return true; }
/** * The last stage output queue will be connected * to the first stage input queue (feedback channel). */ int wrap_around() { if (nodes_list.size()<2) { error("PIPE, too few pipeline nodes\n"); return -1; } fixedsize=false; // NOTE: force unbounded size for the queues! if (create_input_buffer(out_buffer_entries, fixedsize)<0) return -1; if (set_output_buffer(get_in_buffer())<0) return -1; nodes_list[0]->skip1pop = true; return 0; }
/** * It prepare the Pipeline skeleton for execution. * * \return TODO */ inline int prepare() { // create input FFBUFFER int nstages=static_cast<int>(nodes_list.size()); for(int i=1;i<nstages;++i) { if (nodes_list[i]->create_input_buffer(in_buffer_entries, fixedsize)<0) { error("PIPE, creating input buffer for node %d\n", i); return -1; } } // set output buffer for(int i=0;i<(nstages-1);++i) { if (nodes_list[i]->set_output_buffer(nodes_list[i+1]->get_in_buffer())<0) { error("PIPE, setting output buffer to node %d\n", i); return -1; } } // Preparation of buffers for the accelerator int ret = 0; if (has_input_channel) { if (create_input_buffer(in_buffer_entries, fixedsize)<0) { error("PIPE, creating input buffer for the accelerator\n"); ret=-1; } else { if (get_out_buffer()) { error("PIPE, output buffer already present for the accelerator\n"); ret=-1; } else { if (create_output_buffer(out_buffer_entries,fixedsize)<0) { error("PIPE, creating output buffer for the accelerator\n"); ret = -1; } } } } prepared=true; return ret; }
/* Pass the path to the zipfile and the name of the file within the zipfile. buf will be set to point to the uncompressed image of that zipped file. length will be set to the length of the uncompressed data. */ int /* error */ load_zipped_file (const char *zipfile, const char *filename, unsigned char **buf, int *length) { FILE *fp = NULL; t_end_of_cent_dir ecd; t_central_dir_ent cd; t_local_file_hdr lfh; unsigned char *inbuf = 0, *outbuf = 0; char filenameUpper[32], *p; int err; /* open zipfile for binary read */ if ((fp = fopen (zipfile,"rb")) != NULL) { /* determine length of zip file */ err = get_file_length (fp, &gZipLen); if (err!=0) { ERRORMSG ("Error in zipfile: get_file_length() failed\n"); goto bail; } /* read end-of-central-directory */ err = read_end_of_cent_dir (fp, &ecd); if (err!=0) { ERRORMSG ("Error reading 'end of central directory'\n"); goto bail; } /* verify that we can work with this zipfile (no disk spanning allowed) */ if ((ecd.number_of_this_disk != ecd.number_of_disk_start_cent_dir) || (ecd.total_entries_cent_dir_this_disk != ecd.total_entries_cent_dir) || (ecd.total_entries_cent_dir < 1)) { err = -1; ERRORMSG ("Unsupported zipfile: zipfile cannot span disks\n"); goto bail; } /* find matching file in central directory (force upper case) */ for (p=filenameUpper; (*p++ = toupper(*filename++)) != '\0';){}; err = find_matching_cd_entry (fp, filenameUpper, &ecd, &cd); if (err!=0) { ERRORMSG("Could not find %s in zipfile %s\n", filenameUpper, zipfile); goto bail; } /* read in local file header */ err = read_local_file_header (fp, &cd, &lfh); if (err!=0) { ERRORMSG ("Error reading 'local file header'\n"); goto bail; } /* extract file based on compression method */ if (lfh.compression_method == 0x0000) { /* file is not compressed, simply stored -- copy directly to output buffer */ err = create_input_buffer (fp, &cd, &lfh, &outbuf); if (err!=0) ERRORMSG ("Couldn't extract uncompressed file\n"); } else if (lfh.compression_method == 0x0008) { /* file is compressed using "Deflate" method */ /* create input and output buffers */ err = create_input_buffer (fp, &cd, &lfh, &inbuf); if (err==0) { g_nextbyte = inbuf; outbuf = malloc (lfh.uncompressed_size); if (outbuf!=0) g_outbuf = outbuf; else { ERRORMSG ("Couldn't allocate %d bytes for output buffer\n", lfh.uncompressed_size); err = -1; } } else { ERRORMSG ("Could not create input buffer\n"); } /* create sliding window for inflate() */ if (err==0) { slide = malloc (0x8000); if (slide==0) { ERRORMSG ("Could not create 32K sliding window\n"); err = -1; } } /* inflate the compressed file (now in memory) */ if (err==0) { err = zip_inflate (); if (err!=0) { ERRORMSG ("Error inflating compressed file: %d", err); } } } /* return pointer to uncompressed data */ if (err==0) { *buf = outbuf; *length = lfh.uncompressed_size; outbuf = 0; /* prevent data from being freed() */ } } else { ERRORMSG ("Could not open zipfile %s\n", zipfile); err = -1; } bail: if (fp) fclose (fp); if (inbuf) free (inbuf); if (outbuf) free (outbuf); if (slide) { free (slide); slide = 0; } return err; }