VMType::~VMType() { if( m_vm_pid > 0 && daemonCore ) { daemonCore->Send_Signal(m_vm_pid, SIGKILL); } m_vm_id = 0; m_vm_pid = 0; m_status = VM_STOPPED; m_cpu_time = 0; if( m_delete_working_files && !m_is_checkpointed ) { if( m_workingpath.IsEmpty() == false ) { // We will delete all files in the working directory. Directory working_dir(m_workingpath.Value(), PRIV_USER); working_dir.Remove_Entire_Directory(); } } }
QStringList EventPlugin::existingFileEventNames(const QString &_dir) const { /* QStringList ret; QDirIterator it(dir); while (it.hasNext()) { if(it.fileName().endsWith(QLatin1String(".qbe"), Qt::CaseInsensitive)) ret << it.fileName().mid(0, it.fileName().length() - 4); } return ret; */ QString dir = _dir; if(dir.isEmpty()) { ConnectionSettings connection_settings; dir = connection_settings.singleWorkingDir(); } QDir working_dir(dir); QStringList event_names = working_dir.entryList(QStringList() << ('*' + QBE_EXT), QDir::Files | QDir::Readable, QDir::Name); for (int i = 0; i < event_names.count(); ++i) { event_names[i] = fileNameToEventName(event_names[i]); } return event_names; }
inline unsigned working_dir(FixedArray<char, N>& str) { unsigned const size = working_dir(str._data, N); fixed_array::resize(str, size); return size; }
inline unsigned working_dir(char (&str)[N]) { return working_dir(str, N); }
bool VMProc::ShutdownGraceful() { dprintf(D_FULLDEBUG,"Inside VMProc::ShutdownGraceful()\n"); if( !m_vmgahp ) { return true; } if( JobPid == -1 ) { delete m_vmgahp; m_vmgahp = NULL; return true; } bool delete_working_files = true; if( m_vm_checkpoint ) { // We need to do checkpoint before vacating. // The reason we call checkpoint explicitly here // is to make sure the file uploading for checkpoint. // If file uploading failed, we will not update job classAd // such as the total count of checkpoint and last checkpoint time. m_is_vacate_ckpt = true; is_checkpointed = false; Starter->RemotePeriodicCkpt(1); // Check the success of checkpoint and file transfer if( is_checkpointed && !m_last_ckpt_result ) { // This means the checkpoint succeeded but file transfer failed. // We will not delete files in the working directory so that // file transfer will be retried delete_working_files = false; dprintf(D_ALWAYS, "Vacating checkpoint succeeded but " "file transfer failed\n"); } } // stop the running VM StopVM(); is_suspended = false; m_is_soft_suspended = false; is_checkpointed = false; requested_exit = true; // destroy vmgahp server if( m_vmgahp->cleanup() == false ) { //daemonCore->Send_Signal(JobPid, SIGKILL); daemonCore->Kill_Family(JobPid); // To make sure that the process dealing with a VM exits, killProcessForVM(); } // final cleanup.. cleanup(); // Because we already performed checkpoint, // we don't need to keep files in the working directory. // So file transfer will not be called again. if( delete_working_files ) { Directory working_dir( Starter->GetWorkingDir(), PRIV_USER ); working_dir.Remove_Entire_Directory(); } return false; // return false says shutdown is pending }
int main(int argc, char **argv) { struct tomatosaver tomatosaver; size_t control_socket_length, socket_path_length, socket_path_root_length; enum message_type msg_type; int bytes_read, control_socket; char *socket_path, *socket_path_root; socket_path = NULL; socket_path_root = NULL; if (argc != 2) { usage(argv[0]); goto error_out; } if (!strcmp("status", argv[1])) { msg_type = MSG_CTL_STATUS; } else if (!strcmp("quit", argv[1])) { msg_type = MSG_CTL_QUIT; } else { usage(argv[0]); goto error_out; } control_socket_length = strlen(TOMATOSAVER_CONTROL_SOCKET); socket_path_root = working_dir(); socket_path_root_length = strlen(socket_path_root); socket_path_length = socket_path_root_length + control_socket_length; socket_path = (char *)malloc(socket_path_length + 1); if (socket_path == NULL) { log_error("Unable to allocate enough memory to hold control " "socket path: %s\n", strerror(errno)); goto free_error_out; } memset(socket_path, 0, socket_path_length + 1); strcpy(socket_path, socket_path_root); strcat(socket_path, TOMATOSAVER_CONTROL_SOCKET); control_socket = init_control_socket(socket_path, connect); if (control_socket == -1) { goto free_error_out; } write(control_socket, &msg_type, sizeof(msg_type)); memset(&tomatosaver, 0, sizeof(tomatosaver)); bytes_read = read(control_socket, &tomatosaver, sizeof(tomatosaver)); if (bytes_read == -1) { log_error("Unable to read response from daemon: %s\n", strerror(errno)); goto close_error_out; } switch (tomatosaver.current_state) { case STATE_POMODORI: case STATE_SHORT_BREAK: case STATE_LONG_BREAK: case STATE_WAITING: log_info("Running (pid=%ld) since %s", (long)tomatosaver.process_id, ctime(&tomatosaver.started_at)); log_info("Next transition at %s", ctime(&tomatosaver.next_transition)); break; case STATE_NOT_RUNNING: log_info("Not running\n"); break; default: log_error("Unknown state\n"); goto close_error_out; } close(control_socket); free(socket_path_root); free(socket_path); return EXIT_SUCCESS; close_error_out: close(control_socket); free_error_out: if (socket_path_root != NULL) { free(socket_path_root); } if (socket_path != NULL) { free(socket_path); } error_out: exit(EXIT_FAILURE); }
int main(int argc, char** argv) { po::variables_map vm; std::string extraction_directory; std::vector<std::string> selected_plugins, selected_categories; // Load the dynamic plugins. bfs::path working_dir(argv[0]); working_dir = working_dir.parent_path(); plugin::PluginManager::get_instance().load_all(working_dir.string()); // Load the configuration config conf = parse_config((working_dir / "manalyze.conf").string()); if (!parse_args(vm, argc, argv)) { return -1; } // Get all the paths now and make them absolute before changing the working directory std::set<std::string> targets = get_input_files(vm); if (vm.count("extract")) { extraction_directory = bfs::absolute(vm["extract"].as<std::string>()).string(); } // Break complex arguments into a list once and for all. if (vm.count("plugins")) { selected_plugins = tokenize_args(vm["plugins"].as<std::vector<std::string> >()); } if (vm.count("dump")) { selected_categories = tokenize_args(vm["dump"].as<std::vector<std::string> >()); } // Instantiate the requested OutputFormatter boost::shared_ptr<io::OutputFormatter> formatter; if (vm.count("output") && vm["output"].as<std::string>() == "json") { formatter.reset(new io::JsonFormatter()); } else // Default: use the human-readable output. { formatter.reset(new io::RawFormatter()); formatter->set_header("* Manalyze " MANALYZE_VERSION " *"); } // Set the working directory to Manalyze's folder. chdir(working_dir.string().c_str()); // Do the actual analysis on all the input files unsigned int count = 0; for (auto it = targets.begin() ; it != targets.end() ; ++it) { perform_analysis(*it, vm, extraction_directory, selected_categories, selected_plugins, conf, formatter); if (++count % 1000 == 0) { formatter->format(std::cout, false); // Flush the formatter from time to time, to avoid eating up all the RAM when analyzing gigs of files. } } formatter->format(std::cout); if (vm.count("plugins")) { // Explicitly unload the plugins plugin::PluginManager::get_instance().unload_all(); } return 0; }