Beispiel #1
0
int
main () {
	init_states ();
	init_dsm ();
	init_runner ();
	delete_runner ();
	delete_dsm ();
}
Beispiel #2
0
int main(int argc, char ** argv) {
  FILE * in;
  if (argc > 1) {
    in = fopen(argv[1], "r");
    if (in == NULL) {
      perror("fopen");
      exit(1);
    }
  }
  else {
    in = stdin;
  }
  
  runner * run = init_runner();
  if (read_file_into_memory(run, in) == -1) {
    exit(1);
  }

  int ret = execute(run);
  printf("\n\n>> ret is %d\n", ret);
}
Beispiel #3
0
bool spawner_new_c::init() {
    if (!init_runner() || !runners.size()) {
        return false;
    }
    for (size_t i = 0; i < runners.size(); i++) {
        if (runners[i]->get_options().controller) {
            // there must be only one controller process
            PANIC_IF(controller_index_ != -1);
            controller_index_ = i;
            control_mode_enabled = true;
            controller_input_lock = multipipe::create_pipe(write_mode, true, 0);
            controller_input_lock->get_pipe()->close();
            // Lock controller stdin
            controller_input_lock->connect(runners[i]->get_pipe(std_stream_input));
            controller_input_ = runners[i]->get_pipe(std_stream_input)->get_pipe();
            controller_output_ = runners[i]->get_pipe(std_stream_output);
        }
    }
    if (controller_index_ != -1) {
        awaited_agents_.resize(runners.size() - 1);
        for (size_t i = 0; i < runners.size(); i++) {
            secure_runner* sr = static_cast<secure_runner*>(runners[i]);
            sr->start_suspended = true;
            if (i != controller_index_) {
                sr->on_terminate = [=]() {
                    LOG("runner", i, "terminated");
                    on_terminate_mutex_.lock();
                    wait_agent_mutex_.lock();
                    awaited_agents_[i - 1] = false;
                    std::string message = std::to_string(i) + "T#\n";
                    // Send message to controller only.
                    controller_input_->write(message.c_str(), message.size());
                    bool have_running_agents = false;
                    for (auto j = 0; j < runners.size(); j++) {
                        if (j != controller_index_ && j != i && runners[j]->is_running()) {
                            have_running_agents = true;
                            break;
                        }
                    }
                    if (!have_running_agents) {
                        // Unlock controller stdin
                        controller_input_lock->finalize();
                    }
                    wait_agent_mutex_.unlock();
                    on_terminate_mutex_.unlock();
                };
            } else {
                sr->on_terminate = [=]() {
                    LOG("controller terminated");
                    for (size_t j = 0; j < runners.size(); j++) {
                        if (j != controller_index_) {
                            runners[j]->resume();
                        }
                    }
                };
            }
        }
    }

    for (auto runner : runners) {
        options_class runner_options = runner->get_options();
        const struct {
            std::vector<options_class::redirect> &streams;
            std_stream_type type;
        } redirects_all[] = {
            { runner_options.stdinput, std_stream_input },
            { runner_options.stdoutput, std_stream_output },
            { runner_options.stderror, std_stream_error },
        };
        for (const auto& redirects : redirects_all) {
            for (const auto& redirect : redirects.streams) {
                PANIC_IF(redirect.original.size() == 0);
                if (redirect.type == options_class::file) {
                    continue;
                }
                setup_stream_(redirect, redirects.type, runner);
            }
        }
    }
    return true;
}
Beispiel #4
0
void spawner_new_c::on_separator(const std::string &_) {
    init_runner();
    parser.clear_program_parser();
    options = options_class(base_options);
    restrictions = restrictions_class(base_restrictions);
}
Beispiel #5
0
bool spawner_new_c::init() {
    if (!init_runner() || !runners.size()) {
        return false;
    }
    for (size_t i = 0; i < runners.size(); i++) {
        if (runners[i]->get_options().controller) {
            // there must be only one controller process
            PANIC_IF(controller_index_ != -1);
            controller_index_ = i;
            control_mode_enabled = true;
            controller_buffer_ = std::make_shared<pipe_buffer_c>(runners[i]->get_input_pipe());
        }
    }
    if (controller_index_ != -1) {
        awaited_normals_.resize(runners.size() - 1);
        for (size_t i = 0; i < runners.size(); i++) {
            secure_runner* sr = static_cast<secure_runner*>(runners[i]);
            if (i != controller_index_) {
                sr->start_suspended = true;
            }
            sr->on_terminate = [=]() {
                on_terminate_mutex_.lock();
                for (auto& r : runners) {
                    if (r == sr) {
                        continue;
                    }
                    for (auto& b : sr->duplex_buffers) {
                        for (int pi = STD_INPUT_PIPE; pi <= STD_ERROR_PIPE; pi++) {
                            auto&& p = r->get_pipe(static_cast<const pipes_t>(pi));
                            p->remove_buffer(b);
                        }
                    }
                }

                if (i > 0 && awaited_normals_[i - 1]) {
                    wait_normal_mutex_.lock();
                    awaited_normals_[i - 1] = false;
                    std::string message = std::to_string(i) + "I#\n";
                    controller_buffer_->write(message.c_str(), message.size());
                    wait_normal_mutex_.unlock();
                }
                on_terminate_mutex_.unlock();
            };
        }
    }

    for (auto& runner : runners) {
        options_class runner_options = runner->get_options();
        struct {
            std::vector<std::string> &streams;
            pipes_t pipe_type;
        } streams[] = {
            { runner_options.stdinput, STD_INPUT_PIPE },
            { runner_options.stdoutput, STD_OUTPUT_PIPE },
            { runner_options.stderror, STD_ERROR_PIPE },
        };
        for (auto& stream_item : streams) {
            for (auto& stream_str : stream_item.streams) {
                PANIC_IF(stream_str.size() == 0);
                if (stream_str[0] != '*') {
                    continue;
                }
                setup_stream_(stream_str, stream_item.pipe_type, runner);
            }
        }
    }
    return true;
}