2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
// Abstraction of a set of executing applications,
|
|
|
|
// connected to I/O files in various ways.
|
|
|
|
// Shouldn't depend on CLIENT_STATE.
|
|
|
|
|
2002-06-06 18:42:01 +00:00
|
|
|
#include "windows_cpp.h"
|
2002-07-11 01:09:53 +00:00
|
|
|
#include "error_numbers.h"
|
2002-06-06 18:42:01 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2002-06-20 23:46:51 +00:00
|
|
|
#include <io.h>
|
2002-10-06 00:43:54 +00:00
|
|
|
#include <afxwin.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_UNISTD_H
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <unistd.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_WAIT_H
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <sys/wait.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_TIME_H
|
2002-05-22 15:52:26 +00:00
|
|
|
#include <sys/time.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_RESOURCE_H
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <sys/resource.h>
|
2002-06-06 18:42:01 +00:00
|
|
|
#endif
|
2002-07-05 19:20:00 +00:00
|
|
|
#if HAVE_SYS_TYPES_H
|
2002-06-06 18:42:01 +00:00
|
|
|
#include <sys/types.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_SIGNAL_H
|
2002-07-01 18:16:31 +00:00
|
|
|
#include <sys/signal.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_FCNTL_H
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <fcntl.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_SIGNAL_H
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <signal.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
2002-07-15 23:21:20 +00:00
|
|
|
|
|
|
|
#include <ctype.h>
|
2002-06-06 18:42:01 +00:00
|
|
|
#include <time.h>
|
2002-06-20 23:46:51 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "client_state.h"
|
2002-07-15 23:21:20 +00:00
|
|
|
#include "client_types.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "filesys.h"
|
|
|
|
#include "file_names.h"
|
|
|
|
#include "log_flags.h"
|
|
|
|
#include "parse.h"
|
2002-07-22 23:07:14 +00:00
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "app.h"
|
2002-08-05 00:29:34 +00:00
|
|
|
#include "boinc_api.h"
|
2002-09-11 21:41:42 +00:00
|
|
|
#include "graphics_api.h"
|
2002-07-31 19:05:15 +00:00
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Goes through an array of strings, and prints each string
|
|
|
|
//
|
|
|
|
static int print_argv(char** argv) {
|
2002-04-30 22:22:54 +00:00
|
|
|
int i;
|
2002-07-15 23:21:20 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; argv[i]; i++) {
|
2002-06-21 06:52:47 +00:00
|
|
|
fprintf(stderr, "argv[%d]: %s\n", i, argv[i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-07-15 23:21:20 +00:00
|
|
|
|
|
|
|
return 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ACTIVE_TASK::ACTIVE_TASK() {
|
|
|
|
result = NULL;
|
|
|
|
wup = NULL;
|
|
|
|
app_version = NULL;
|
2002-07-15 23:21:20 +00:00
|
|
|
pid = 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
slot = 0;
|
2002-07-15 23:21:20 +00:00
|
|
|
state = PROCESS_UNINITIALIZED;
|
2002-04-30 22:22:54 +00:00
|
|
|
exit_status = 0;
|
|
|
|
signal = 0;
|
2002-08-24 00:41:25 +00:00
|
|
|
strcpy(slot_dir, "");
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ACTIVE_TASK::init(RESULT* rp) {
|
|
|
|
result = rp;
|
|
|
|
wup = rp->wup;
|
|
|
|
app_version = wup->avp;
|
2002-07-15 23:21:20 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Start a task in a slot directory. This includes setting up soft links,
|
2002-08-05 00:29:34 +00:00
|
|
|
// passing preferences, and starting the process
|
|
|
|
//
|
2002-08-20 00:30:13 +00:00
|
|
|
// Current dir is top-level BOINC dir
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int ACTIVE_TASK::start(bool first_time) {
|
2002-08-24 00:41:25 +00:00
|
|
|
char exec_name[256], file_path[256], link_path[256], temp[256], exec_path[256];
|
2002-04-30 22:22:54 +00:00
|
|
|
unsigned int i;
|
2002-05-17 22:33:57 +00:00
|
|
|
FILE_REF file_ref;
|
|
|
|
FILE_INFO* fip;
|
2002-10-24 08:25:42 +00:00
|
|
|
int retval;
|
2002-09-11 21:41:42 +00:00
|
|
|
char init_data_path[256], graphics_data_path[256], fd_init_path[256];
|
2002-08-24 00:41:25 +00:00
|
|
|
FILE *f;
|
2002-08-05 00:29:34 +00:00
|
|
|
APP_INIT_DATA aid;
|
2002-09-17 21:54:59 +00:00
|
|
|
GRAPHICS_INFO gi;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
|
|
|
if (first_time) {
|
|
|
|
checkpoint_cpu_time = 0;
|
|
|
|
}
|
|
|
|
current_cpu_time = checkpoint_cpu_time;
|
|
|
|
starting_cpu_time = checkpoint_cpu_time;
|
|
|
|
fraction_done = 0;
|
|
|
|
|
2002-11-18 21:20:54 +00:00
|
|
|
gi.xsize = 800;
|
|
|
|
gi.ysize = 600;
|
2002-09-17 21:54:59 +00:00
|
|
|
gi.graphics_mode = MODE_WINDOW;
|
2002-09-11 21:41:42 +00:00
|
|
|
gi.refresh_period = 0.1;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
|
|
|
memset(&aid, 0, sizeof(aid));
|
2002-08-22 20:19:18 +00:00
|
|
|
|
2002-08-05 00:29:34 +00:00
|
|
|
// TODO: fill in the app prefs, user name, team name, etc.
|
|
|
|
aid.checkpoint_period = DEFAULT_CHECKPOINT_PERIOD;
|
|
|
|
aid.fraction_done_update_period = DEFAULT_FRACTION_DONE_UPDATE_PERIOD;
|
|
|
|
aid.wu_cpu_time = checkpoint_cpu_time;
|
|
|
|
|
2002-08-24 00:41:25 +00:00
|
|
|
sprintf(init_data_path, "%s%s%s", slot_dir, PATH_SEPARATOR, INIT_DATA_FILE);
|
|
|
|
f = fopen(init_data_path, "w");
|
|
|
|
if (!f) {
|
2002-08-05 00:29:34 +00:00
|
|
|
if (log_flags.task_debug) {
|
2002-08-24 00:41:25 +00:00
|
|
|
printf("Failed to open core to app prefs file %s.\n", init_data_path);
|
2002-06-10 22:59:15 +00:00
|
|
|
}
|
2002-07-15 23:21:20 +00:00
|
|
|
return ERR_FOPEN;
|
2002-06-10 22:59:15 +00:00
|
|
|
}
|
2002-08-24 00:41:25 +00:00
|
|
|
retval = write_init_data_file(f, aid);
|
|
|
|
fclose(f);
|
2002-06-08 00:55:25 +00:00
|
|
|
|
2002-09-11 21:41:42 +00:00
|
|
|
sprintf(graphics_data_path, "%s%s%s", slot_dir, PATH_SEPARATOR, GRAPHICS_DATA_FILE);
|
|
|
|
f = fopen(graphics_data_path, "w");
|
|
|
|
if (!f) {
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
printf("Failed to open core to app graphics prefs file %s.\n", graphics_data_path);
|
|
|
|
}
|
|
|
|
return ERR_FOPEN;
|
|
|
|
}
|
2002-09-17 21:54:59 +00:00
|
|
|
retval = write_graphics_file(f, &gi);
|
2002-09-11 21:41:42 +00:00
|
|
|
fclose(f);
|
|
|
|
|
2002-08-24 00:41:25 +00:00
|
|
|
sprintf(fd_init_path, "%s%s%s", slot_dir, PATH_SEPARATOR, FD_INIT_FILE);
|
|
|
|
f = fopen(fd_init_path, "w");
|
|
|
|
if (!f) {
|
2002-08-05 00:29:34 +00:00
|
|
|
if(log_flags.task_debug) {
|
2002-08-24 00:41:25 +00:00
|
|
|
printf("Failed to open init file %s.\n", fd_init_path);
|
2002-06-20 23:46:51 +00:00
|
|
|
}
|
2002-07-15 23:21:20 +00:00
|
|
|
return ERR_FOPEN;
|
2002-06-20 23:46:51 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-08-05 00:29:34 +00:00
|
|
|
// make soft links to the executable(s)
|
2002-06-20 23:46:51 +00:00
|
|
|
//
|
|
|
|
for (i=0; i<app_version->app_files.size(); i++) {
|
|
|
|
fip = app_version->app_files[i].file_info;
|
|
|
|
get_pathname(fip, file_path);
|
|
|
|
if (i == 0) {
|
|
|
|
strcpy(exec_name, fip->name);
|
2002-08-24 00:41:25 +00:00
|
|
|
strcpy(exec_path, file_path);
|
2002-06-20 23:46:51 +00:00
|
|
|
}
|
|
|
|
if (first_time) {
|
2002-09-25 18:33:26 +00:00
|
|
|
sprintf(link_path, "%s%s%s", slot_dir, PATH_SEPARATOR, fip->name);
|
|
|
|
sprintf(temp, "..%s..%s%s", PATH_SEPARATOR, PATH_SEPARATOR, file_path );
|
2002-06-20 23:46:51 +00:00
|
|
|
retval = boinc_link( temp, link_path);
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
printf("link %s to %s\n", file_path, link_path);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-06-20 23:46:51 +00:00
|
|
|
if (retval) {
|
|
|
|
perror("link");
|
2002-08-24 00:41:25 +00:00
|
|
|
fclose(f);
|
2002-06-20 23:46:51 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// create symbolic links, and hook up descriptors, for input files
|
|
|
|
//
|
|
|
|
for (i=0; i<wup->input_files.size(); i++) {
|
|
|
|
file_ref = wup->input_files[i];
|
|
|
|
get_pathname(file_ref.file_info, file_path);
|
|
|
|
if (strlen(file_ref.open_name)) {
|
2002-05-17 22:33:57 +00:00
|
|
|
if (first_time) {
|
2002-09-25 18:33:26 +00:00
|
|
|
sprintf(link_path, "%s%s%s", slot_dir, PATH_SEPARATOR, file_ref.open_name);
|
|
|
|
sprintf(temp, "..%s..%s%s", PATH_SEPARATOR, PATH_SEPARATOR, file_path );
|
2002-05-17 22:33:57 +00:00
|
|
|
if (log_flags.task_debug) {
|
|
|
|
printf("link %s to %s\n", file_path, link_path);
|
|
|
|
}
|
2002-08-24 00:41:25 +00:00
|
|
|
retval = boinc_link(temp, link_path);
|
2002-05-17 22:33:57 +00:00
|
|
|
if (retval) {
|
|
|
|
perror("link");
|
2002-08-24 00:41:25 +00:00
|
|
|
fclose(f);
|
2002-06-20 23:46:51 +00:00
|
|
|
return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-20 23:46:51 +00:00
|
|
|
} else {
|
2002-09-25 18:33:26 +00:00
|
|
|
sprintf(temp, "..%s..%s%s", PATH_SEPARATOR, PATH_SEPARATOR, file_path);
|
2002-08-24 00:41:25 +00:00
|
|
|
write_fd_init_file(f, temp, file_ref.fd, 1);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-06-20 23:46:51 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// hook up the output files using BOINC soft links
|
2002-06-20 23:46:51 +00:00
|
|
|
//
|
|
|
|
for (i=0; i<result->output_files.size(); i++) {
|
|
|
|
file_ref = result->output_files[i];
|
|
|
|
get_pathname(file_ref.file_info, file_path);
|
|
|
|
if (strlen(file_ref.open_name)) {
|
|
|
|
if (first_time) {
|
2002-10-24 08:25:42 +00:00
|
|
|
// the following is a relic of using hard links. not needed
|
|
|
|
//int fd = creat(file_path, 0660);
|
|
|
|
//close(fd);
|
2002-09-25 18:33:26 +00:00
|
|
|
sprintf(link_path, "%s%s%s", slot_dir, PATH_SEPARATOR, file_ref.open_name);
|
|
|
|
sprintf(temp, "..%s..%s%s", PATH_SEPARATOR, PATH_SEPARATOR, file_path );
|
2002-06-20 23:46:51 +00:00
|
|
|
if (log_flags.task_debug) {
|
|
|
|
printf("link %s to %s\n", file_path, link_path);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-08-24 00:41:25 +00:00
|
|
|
retval = boinc_link(temp, link_path);
|
2002-06-20 23:46:51 +00:00
|
|
|
if (retval) {
|
2002-08-24 00:41:25 +00:00
|
|
|
fclose(f);
|
2002-06-20 23:46:51 +00:00
|
|
|
perror("link");
|
|
|
|
return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-20 23:46:51 +00:00
|
|
|
} else {
|
2002-09-25 18:33:26 +00:00
|
|
|
sprintf(temp, "..%s..%s%s", PATH_SEPARATOR, PATH_SEPARATOR, file_path);
|
2002-08-24 00:41:25 +00:00
|
|
|
write_fd_init_file(f, temp, file_ref.fd, 0);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-06-20 23:46:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-24 00:41:25 +00:00
|
|
|
fclose(f);
|
2002-06-20 23:46:51 +00:00
|
|
|
|
2002-11-20 20:14:48 +00:00
|
|
|
sprintf(temp, "%s%s%s", slot_dir, PATH_SEPARATOR, SUSPEND_QUIT_FILE);
|
|
|
|
file_delete(temp);
|
|
|
|
|
2002-07-03 22:37:24 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2002-08-12 00:51:42 +00:00
|
|
|
char* argv[100];
|
2002-06-20 23:46:51 +00:00
|
|
|
pid = fork();
|
|
|
|
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.
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// chdir() into the slot directory
|
|
|
|
//
|
2002-08-24 00:41:25 +00:00
|
|
|
retval = chdir(slot_dir);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
|
|
|
perror("chdir");
|
|
|
|
exit(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
// hook up stderr to a specially-named file
|
|
|
|
//
|
|
|
|
freopen(STDERR_FILE, "a", stderr);
|
|
|
|
|
|
|
|
argv[0] = exec_name;
|
|
|
|
parse_command_line(wup->command_line, argv+1);
|
|
|
|
if (log_flags.task_debug) print_argv(argv);
|
2002-09-22 23:27:14 +00:00
|
|
|
boinc_resolve_filename(exec_name, temp, sizeof(temp));
|
2002-06-20 23:46:51 +00:00
|
|
|
retval = execv(temp, argv);
|
2002-04-30 22:22:54 +00:00
|
|
|
fprintf(stderr, "execv failed: %d\n", retval);
|
|
|
|
perror("execv");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (log_flags.task_debug) printf("forked process: pid %d\n", pid);
|
|
|
|
#endif
|
2002-07-03 22:37:24 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2002-07-05 05:43:57 +00:00
|
|
|
PROCESS_INFORMATION process_info;
|
|
|
|
STARTUPINFO startup_info;
|
2002-08-24 00:41:25 +00:00
|
|
|
char slotdirpath[256];
|
2002-11-19 00:28:33 +00:00
|
|
|
char cmd_line[512];
|
2002-06-20 23:46:51 +00:00
|
|
|
|
2002-07-05 05:43:57 +00:00
|
|
|
memset( &process_info, 0, sizeof( process_info ) );
|
|
|
|
memset( &startup_info, 0, sizeof( startup_info ) );
|
|
|
|
startup_info.cb = sizeof(startup_info);
|
|
|
|
startup_info.lpReserved = NULL;
|
|
|
|
startup_info.lpDesktop = "";
|
2002-06-20 23:46:51 +00:00
|
|
|
|
2002-08-22 20:19:18 +00:00
|
|
|
// NOTE: in Windows, stderr is redirected within boinc_init();
|
2002-06-20 23:46:51 +00:00
|
|
|
|
2002-11-19 00:28:33 +00:00
|
|
|
sprintf( cmd_line, "%s %s", exec_path, wup->command_line );
|
2002-06-20 23:46:51 +00:00
|
|
|
// Need to condense argv into a single string
|
|
|
|
//if (log_flags.task_debug) print_argv(argv);
|
2002-08-05 00:29:34 +00:00
|
|
|
//
|
2002-08-24 00:41:25 +00:00
|
|
|
full_path(slot_dir, slotdirpath);
|
2002-08-22 20:19:18 +00:00
|
|
|
if (!CreateProcess(exec_path,
|
2002-10-24 17:06:42 +00:00
|
|
|
cmd_line,
|
2002-08-22 20:19:18 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-06-20 23:46:51 +00:00
|
|
|
FALSE,
|
2002-11-05 21:16:00 +00:00
|
|
|
CREATE_NEW_PROCESS_GROUP|CREATE_NO_WINDOW|IDLE_PRIORITY_CLASS,
|
2002-06-20 23:46:51 +00:00
|
|
|
NULL,
|
2002-08-24 00:41:25 +00:00
|
|
|
slotdirpath,
|
2002-06-20 23:46:51 +00:00
|
|
|
&startup_info,
|
2002-08-22 20:19:18 +00:00
|
|
|
&process_info
|
|
|
|
)) {
|
2002-07-05 05:43:57 +00:00
|
|
|
state = GetLastError();
|
2002-11-19 00:28:33 +00:00
|
|
|
char *errorargs[] = {app_version->app_name,"","","",""};
|
|
|
|
LPVOID lpMsgBuf;
|
|
|
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, state, 0, (LPTSTR)&lpMsgBuf, 0, errorargs);
|
|
|
|
|
|
|
|
// check for an error; if there is one, set error information for the currect result
|
|
|
|
if(state) {
|
|
|
|
gstate.report_project_error(*result, state, (LPTSTR)&lpMsgBuf);
|
|
|
|
LocalFree(lpMsgBuf);
|
|
|
|
return -1;
|
|
|
|
}
|
2002-10-26 08:02:13 +00:00
|
|
|
fprintf(stdout, "CreateProcess: %s\n", (LPCTSTR)lpMsgBuf);
|
2002-11-19 00:28:33 +00:00
|
|
|
LocalFree(lpMsgBuf);
|
2002-07-05 05:43:57 +00:00
|
|
|
}
|
|
|
|
pid_handle = process_info.hProcess;
|
2002-11-19 00:28:33 +00:00
|
|
|
thread_handle = process_info.hThread;
|
2002-06-20 23:46:51 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
state = PROCESS_RUNNING;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Sends a request to the process of this active task to exit. If it
|
2002-11-18 21:20:54 +00:00
|
|
|
// doesn't exit within a set time (seconds), the process is terminated
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2002-07-01 18:16:31 +00:00
|
|
|
void ACTIVE_TASK::request_exit(int seconds) {
|
|
|
|
int retval;
|
2002-11-19 00:28:33 +00:00
|
|
|
char susp_file[256];
|
2002-07-11 01:09:53 +00:00
|
|
|
if(seconds<0) {
|
|
|
|
fprintf(stderr, "error: ACTIVE_TASK.request_exit: negative seconds\n");
|
|
|
|
seconds=0;
|
|
|
|
}
|
2002-11-19 00:28:33 +00:00
|
|
|
|
|
|
|
get_slot_dir(slot, slot_dir);
|
|
|
|
sprintf( susp_file, "%s%s%s", slot_dir, PATH_SEPARATOR, SUSPEND_QUIT_FILE );
|
|
|
|
FILE *fp = fopen( susp_file, "w" );
|
|
|
|
write_suspend_quit_file( fp, false, true );
|
|
|
|
fclose(fp);
|
|
|
|
|
2002-11-19 22:57:05 +00:00
|
|
|
// We shouldn't sleep the full amount if the process successfully quits
|
2002-11-19 00:28:33 +00:00
|
|
|
boinc_sleep(seconds);
|
2002-07-05 19:20:00 +00:00
|
|
|
#if HAVE_SIGNAL_H
|
|
|
|
#if HAVE_SYS_TYPES_H
|
2002-07-11 01:09:53 +00:00
|
|
|
while(retval) retval=kill(pid, SIGKILL);
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
2002-07-11 01:09:53 +00:00
|
|
|
while(retval) retval=TerminateProcess(pid_handle, -1);
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
2002-07-01 18:16:31 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Inserts an active task into the ACTIVE_TASK_SET and starts it up
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int ACTIVE_TASK_SET::insert(ACTIVE_TASK* atp) {
|
|
|
|
int retval;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2002-08-24 00:41:25 +00:00
|
|
|
get_slot_dir(atp->slot, atp->slot_dir);
|
|
|
|
clean_out_dir(atp->slot_dir);
|
2002-04-30 22:22:54 +00:00
|
|
|
retval = atp->start(true);
|
|
|
|
if (retval) return retval;
|
|
|
|
active_tasks.push_back(atp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Checks if any child processes have exited and records their final CPU time
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
|
|
|
bool ACTIVE_TASK_SET::poll() {
|
2002-08-22 22:28:51 +00:00
|
|
|
ACTIVE_TASK* atp;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-06-06 18:42:01 +00:00
|
|
|
#ifdef _WIN32
|
2002-07-05 05:43:57 +00:00
|
|
|
unsigned long exit_code;
|
|
|
|
int i;
|
|
|
|
FILETIME creation_time, exit_time, kernel_time, user_time;
|
|
|
|
ULARGE_INTEGER tKernel, tUser;
|
|
|
|
LONGLONG totTime;
|
2002-08-22 22:28:51 +00:00
|
|
|
bool found = false;
|
2002-06-06 18:42:01 +00:00
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2002-08-05 00:29:34 +00:00
|
|
|
if (GetExitCodeProcess(atp->pid_handle, &exit_code)) {
|
2002-07-05 05:43:57 +00:00
|
|
|
// Get the elapsed CPU time
|
2002-08-05 00:29:34 +00:00
|
|
|
if (GetProcessTimes(atp->pid_handle, &creation_time, &exit_time, &kernel_time, &user_time)) {
|
2002-07-05 05:43:57 +00:00
|
|
|
tKernel.LowPart = kernel_time.dwLowDateTime;
|
|
|
|
tKernel.HighPart = kernel_time.dwHighDateTime;
|
|
|
|
tUser.LowPart = user_time.dwLowDateTime;
|
|
|
|
tUser.HighPart = user_time.dwHighDateTime;
|
2002-08-24 00:41:25 +00:00
|
|
|
|
2002-07-05 05:43:57 +00:00
|
|
|
// Runtimes in 100-nanosecond units
|
|
|
|
totTime = tKernel.QuadPart + tUser.QuadPart;
|
|
|
|
}
|
2002-11-20 22:57:43 +00:00
|
|
|
atp->result->final_cpu_time = atp->checkpoint_cpu_time;
|
2002-08-05 00:29:34 +00:00
|
|
|
if (exit_code != STILL_ACTIVE) {
|
2002-08-24 00:41:25 +00:00
|
|
|
found = true;
|
2002-07-05 05:43:57 +00:00
|
|
|
atp->state = PROCESS_EXITED;
|
|
|
|
atp->exit_status = exit_code;
|
|
|
|
atp->result->exit_status = atp->exit_status;
|
2002-12-05 21:56:33 +00:00
|
|
|
atp->result->active_task_state = PROCESS_EXITED;
|
2002-11-19 00:28:33 +00:00
|
|
|
CloseHandle(atp->pid_handle);
|
|
|
|
CloseHandle(atp->thread_handle);
|
2002-11-22 00:13:47 +00:00
|
|
|
atp->read_stderr_file();
|
|
|
|
clean_out_dir(atp->slot_dir);
|
2002-07-05 05:43:57 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-06 18:42:01 +00:00
|
|
|
}
|
2002-06-20 23:46:51 +00:00
|
|
|
|
2002-11-22 00:13:47 +00:00
|
|
|
return found;
|
2002-12-05 19:13:06 +00:00
|
|
|
#else
|
2002-06-06 18:42:01 +00:00
|
|
|
|
|
|
|
struct rusage rs;
|
|
|
|
int pid;
|
2002-08-09 23:16:37 +00:00
|
|
|
int stat;
|
2002-06-06 18:42:01 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
pid = wait3(&stat, WNOHANG, &rs);
|
|
|
|
if (pid <= 0) return false;
|
|
|
|
if (log_flags.task_debug) printf("got signal for process %d\n", pid);
|
|
|
|
atp = lookup_pid(pid);
|
|
|
|
if (!atp) {
|
|
|
|
fprintf(stderr, "ACTIVE_TASK_SET::poll(): pid %d not found\n", pid);
|
|
|
|
return true;
|
|
|
|
}
|
2002-08-05 00:29:34 +00:00
|
|
|
double x = rs.ru_utime.tv_sec + rs.ru_utime.tv_usec/1.e6;
|
|
|
|
atp->result->final_cpu_time = atp->starting_cpu_time + x;
|
2002-04-30 22:22:54 +00:00
|
|
|
if (WIFEXITED(stat)) {
|
|
|
|
atp->state = PROCESS_EXITED;
|
|
|
|
atp->exit_status = WEXITSTATUS(stat);
|
|
|
|
atp->result->exit_status = atp->exit_status;
|
2002-12-05 21:56:33 +00:00
|
|
|
atp->result->active_task_state = PROCESS_EXITED;
|
2002-08-26 22:57:17 +00:00
|
|
|
if (log_flags.task_debug) printf("process exited: status %d\n", atp->exit_status);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (WIFSIGNALED(stat)) {
|
|
|
|
atp->state = PROCESS_WAS_SIGNALED;
|
|
|
|
atp->signal = WTERMSIG(stat);
|
2002-12-05 21:35:51 +00:00
|
|
|
atp->result->signal = atp->signal;
|
2002-12-05 21:56:33 +00:00
|
|
|
atp->result->active_task_state = PROCESS_WAS_SIGNALED;
|
2002-08-26 22:57:17 +00:00
|
|
|
if (log_flags.task_debug) printf("process was signaled: %d\n", atp->signal);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
|
|
|
atp->state = PROCESS_EXIT_UNKNOWN;
|
|
|
|
atp->result->exit_status = -1;
|
|
|
|
}
|
2002-06-06 18:42:01 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-12-05 21:56:33 +00:00
|
|
|
atp->read_stderr_file();
|
2002-11-22 00:13:47 +00:00
|
|
|
clean_out_dir(atp->slot_dir);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for the stderr file, copy to result record
|
|
|
|
//
|
|
|
|
bool ACTIVE_TASK::read_stderr_file() {
|
|
|
|
char path[256];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
sprintf(path, "%s%s%s", slot_dir, PATH_SEPARATOR, STDERR_FILE);
|
2002-04-30 22:22:54 +00:00
|
|
|
FILE* f = fopen(path, "r");
|
|
|
|
if (f) {
|
2002-11-22 00:13:47 +00:00
|
|
|
n = fread(result->stderr_out, 1, STDERR_MAX_LEN, f);
|
|
|
|
result->stderr_out[n] = 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
fclose(f);
|
2002-12-05 21:56:33 +00:00
|
|
|
return true;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-12-05 21:56:33 +00:00
|
|
|
return false;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Find the ACTIVE_TASK in the current set with the matching PID
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
ACTIVE_TASK* ACTIVE_TASK_SET::lookup_pid(int pid) {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
|
|
|
if (atp->pid == pid) return atp;
|
|
|
|
}
|
2002-07-15 23:21:20 +00:00
|
|
|
return NULL;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Sends a suspend request to all currently running computation processes
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
void ACTIVE_TASK_SET::suspend_all() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2002-11-19 21:26:34 +00:00
|
|
|
atp->suspend(true); // suspend each active task
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Sends a resume signal to all currently running computation processes
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
void ACTIVE_TASK_SET::unsuspend_all() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2002-11-19 21:26:34 +00:00
|
|
|
atp->suspend(false); // resume each active task
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Attempts to exit all currently running computation processes, either
|
|
|
|
// via exit request or termination
|
|
|
|
//
|
2002-07-01 18:16:31 +00:00
|
|
|
void ACTIVE_TASK_SET::exit_tasks() {
|
|
|
|
unsigned int i;
|
2002-07-11 01:09:53 +00:00
|
|
|
ACTIVE_TASK *atp;
|
2002-07-01 18:16:31 +00:00
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2002-11-19 22:57:05 +00:00
|
|
|
atp->request_exit(1); // Give it 1 second to quit
|
2002-08-05 00:29:34 +00:00
|
|
|
atp->check_app_status_files();
|
2002-07-01 18:16:31 +00:00
|
|
|
}
|
2002-10-07 06:32:51 +00:00
|
|
|
}
|
2002-10-06 00:43:54 +00:00
|
|
|
|
2002-06-06 18:42:01 +00:00
|
|
|
#ifdef _WIN32
|
2002-11-19 21:26:34 +00:00
|
|
|
// Send a suspend or resume request to the ACTIVE_TASK
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2002-11-19 21:26:34 +00:00
|
|
|
void ACTIVE_TASK::suspend(bool suspend) {
|
2002-11-19 00:28:33 +00:00
|
|
|
char susp_file[256];
|
|
|
|
|
|
|
|
get_slot_dir(slot, slot_dir);
|
|
|
|
sprintf( susp_file, "%s%s%s", slot_dir, PATH_SEPARATOR, SUSPEND_QUIT_FILE );
|
|
|
|
FILE *fp = fopen( susp_file, "w" );
|
2002-06-06 18:42:01 +00:00
|
|
|
|
2002-11-19 22:57:05 +00:00
|
|
|
if (suspend)
|
|
|
|
write_suspend_quit_file( fp, true, false );
|
|
|
|
else
|
|
|
|
write_suspend_quit_file( fp, false, false );
|
2002-11-19 00:28:33 +00:00
|
|
|
|
|
|
|
fclose(fp);
|
2002-06-06 18:42:01 +00:00
|
|
|
}
|
|
|
|
#else
|
2002-11-19 21:26:34 +00:00
|
|
|
// Send a suspend or resume request to the ACTIVE_TASK
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2002-11-19 21:26:34 +00:00
|
|
|
void ACTIVE_TASK::suspend(bool suspend) {
|
2002-11-19 22:57:05 +00:00
|
|
|
if (suspend)
|
|
|
|
kill(this->pid, SIGSTOP); // put the process to sleep
|
|
|
|
else
|
|
|
|
kill(this->pid, SIGCONT); // wake up the process
|
2002-06-06 18:42:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Remove an ACTIVE_TASK from the set, assumes that the task has
|
|
|
|
// already been shut down via request_exit or similar means
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int ACTIVE_TASK_SET::remove(ACTIVE_TASK* atp) {
|
|
|
|
vector<ACTIVE_TASK*>::iterator iter;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
iter = active_tasks.begin();
|
|
|
|
while (iter != active_tasks.end()) {
|
|
|
|
if (*iter == atp) {
|
|
|
|
active_tasks.erase(iter);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "ACTIVE_TASK_SET::remove(): not found\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Restart active tasks without wiping and reinitializing slot directories
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int ACTIVE_TASK_SET::restart_tasks() {
|
|
|
|
vector<ACTIVE_TASK*>::iterator iter;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
iter = active_tasks.begin();
|
|
|
|
while (iter != active_tasks.end()) {
|
|
|
|
atp = *iter;
|
2002-08-24 00:41:25 +00:00
|
|
|
get_slot_dir(atp->slot, atp->slot_dir);
|
2002-04-30 22:22:54 +00:00
|
|
|
retval = atp->start(false);
|
|
|
|
if (log_flags.task) {
|
|
|
|
printf("restarting application for result %s\n", atp->result->name);
|
|
|
|
}
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "ACTIVE_TASKS::restart_tasks(); restart failed: %d\n", retval);
|
|
|
|
active_tasks.erase(iter);
|
|
|
|
} else {
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-19 21:26:34 +00:00
|
|
|
// See if the app has generated a new fraction-done file.
|
|
|
|
// If so read it and return true.
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2002-08-05 00:29:34 +00:00
|
|
|
bool ACTIVE_TASK::check_app_status_files() {
|
|
|
|
FILE* f;
|
2002-08-26 22:57:17 +00:00
|
|
|
char path[256];
|
2002-08-05 00:29:34 +00:00
|
|
|
bool found = false;
|
2002-08-08 23:41:48 +00:00
|
|
|
int retval;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2002-11-15 22:30:25 +00:00
|
|
|
sprintf(path, "%s%s%s", slot_dir, PATH_SEPARATOR, FRACTION_DONE_FILE);
|
2002-08-26 22:57:17 +00:00
|
|
|
f = fopen(path, "r");
|
2002-08-05 00:29:34 +00:00
|
|
|
if (f) {
|
|
|
|
found = true;
|
2002-11-19 21:26:34 +00:00
|
|
|
parse_fraction_done_file(f, fraction_done, current_cpu_time, checkpoint_cpu_time);
|
2002-08-05 00:29:34 +00:00
|
|
|
fclose(f);
|
2002-08-26 22:57:17 +00:00
|
|
|
retval = file_delete(path);
|
2002-08-24 00:41:25 +00:00
|
|
|
if (retval) {
|
2002-08-26 22:57:17 +00:00
|
|
|
fprintf(stderr,
|
2002-08-28 21:50:51 +00:00
|
|
|
"ACTIVE_TASK.check_app_status_files: could not delete %s: %d\n",
|
|
|
|
path, retval
|
|
|
|
);
|
2002-08-24 00:41:25 +00:00
|
|
|
}
|
2002-08-05 00:29:34 +00:00
|
|
|
}
|
|
|
|
return found;
|
2002-06-21 18:31:32 +00:00
|
|
|
}
|
|
|
|
|
2002-11-20 20:14:48 +00:00
|
|
|
// Returns the estimated time to completion (in seconds) of this
|
|
|
|
// active task, based on current reported CPU time and fraction done
|
|
|
|
//
|
|
|
|
double ACTIVE_TASK::est_time_to_completion() {
|
2002-12-05 21:56:33 +00:00
|
|
|
if(fraction_done <= 0 || fraction_done > 1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2002-11-20 20:14:48 +00:00
|
|
|
return (current_cpu_time / fraction_done) - current_cpu_time;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Poll each of the currently running tasks and get their CPU time
|
|
|
|
//
|
2002-06-21 18:31:32 +00:00
|
|
|
bool ACTIVE_TASK_SET::poll_time() {
|
|
|
|
ACTIVE_TASK* atp;
|
2002-07-01 18:16:31 +00:00
|
|
|
unsigned int i;
|
2002-08-08 23:41:48 +00:00
|
|
|
bool updated = false;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2002-08-22 22:28:51 +00:00
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
2002-06-21 18:31:32 +00:00
|
|
|
atp = active_tasks[i];
|
2002-08-05 00:29:34 +00:00
|
|
|
updated |= atp->check_app_status_files();
|
2002-06-21 18:31:32 +00:00
|
|
|
}
|
2002-08-22 22:28:51 +00:00
|
|
|
|
2002-06-21 18:31:32 +00:00
|
|
|
return updated;
|
|
|
|
}
|
|
|
|
|
2002-08-26 22:14:06 +00:00
|
|
|
// Gets the next available free slot, or returns -1 if all slots are full
|
2002-09-22 23:27:14 +00:00
|
|
|
// TODO: don't use malloc here
|
2002-08-26 22:14:06 +00:00
|
|
|
//
|
|
|
|
int ACTIVE_TASK_SET::get_free_slot(int total_slots) {
|
2002-09-22 23:27:14 +00:00
|
|
|
unsigned int i;
|
2002-08-26 22:14:06 +00:00
|
|
|
char *slot_status;
|
|
|
|
|
2002-09-22 23:27:14 +00:00
|
|
|
if (active_tasks.size() >= (unsigned int)total_slots) {
|
2002-08-26 22:14:06 +00:00
|
|
|
return -1;
|
2002-09-22 23:27:14 +00:00
|
|
|
}
|
|
|
|
|
2002-08-26 22:14:06 +00:00
|
|
|
slot_status = (char *)calloc( sizeof(char), total_slots );
|
|
|
|
if (!slot_status) return -1;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
if (active_tasks[i]->slot >= 0 && active_tasks[i]->slot < total_slots) {
|
|
|
|
slot_status[active_tasks[i]->slot] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-22 23:27:14 +00:00
|
|
|
for (i=0; i<(unsigned int)total_slots; i++) {
|
2002-08-26 22:14:06 +00:00
|
|
|
if (!slot_status[i]) {
|
|
|
|
free(slot_status);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(slot_status);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Write XML data about this ACTIVE_TASK
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int ACTIVE_TASK::write(FILE* fout) {
|
|
|
|
fprintf(fout,
|
|
|
|
"<active_task>\n"
|
2002-06-21 06:52:47 +00:00
|
|
|
" <project_master_url>%s</project_master_url>\n"
|
2002-04-30 22:22:54 +00:00
|
|
|
" <result_name>%s</result_name>\n"
|
|
|
|
" <app_version_num>%d</app_version_num>\n"
|
|
|
|
" <slot>%d</slot>\n"
|
2002-08-05 00:29:34 +00:00
|
|
|
" <checkpoint_cpu_time>%f</checkpoint_cpu_time>\n"
|
2002-04-30 22:22:54 +00:00
|
|
|
"</active_task>\n",
|
2002-06-21 06:52:47 +00:00
|
|
|
result->project->master_url,
|
2002-04-30 22:22:54 +00:00
|
|
|
result->name,
|
|
|
|
app_version->version_num,
|
|
|
|
slot,
|
2002-08-05 00:29:34 +00:00
|
|
|
checkpoint_cpu_time
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Parse XML information about an active task
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int ACTIVE_TASK::parse(FILE* fin, CLIENT_STATE* cs) {
|
2002-06-21 06:52:47 +00:00
|
|
|
char buf[256], result_name[256], project_master_url[256];
|
2002-04-30 22:22:54 +00:00
|
|
|
int app_version_num=0;
|
|
|
|
PROJECT* project;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
strcpy(result_name, "");
|
2002-06-21 06:52:47 +00:00
|
|
|
strcpy(project_master_url, "");
|
2002-04-30 22:22:54 +00:00
|
|
|
while (fgets(buf, 256, fin)) {
|
|
|
|
if (match_tag(buf, "</active_task>")) {
|
2002-06-21 06:52:47 +00:00
|
|
|
project = cs->lookup_project(project_master_url);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!project) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"ACTIVE_TASK::parse(): project not found: %s\n",
|
2002-06-21 06:52:47 +00:00
|
|
|
project_master_url
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
result = cs->lookup_result(project, result_name);
|
|
|
|
if (!result) {
|
|
|
|
fprintf(stderr, "ACTIVE_TASK::parse(): result not found\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
wup = result->wup;
|
|
|
|
app_version = cs->lookup_app_version(
|
|
|
|
result->app, app_version_num
|
|
|
|
);
|
|
|
|
if (!app_version) {
|
|
|
|
fprintf(stderr, "ACTIVE_TASK::parse(): app_version not found\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<result_name>", result_name, sizeof(result_name))) continue;
|
|
|
|
else if (parse_str(buf, "<project_master_url>", project_master_url, sizeof(project_master_url))) continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (parse_int(buf, "<app_version_num>", app_version_num)) continue;
|
|
|
|
else if (parse_int(buf, "<slot>", slot)) continue;
|
2002-08-24 00:41:25 +00:00
|
|
|
else if (parse_double(buf, "<checkpoint_cpu_time>", checkpoint_cpu_time)) continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
else fprintf(stderr, "ACTIVE_TASK::parse(): unrecognized %s\n", buf);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Write XML information about this active task set
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int ACTIVE_TASK_SET::write(FILE* fout) {
|
|
|
|
unsigned int i;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
fprintf(fout, "<active_task_set>\n");
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
active_tasks[i]->write(fout);
|
|
|
|
}
|
|
|
|
fprintf(fout, "</active_task_set>\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Parse XML information about an active task set
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int ACTIVE_TASK_SET::parse(FILE* fin, CLIENT_STATE* cs) {
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
char buf[256];
|
|
|
|
int retval;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
while (fgets(buf, 256, fin)) {
|
|
|
|
if (match_tag(buf, "</active_task_set>")) return 0;
|
|
|
|
else if (match_tag(buf, "<active_task>")) {
|
|
|
|
atp = new ACTIVE_TASK;
|
|
|
|
retval = atp->parse(fin, cs);
|
|
|
|
if (!retval) active_tasks.push_back(atp);
|
|
|
|
else delete atp;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "ACTIVE_TASK_SET::parse(): unrecognized %s\n", buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|