2003-06-11 23:12:55 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-12-03 18:57:40 +00:00
|
|
|
// 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
|
2003-06-11 23:12:55 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-06-11 23:12:57 +00:00
|
|
|
//
|
2002-12-03 18:57:40 +00:00
|
|
|
// 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
|
2003-06-11 23:12:57 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-12-03 18:57:40 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
2003-06-11 23:12:55 +00:00
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-06-11 23:12:57 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-12-03 18:57:40 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
// transitioner - handle transitions in the state of a WU
|
|
|
|
// - a result has become DONE (via timeout or client reply)
|
|
|
|
// - the WU error mask is set (e.g. by validater)
|
|
|
|
// - assimilation is finished
|
2002-10-24 08:25:42 +00:00
|
|
|
//
|
2003-08-15 20:35:44 +00:00
|
|
|
// cmdline:
|
2002-11-07 19:31:34 +00:00
|
|
|
// [ -asynch ] be asynchronous
|
2003-08-15 20:35:44 +00:00
|
|
|
// [ -one_pass ] do one pass, then exit
|
|
|
|
// [ -d x ] debug level x
|
2002-10-24 08:25:42 +00:00
|
|
|
|
2002-11-08 08:54:16 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2002-11-05 18:36:09 +00:00
|
|
|
#include <vector>
|
2002-11-07 19:31:34 +00:00
|
|
|
#include <unistd.h>
|
2003-09-19 07:54:11 +00:00
|
|
|
#include <limits.h>
|
2002-11-05 18:36:09 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2003-02-10 19:51:32 +00:00
|
|
|
#include "util.h"
|
2002-11-07 19:31:34 +00:00
|
|
|
#include "backend_lib.h"
|
2003-08-15 00:45:25 +00:00
|
|
|
#include "sched_config.h"
|
2003-03-08 00:09:40 +00:00
|
|
|
#include "sched_util.h"
|
2002-11-05 18:36:09 +00:00
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
#define LOCKFILE "transitioner.out"
|
|
|
|
#define PIDFILE "transitioner.pid"
|
2002-12-12 23:01:26 +00:00
|
|
|
|
2002-11-05 18:36:09 +00:00
|
|
|
int startup_time;
|
2003-09-02 21:16:55 +00:00
|
|
|
SCHED_CONFIG config;
|
2002-11-07 19:31:34 +00:00
|
|
|
R_RSA_PRIVATE_KEY key;
|
2002-11-05 18:36:09 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
void handle_wu(DB_WORKUNIT& wu) {
|
2003-09-11 09:35:19 +00:00
|
|
|
vector<DB_RESULT> results;
|
|
|
|
DB_RESULT* p_canonical_result = NULL;
|
2003-08-15 20:35:44 +00:00
|
|
|
int nerrors, retval, ninprogress, nsuccess;
|
|
|
|
int nunsent, ncouldnt_send, nover;
|
2003-09-11 09:35:19 +00:00
|
|
|
char suffix[256], result_template[MAX_BLOB_SIZE];
|
2003-08-15 20:35:44 +00:00
|
|
|
time_t now = time(0), x;
|
|
|
|
bool all_over, have_result_to_validate, do_delete;
|
2002-10-24 08:25:42 +00:00
|
|
|
|
2003-09-11 09:35:19 +00:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
// scan the results for the WU
|
|
|
|
//
|
|
|
|
DB_RESULT result;
|
|
|
|
sprintf(buf, "where workunitid=%d", wu.id);
|
|
|
|
while (!result.enumerate(buf)) {
|
|
|
|
results.push_back(result);
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2002-12-18 19:07:03 +00:00
|
|
|
|
2003-08-22 00:42:40 +00:00
|
|
|
ScopeMessages scope_messages(log_messages, SchedMessages::NORMAL);
|
2003-06-11 23:12:59 +00:00
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
// count up the number of results in various states,
|
|
|
|
// and check for timed-out results
|
|
|
|
//
|
|
|
|
nunsent = 0;
|
|
|
|
ninprogress = 0;
|
2003-10-10 20:10:18 +00:00
|
|
|
nover = 0;
|
2003-01-23 08:07:48 +00:00
|
|
|
nerrors = 0;
|
2003-08-15 20:35:44 +00:00
|
|
|
nsuccess = 0;
|
|
|
|
ncouldnt_send = 0;
|
|
|
|
have_result_to_validate = false;
|
2003-09-15 22:49:59 +00:00
|
|
|
for (unsigned int i=0; i<results.size(); i++) {
|
2003-09-11 09:35:19 +00:00
|
|
|
DB_RESULT& result = results[i];
|
2003-01-23 08:07:48 +00:00
|
|
|
|
|
|
|
switch (result.server_state) {
|
2003-08-15 20:35:44 +00:00
|
|
|
case RESULT_SERVER_STATE_UNSENT:
|
|
|
|
nunsent++;
|
|
|
|
break;
|
2003-01-23 08:07:48 +00:00
|
|
|
case RESULT_SERVER_STATE_IN_PROGRESS:
|
|
|
|
if (result.report_deadline < now) {
|
2003-06-14 20:15:53 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
2003-10-06 23:42:43 +00:00
|
|
|
"[WU#%d %s] [RESULT#%d %s] result timed out (%d < %d) server_state:IN_PROGRESS=>OVER; outcome:NO_REPLY\n",
|
2003-08-15 20:35:44 +00:00
|
|
|
wu.id, wu.name, result.id, result.name,
|
|
|
|
result.report_deadline, (int)now
|
2003-06-14 20:15:53 +00:00
|
|
|
);
|
2003-01-23 08:07:48 +00:00
|
|
|
result.server_state = RESULT_SERVER_STATE_OVER;
|
|
|
|
result.outcome = RESULT_OUTCOME_NO_REPLY;
|
2003-10-06 23:42:43 +00:00
|
|
|
retval = result.update();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] result.update() == %d\n",
|
|
|
|
wu.id, wu.name, result.id, result.name, retval
|
|
|
|
);
|
|
|
|
}
|
2003-08-18 22:34:53 +00:00
|
|
|
nover++;
|
2003-08-15 20:35:44 +00:00
|
|
|
} else {
|
|
|
|
ninprogress++;
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESULT_SERVER_STATE_OVER:
|
2003-08-15 20:35:44 +00:00
|
|
|
nover++;
|
2003-01-23 08:07:48 +00:00
|
|
|
switch (result.outcome) {
|
|
|
|
case RESULT_OUTCOME_COULDNT_SEND:
|
2003-06-14 20:15:53 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
2003-07-26 22:01:38 +00:00
|
|
|
"[WU#%d %s] [RESULT#%d %s] result couldn't be sent\n",
|
2003-06-14 20:15:53 +00:00
|
|
|
wu.id, wu.name, result.id, result.name
|
|
|
|
);
|
2003-08-15 20:35:44 +00:00
|
|
|
ncouldnt_send++;
|
2003-01-23 08:07:48 +00:00
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_SUCCESS:
|
2003-08-15 20:35:44 +00:00
|
|
|
if (result.validate_state == VALIDATE_STATE_INIT) {
|
|
|
|
have_result_to_validate = true;
|
|
|
|
}
|
|
|
|
nsuccess++;
|
2003-01-23 08:07:48 +00:00
|
|
|
break;
|
2003-08-15 20:35:44 +00:00
|
|
|
case RESULT_OUTCOME_CLIENT_ERROR:
|
2003-01-23 08:07:48 +00:00
|
|
|
nerrors++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2002-11-07 19:31:34 +00:00
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2002-11-07 19:31:34 +00:00
|
|
|
|
2003-10-10 20:10:18 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::DEBUG,
|
|
|
|
"[WU#%d %s] %d results: unsent %d, in_progress %d, over %d (success %d, error %d, couldnt_send %d)\n",
|
|
|
|
wu.id, wu.name,
|
|
|
|
(int)results.size(),
|
|
|
|
nunsent, ninprogress, nover, nsuccess, nerrors, ncouldnt_send
|
|
|
|
);
|
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
// trigger validation if we have a quorum
|
|
|
|
// and some result hasn't been validated
|
2003-01-23 08:07:48 +00:00
|
|
|
//
|
2003-08-15 20:35:44 +00:00
|
|
|
if (nsuccess >= wu.min_quorum && have_result_to_validate) {
|
|
|
|
wu.need_validate = true;
|
2003-10-10 05:36:09 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"[WU#%d %s] need_validate:=>true [nsuccess=%d >= min_quorum=%d]\n",
|
|
|
|
wu.id, wu.name, nsuccess, wu.min_quorum
|
|
|
|
);
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check for WU error conditions
|
|
|
|
// NOTE: check on max # of success results is done in validater
|
|
|
|
//
|
|
|
|
if (ncouldnt_send > 0) {
|
|
|
|
wu.error_mask |= WU_ERROR_COULDNT_SEND_RESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nerrors > wu.max_error_results) {
|
2003-06-14 20:15:53 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"[WU#%d %s] WU has too many errors (%d errors for %d results)\n",
|
|
|
|
wu.id, wu.name, nerrors, (int)results.size()
|
|
|
|
);
|
2003-01-23 08:07:48 +00:00
|
|
|
wu.error_mask |= WU_ERROR_TOO_MANY_ERROR_RESULTS;
|
|
|
|
}
|
2003-08-15 20:35:44 +00:00
|
|
|
if ((int)results.size() > wu.max_total_results) {
|
2003-06-14 20:15:53 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
2003-08-15 20:35:44 +00:00
|
|
|
"[WU#%d %s] WU has too many total results (%d)\n",
|
|
|
|
wu.id, wu.name, (int)results.size()
|
2003-06-14 20:15:53 +00:00
|
|
|
);
|
2003-08-15 20:35:44 +00:00
|
|
|
wu.error_mask |= WU_ERROR_TOO_MANY_TOTAL_RESULTS;
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2002-11-03 23:05:12 +00:00
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
// if this WU had an error, don't send any unsent results,
|
|
|
|
// and trigger assimilation if needed
|
2003-01-23 08:07:48 +00:00
|
|
|
//
|
2003-08-08 08:57:16 +00:00
|
|
|
if (wu.error_mask) {
|
2003-09-15 22:49:59 +00:00
|
|
|
for (unsigned int i=0; i<results.size(); i++) {
|
2003-09-11 09:35:19 +00:00
|
|
|
DB_RESULT& result = results[i];
|
2002-12-07 00:56:51 +00:00
|
|
|
if (result.server_state == RESULT_SERVER_STATE_UNSENT) {
|
2003-10-06 23:42:43 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] server_state:UNSENT=>OVER; outcome:=>DIDNT_NEED\n",
|
|
|
|
wu.id, wu.name, result.id, result.name
|
|
|
|
);
|
2003-01-23 08:07:48 +00:00
|
|
|
result.server_state = RESULT_SERVER_STATE_OVER;
|
|
|
|
result.outcome = RESULT_OUTCOME_DIDNT_NEED;
|
2003-10-06 23:42:43 +00:00
|
|
|
retval = result.update();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] result.update() == %d\n",
|
|
|
|
wu.id, wu.name, result.id, result.name, retval
|
|
|
|
);
|
|
|
|
}
|
2002-11-03 23:05:12 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
if (wu.assimilate_state == ASSIMILATE_INIT) {
|
2002-12-17 19:00:43 +00:00
|
|
|
wu.assimilate_state = ASSIMILATE_READY;
|
2003-10-10 05:36:09 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"[WU#%d %s] error_mask:%d assimilate_state:INIT=>READY\n",
|
|
|
|
wu.id, wu.name, wu.error_mask
|
|
|
|
);
|
2002-11-03 23:05:12 +00:00
|
|
|
}
|
2003-08-18 22:34:53 +00:00
|
|
|
} else if (wu.assimilate_state == ASSIMILATE_INIT) {
|
2003-01-23 08:07:48 +00:00
|
|
|
// If no error, generate new results if needed.
|
2003-09-15 22:49:59 +00:00
|
|
|
// NOTE!! `n' must be a SIGNED integer!
|
|
|
|
int n = wu.target_nresults - nunsent - ninprogress - nsuccess;
|
2003-08-15 20:35:44 +00:00
|
|
|
if (n > 0) {
|
2003-06-14 20:15:53 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
2003-08-18 22:34:53 +00:00
|
|
|
"[WU#%d %s] Generating %d more results (%d target - %d unsent - %d in progress - %d success)\n",
|
|
|
|
wu.id, wu.name, n, wu.target_nresults, nunsent, ninprogress, nsuccess
|
2003-06-14 20:15:53 +00:00
|
|
|
);
|
2003-09-15 22:49:59 +00:00
|
|
|
for (int i=0; i<n; i++) {
|
2003-08-15 23:44:28 +00:00
|
|
|
sprintf(suffix, "%d", results.size()+i);
|
|
|
|
strcpy(result_template, wu.result_template);
|
|
|
|
retval = create_result(wu, result_template, suffix, key, "");
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[WU#%d %s] create_result() %d\n",
|
|
|
|
wu.id, wu.name, retval
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2002-11-07 19:31:34 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2002-11-07 19:31:34 +00:00
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
// scan results, see if all over, look for canonical result
|
|
|
|
//
|
|
|
|
all_over = true;
|
2003-09-15 22:49:59 +00:00
|
|
|
for (unsigned int i=0; i<results.size(); i++) {
|
2003-09-11 09:35:19 +00:00
|
|
|
DB_RESULT& result = results[i];
|
2003-08-15 20:35:44 +00:00
|
|
|
if (result.server_state != RESULT_SERVER_STATE_OVER) {
|
|
|
|
all_over = false;
|
|
|
|
}
|
|
|
|
if (result.id == wu.canonical_resultid) {
|
2003-09-11 09:35:19 +00:00
|
|
|
p_canonical_result = &result;
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-11 09:35:19 +00:00
|
|
|
if (wu.canonical_resultid && p_canonical_result == 0) {
|
2003-08-15 20:35:44 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[WU#%d %s] can't find canonical result\n",
|
|
|
|
wu.id, wu.name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if WU is assimilated, trigger file deletion
|
|
|
|
//
|
|
|
|
if (wu.assimilate_state == ASSIMILATE_DONE) {
|
|
|
|
// can delete input files if all results OVER
|
|
|
|
//
|
2003-09-20 17:38:13 +00:00
|
|
|
if (all_over && wu.file_delete_state == FILE_DELETE_INIT) {
|
2003-08-15 20:35:44 +00:00
|
|
|
wu.file_delete_state = FILE_DELETE_READY;
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::DEBUG,
|
2003-10-06 23:42:43 +00:00
|
|
|
"[WU#%d %s] ASSIMILATE_DONE: file_delete_state:=>READY\n",
|
2003-08-15 20:35:44 +00:00
|
|
|
wu.id, wu.name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// output of error results can be deleted immediately;
|
|
|
|
// output of success results can be deleted if validated
|
2003-08-08 08:57:16 +00:00
|
|
|
//
|
2003-09-15 22:49:59 +00:00
|
|
|
for (unsigned int i=0; i<results.size(); i++) {
|
2003-09-11 09:35:19 +00:00
|
|
|
DB_RESULT& result = results[i];
|
2003-09-20 17:38:13 +00:00
|
|
|
|
2003-09-11 09:25:26 +00:00
|
|
|
// can delete canonical result outputs only if all successful
|
|
|
|
// results have been validated
|
2003-09-20 17:38:13 +00:00
|
|
|
//
|
2003-09-11 09:35:19 +00:00
|
|
|
if (&result == p_canonical_result && !all_over) continue;
|
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
do_delete = false;
|
|
|
|
switch(result.outcome) {
|
|
|
|
case RESULT_OUTCOME_CLIENT_ERROR:
|
|
|
|
do_delete = true;
|
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_SUCCESS:
|
|
|
|
do_delete = (result.validate_state != VALIDATE_STATE_INIT);
|
2003-08-08 08:57:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-09-20 17:38:13 +00:00
|
|
|
if (do_delete && result.file_delete_state == FILE_DELETE_INIT) {
|
2003-10-06 23:42:43 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] file_delete_state:=>READY\n",
|
|
|
|
wu.id, wu.name, result.id, result.name
|
|
|
|
);
|
2003-08-15 20:35:44 +00:00
|
|
|
result.file_delete_state = FILE_DELETE_READY;
|
2003-10-06 23:42:43 +00:00
|
|
|
retval = result.update();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] result.update() == %d\n",
|
|
|
|
wu.id, wu.name, result.id, result.name, retval
|
|
|
|
);
|
|
|
|
}
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
2002-11-03 23:05:12 +00:00
|
|
|
}
|
2002-11-07 19:31:34 +00:00
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
|
2003-09-19 07:54:12 +00:00
|
|
|
wu.transition_time = INT_MAX;
|
2003-09-15 22:49:59 +00:00
|
|
|
for (unsigned int i=0; i<results.size(); i++) {
|
2003-09-11 09:35:19 +00:00
|
|
|
DB_RESULT& result = results[i];
|
2003-08-15 20:35:44 +00:00
|
|
|
if (result.server_state == RESULT_SERVER_STATE_IN_PROGRESS) {
|
|
|
|
x = result.sent_time + wu.delay_bound;
|
|
|
|
if (x < wu.transition_time) {
|
|
|
|
wu.transition_time = x;
|
|
|
|
}
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = wu.update();
|
2003-01-23 08:07:48 +00:00
|
|
|
if (retval) {
|
2003-06-14 20:15:53 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
2003-10-06 23:42:43 +00:00
|
|
|
"[WU#%d %s] workunit.update() == %d\n", wu.id, wu.name, retval
|
2003-06-14 20:15:53 +00:00
|
|
|
);
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
bool do_pass() {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_WORKUNIT wu;
|
|
|
|
char buf[256];
|
2003-01-23 08:07:48 +00:00
|
|
|
bool did_something = false;
|
|
|
|
|
2003-06-11 23:12:51 +00:00
|
|
|
check_stop_trigger();
|
2003-01-23 08:07:48 +00:00
|
|
|
// loop over WUs that are due to be checked
|
|
|
|
//
|
2003-08-15 20:35:44 +00:00
|
|
|
sprintf(buf, "where transition_time<%d", (int)time(0));
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!wu.enumerate(buf)) {
|
2003-01-23 08:07:48 +00:00
|
|
|
did_something = true;
|
|
|
|
handle_wu(wu);
|
|
|
|
}
|
2002-11-07 19:31:34 +00:00
|
|
|
return did_something;
|
|
|
|
}
|
|
|
|
|
2002-12-24 03:03:45 +00:00
|
|
|
void main_loop(bool one_pass) {
|
2002-11-07 19:31:34 +00:00
|
|
|
int retval;
|
|
|
|
|
2003-09-05 21:26:21 +00:00
|
|
|
retval = boinc_db.open(config.db_name, config.db_passwd);
|
2002-11-07 19:31:34 +00:00
|
|
|
if (retval) {
|
2003-09-05 21:26:21 +00:00
|
|
|
log_messages.printf(SchedMessages::CRITICAL, "boinc_db.open: %d\n", retval);
|
2002-11-07 19:31:34 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-06-11 23:12:51 +00:00
|
|
|
if (one_pass) {
|
2003-08-15 20:35:44 +00:00
|
|
|
do_pass();
|
2003-06-11 23:12:51 +00:00
|
|
|
} else {
|
|
|
|
while (1) {
|
2003-08-15 20:35:44 +00:00
|
|
|
if (!do_pass()) sleep(1);
|
2003-06-11 23:12:51 +00:00
|
|
|
}
|
2002-10-24 08:25:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2002-11-07 19:31:34 +00:00
|
|
|
int i, retval;
|
2002-12-24 03:03:45 +00:00
|
|
|
bool asynch = false, one_pass=false;
|
2002-11-07 19:31:34 +00:00
|
|
|
char path[256];
|
|
|
|
|
2003-03-08 00:09:40 +00:00
|
|
|
check_stop_trigger();
|
2002-11-05 18:36:09 +00:00
|
|
|
startup_time = time(0);
|
|
|
|
for (i=1; i<argc; i++) {
|
2003-08-15 20:35:44 +00:00
|
|
|
if (!strcmp(argv[i], "-asynch")) {
|
2002-11-05 18:36:09 +00:00
|
|
|
asynch = true;
|
2002-12-24 03:03:45 +00:00
|
|
|
} else if (!strcmp(argv[i], "-one_pass")) {
|
|
|
|
one_pass = true;
|
2003-06-11 23:12:48 +00:00
|
|
|
} else if (!strcmp(argv[i], "-d")) {
|
2003-06-11 23:12:56 +00:00
|
|
|
log_messages.set_debug_level(atoi(argv[++i]));
|
2002-11-05 18:36:09 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-10 19:51:32 +00:00
|
|
|
|
2003-09-02 21:16:55 +00:00
|
|
|
retval = config.parse_file("..");
|
2003-02-10 19:51:32 +00:00
|
|
|
if (retval) {
|
2003-06-11 23:12:56 +00:00
|
|
|
log_messages.printf(SchedMessages::CRITICAL, "can't read config file\n");
|
2003-02-10 19:51:32 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(path, "%s/upload_private", config.key_dir);
|
|
|
|
retval = read_key_file(path, key);
|
|
|
|
if (retval) {
|
2003-06-11 23:12:56 +00:00
|
|
|
log_messages.printf(SchedMessages::CRITICAL, "can't read key\n");
|
2003-02-10 19:51:32 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2002-11-05 18:36:09 +00:00
|
|
|
if (asynch) {
|
2002-12-03 18:57:40 +00:00
|
|
|
if (fork()) {
|
|
|
|
exit(0);
|
2002-11-05 18:36:09 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-27 19:29:48 +00:00
|
|
|
|
2003-06-11 23:12:57 +00:00
|
|
|
// // Call lock_file after fork(), because file locks are not always inherited
|
|
|
|
// if (lock_file(LOCKFILE)) {
|
2003-08-15 20:35:44 +00:00
|
|
|
// log_messages.printf(SchedMessages::NORMAL, "Another copy of transitioner is already running\n");
|
2003-06-11 23:12:57 +00:00
|
|
|
// exit(1);
|
|
|
|
// }
|
|
|
|
// write_pid_file(PIDFILE);
|
2003-06-11 23:12:56 +00:00
|
|
|
log_messages.printf(SchedMessages::NORMAL, "Starting\n");
|
2003-06-11 23:12:54 +00:00
|
|
|
|
2003-06-11 23:12:51 +00:00
|
|
|
install_sigint_handler();
|
2003-02-27 19:29:48 +00:00
|
|
|
|
2002-12-24 03:03:45 +00:00
|
|
|
main_loop(one_pass);
|
2002-10-24 08:25:42 +00:00
|
|
|
}
|