2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-06-11 23:36:50 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2003-06-11 23:36:50 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-12-03 18:57:40 +00:00
|
|
|
// Handle a scheduling server RPC
|
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-08-03 21:51:30 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdio>
|
2002-09-26 23:12:13 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2004-08-03 21:51:30 +00:00
|
|
|
#include <ctime>
|
|
|
|
#include <cmath>
|
2002-09-26 23:12:13 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
2005-05-17 05:55:24 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
2005-08-16 23:47:51 +00:00
|
|
|
#include <sys/stat.h>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "backend_lib.h"
|
2003-10-21 04:06:55 +00:00
|
|
|
#include "error_numbers.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "parse.h"
|
2003-04-03 18:35:40 +00:00
|
|
|
#include "util.h"
|
2005-05-17 21:08:48 +00:00
|
|
|
#include "filesys.h"
|
|
|
|
|
|
|
|
#include "main.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "server_types.h"
|
2003-06-11 23:36:40 +00:00
|
|
|
#include "sched_util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "handle_request.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "sched_msgs.h"
|
2005-08-04 03:50:04 +00:00
|
|
|
#include "sched_resend.h"
|
2004-04-04 01:59:47 +00:00
|
|
|
#include "sched_send.h"
|
2004-08-05 22:14:23 +00:00
|
|
|
#include "sched_config.h"
|
2005-05-17 21:08:48 +00:00
|
|
|
#include "sched_locality.h"
|
2003-08-09 00:11:32 +00:00
|
|
|
|
2004-07-03 21:38:22 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#include "fcgi_stdio.h"
|
|
|
|
#endif
|
|
|
|
|
2005-06-03 21:39:38 +00:00
|
|
|
// Try to lock a file with name based on host ID,
|
|
|
|
// to prevent 2 schedulers from running at same time for same host.
|
|
|
|
// Return:
|
|
|
|
// 0 if successful
|
|
|
|
// In this case store file descriptor in reply struct so we can unlock later
|
|
|
|
// In other cases store -1 in reply struct
|
|
|
|
// PID (>0) if another process has lock
|
|
|
|
// -1 if error (e.g. can't create file)
|
2005-05-17 05:55:24 +00:00
|
|
|
//
|
|
|
|
int lock_sched(SCHEDULER_REPLY& reply) {
|
2005-05-24 04:32:36 +00:00
|
|
|
char filename[256];
|
2005-05-17 05:55:24 +00:00
|
|
|
char pid_string[16];
|
|
|
|
int fd, pid, count;
|
|
|
|
|
|
|
|
reply.lockfile_fd=-1;
|
|
|
|
|
2005-06-03 21:39:38 +00:00
|
|
|
sprintf(filename, "%s/CGI_%07d", config.sched_lockfile_dir, reply.host.id);
|
2005-05-17 05:55:24 +00:00
|
|
|
|
2005-05-24 04:32:36 +00:00
|
|
|
fd = open(filename, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
|
|
|
if (fd < 0) return -1;
|
2005-05-17 05:55:24 +00:00
|
|
|
|
2005-05-24 04:32:36 +00:00
|
|
|
// if we can't get an advisory write lock on the file,
|
|
|
|
// return the PID of the process that DOES hold the lock.
|
2005-06-03 21:39:38 +00:00
|
|
|
// (or -1 if failure)
|
2005-05-24 04:32:36 +00:00
|
|
|
//
|
2005-06-03 21:39:38 +00:00
|
|
|
pid = mylockf(fd);
|
|
|
|
if (pid) {
|
|
|
|
close(fd);
|
|
|
|
return pid;
|
|
|
|
}
|
2005-05-17 05:55:24 +00:00
|
|
|
|
|
|
|
// write PID into the CGI_<HOSTID> file and flush to disk
|
2005-05-24 04:32:36 +00:00
|
|
|
//
|
2005-06-03 21:39:38 +00:00
|
|
|
count = sprintf(pid_string, "%d\n", getpid());
|
2005-05-17 05:55:24 +00:00
|
|
|
write(fd, pid_string, count);
|
|
|
|
fsync(fd);
|
|
|
|
|
2005-06-03 21:39:38 +00:00
|
|
|
reply.lockfile_fd = fd;
|
2005-05-17 05:55:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-03 21:39:38 +00:00
|
|
|
// unlock and delete per-host lockfile
|
|
|
|
//
|
|
|
|
void unlock_sched(SCHEDULER_REPLY& reply) {
|
|
|
|
char filename[256];
|
|
|
|
|
|
|
|
if (reply.lockfile_fd < 0) return;
|
|
|
|
sprintf(filename, "%s/CGI_%07d", config.sched_lockfile_dir, reply.host.id);
|
|
|
|
unlink(filename);
|
|
|
|
close(reply.lockfile_fd);
|
|
|
|
}
|
|
|
|
|
2006-03-12 06:20:28 +00:00
|
|
|
// find the user's most recently-created host with given host CPID
|
2006-03-11 00:17:46 +00:00
|
|
|
//
|
2006-03-12 06:33:38 +00:00
|
|
|
static bool find_host_by_cpid(DB_USER& user, char* host_cpid, DB_HOST& host) {
|
2006-03-11 00:17:46 +00:00
|
|
|
char buf[256], buf2[256];
|
|
|
|
sprintf(buf, "%s%s", host_cpid, user.email_addr);
|
|
|
|
md5_block((const unsigned char*)buf, strlen(buf), buf2);
|
|
|
|
|
|
|
|
sprintf(buf,
|
|
|
|
"where userid=%d and host_cpid='%s' order by id desc", user.id, buf2
|
|
|
|
);
|
|
|
|
if (!host.enumerate(buf)) {
|
|
|
|
host.end_enumerate();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-06-06 18:45:40 +00:00
|
|
|
// Called when there's evidence that the host has detached.
|
|
|
|
// Mark in-progress results for the given host
|
2006-07-06 17:30:03 +00:00
|
|
|
// as server state OVER, outcome CLIENT_DETACHED.
|
2006-06-06 18:45:40 +00:00
|
|
|
// This serves two purposes:
|
|
|
|
// 1) make sure we don't resend these results to the host
|
|
|
|
// (they may be the reason the user detached)
|
|
|
|
// 2) trigger the generation of new results for these WUs
|
2006-03-12 06:20:28 +00:00
|
|
|
//
|
2006-06-06 18:45:40 +00:00
|
|
|
static void mark_results_over(DB_HOST& host) {
|
2006-03-12 06:20:28 +00:00
|
|
|
char buf[256], buf2[256];
|
|
|
|
DB_RESULT result;
|
|
|
|
sprintf(buf, "where hostid=%d and server_state=%d",
|
|
|
|
host.id,
|
|
|
|
RESULT_SERVER_STATE_IN_PROGRESS
|
|
|
|
);
|
|
|
|
while (!result.enumerate(buf)) {
|
|
|
|
sprintf(buf2,
|
|
|
|
"server_state=%d, outcome=%d",
|
|
|
|
RESULT_SERVER_STATE_OVER,
|
2006-07-06 17:30:03 +00:00
|
|
|
RESULT_OUTCOME_CLIENT_DETACHED
|
2006-03-12 06:20:28 +00:00
|
|
|
);
|
|
|
|
result.update_field(buf2);
|
|
|
|
|
|
|
|
// and trigger WU transition
|
|
|
|
//
|
|
|
|
DB_WORKUNIT wu;
|
|
|
|
wu.id = result.workunitid;
|
2006-05-02 22:33:00 +00:00
|
|
|
sprintf(buf2, "transition_time=%d", (int)time(0));
|
2006-03-12 06:20:28 +00:00
|
|
|
wu.update_field(buf2);
|
2006-05-24 08:31:49 +00:00
|
|
|
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2006-06-03 14:59:22 +00:00
|
|
|
"[HOST#%d] [RESULT#%d] [WU#%d] changed CPID: marking in-progress result %s as client error!\n",
|
2006-05-24 08:31:49 +00:00
|
|
|
host.id, result.id, result.workunitid, result.name
|
|
|
|
);
|
2006-03-12 06:20:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-17 21:08:48 +00:00
|
|
|
// Based on the info in the request message,
|
|
|
|
// look up the host and its user, and make sure the authenticator matches.
|
|
|
|
// Some special cases:
|
|
|
|
// 1) If no host ID is supplied, or if RPC seqno mismatch,
|
|
|
|
// create a new host record
|
|
|
|
// 2) If the host record specified by sreq.hostid is a "zombie"
|
|
|
|
// (i.e. it was merged with another host via the web site)
|
|
|
|
// then follow links to find the proper host
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2004-09-27 19:44:40 +00:00
|
|
|
// POSTCONDITION:
|
2006-03-11 00:17:46 +00:00
|
|
|
// If this function returns zero, then:
|
2004-09-27 19:44:40 +00:00
|
|
|
// - reply.host contains a valid host record (possibly new)
|
|
|
|
// - reply.user contains a valid user record
|
2005-02-13 19:04:20 +00:00
|
|
|
// - if user belongs to a team, reply.team contains team record
|
2004-09-27 19:44:40 +00:00
|
|
|
//
|
2002-08-26 22:57:17 +00:00
|
|
|
int authenticate_user(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2002-04-30 22:22:54 +00:00
|
|
|
int retval;
|
2003-01-17 18:51:39 +00:00
|
|
|
char buf[256];
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_HOST host;
|
|
|
|
DB_USER user;
|
|
|
|
DB_TEAM team;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
if (sreq.hostid) {
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = host.lookup_id(sreq.hostid);
|
2005-04-12 21:54:40 +00:00
|
|
|
while (!retval && host.userid==0) {
|
2005-04-07 20:46:25 +00:00
|
|
|
// if host record is zombie, follow link to new host
|
|
|
|
//
|
|
|
|
retval = host.lookup_id(host.rpc_seqno);
|
|
|
|
if (!retval) {
|
|
|
|
reply.hostid = host.id;
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2005-04-07 20:46:25 +00:00
|
|
|
"[HOST#%d] forwarding to new host ID %d\n",
|
|
|
|
sreq.hostid, host.id
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2005-01-31 22:19:03 +00:00
|
|
|
USER_MESSAGE um("Can't find host record", "low");
|
|
|
|
reply.insert_message(um);
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2003-06-14 17:46:08 +00:00
|
|
|
"[HOST#%d?] can't find host\n",
|
|
|
|
sreq.hostid
|
|
|
|
);
|
2003-04-30 22:08:16 +00:00
|
|
|
sreq.hostid = 0;
|
2004-01-08 00:40:53 +00:00
|
|
|
goto lookup_user_and_make_new_host;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2005-04-07 20:46:25 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
reply.host = host;
|
2005-03-19 18:24:24 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_DEBUG,
|
2005-04-07 20:46:25 +00:00
|
|
|
"Request [HOST#%d] Database [HOST#%d] Request [RPC#%d] Database [RPC#%d]\n",
|
|
|
|
sreq.hostid, host.id, sreq.rpc_seqno, host.rpc_seqno
|
|
|
|
);
|
2003-06-04 17:21:26 +00:00
|
|
|
|
2004-12-20 21:37:20 +00:00
|
|
|
strlcpy(
|
2006-03-11 00:17:46 +00:00
|
|
|
user.authenticator, sreq.authenticator, sizeof(user.authenticator)
|
2004-12-20 21:37:20 +00:00
|
|
|
);
|
|
|
|
sprintf(buf, "where authenticator='%s'", user.authenticator);
|
|
|
|
retval = user.lookup(buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2005-01-31 22:19:03 +00:00
|
|
|
USER_MESSAGE um("Invalid or missing account key. "
|
|
|
|
"Visit this project's web site to get an account key.",
|
2005-02-13 19:04:20 +00:00
|
|
|
"high"
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2005-01-31 22:19:03 +00:00
|
|
|
reply.insert_message(um);
|
2006-11-05 00:15:10 +00:00
|
|
|
reply.set_delay(DELAY_MISSING_KEY);
|
2003-04-30 22:02:53 +00:00
|
|
|
reply.nucleus_only = true;
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2003-06-14 17:46:08 +00:00
|
|
|
"[HOST#%d] [USER#%d] Bad authenticator '%s'\n",
|
|
|
|
host.id, user.id, sreq.authenticator
|
|
|
|
);
|
2003-10-21 04:06:55 +00:00
|
|
|
return ERR_AUTHENTICATOR;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2005-02-13 19:04:20 +00:00
|
|
|
|
2004-12-20 21:37:20 +00:00
|
|
|
reply.user = user;
|
|
|
|
|
|
|
|
if (host.userid != user.id) {
|
|
|
|
// If the request's host ID isn't consistent with the authenticator,
|
|
|
|
// create a new host record.
|
|
|
|
//
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2004-12-20 21:37:20 +00:00
|
|
|
"[HOST#%d] [USER#%d] inconsistent host ID; creating new host\n",
|
|
|
|
host.id, user.id
|
|
|
|
);
|
|
|
|
goto make_new_host;
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// If the seqno from the host is less than what we expect,
|
|
|
|
// the user must have copied the state file to a different host.
|
|
|
|
// Make a new host record.
|
2004-05-03 02:18:35 +00:00
|
|
|
//
|
2002-08-26 22:57:17 +00:00
|
|
|
if (sreq.rpc_seqno < reply.host.rpc_seqno) {
|
2002-04-30 22:22:54 +00:00
|
|
|
sreq.hostid = 0;
|
2004-01-08 00:09:26 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2004-01-08 00:09:26 +00:00
|
|
|
"[HOST#%d] [USER#%d] RPC seqno %d less than expected %d; creating new host\n",
|
|
|
|
reply.host.id, user.id, sreq.rpc_seqno, reply.host.rpc_seqno
|
|
|
|
);
|
2004-01-08 00:40:53 +00:00
|
|
|
goto make_new_host;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-03-11 00:17:46 +00:00
|
|
|
// Here no hostid was given, or the ID was bad.
|
|
|
|
// Look up the user, then create a new host record
|
2003-06-04 17:21:26 +00:00
|
|
|
//
|
2004-01-08 00:40:53 +00:00
|
|
|
lookup_user_and_make_new_host:
|
2004-12-20 21:37:20 +00:00
|
|
|
strlcpy(
|
2003-06-04 17:21:26 +00:00
|
|
|
user.authenticator, sreq.authenticator,
|
|
|
|
sizeof(user.authenticator)
|
2002-09-22 23:27:14 +00:00
|
|
|
);
|
2003-06-04 17:21:26 +00:00
|
|
|
sprintf(buf, "where authenticator='%s'", user.authenticator);
|
|
|
|
retval = user.lookup(buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2005-01-31 22:19:03 +00:00
|
|
|
USER_MESSAGE um(
|
2004-12-06 22:41:19 +00:00
|
|
|
"Invalid or missing account key. "
|
2005-01-31 22:19:03 +00:00
|
|
|
"Visit this project's web site to get an account key.",
|
|
|
|
"low"
|
2003-03-02 19:24:09 +00:00
|
|
|
);
|
2005-01-31 22:19:03 +00:00
|
|
|
reply.insert_message(um);
|
2006-11-05 00:15:10 +00:00
|
|
|
reply.set_delay(DELAY_MISSING_KEY);
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2003-06-14 17:46:08 +00:00
|
|
|
"[HOST#<none>] Bad authenticator '%s'\n",
|
|
|
|
sreq.authenticator
|
|
|
|
);
|
2003-10-21 04:06:55 +00:00
|
|
|
return ERR_AUTHENTICATOR;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-06-04 17:21:26 +00:00
|
|
|
reply.user = user;
|
2006-03-11 00:17:46 +00:00
|
|
|
|
|
|
|
// If host CPID is present,
|
|
|
|
// scan backwards through this user's hosts,
|
|
|
|
// looking for one with the same host CPID.
|
|
|
|
// If we find one, it means the user detached and reattached.
|
2006-03-12 06:20:28 +00:00
|
|
|
// Use the existing host record,
|
2006-07-06 17:30:03 +00:00
|
|
|
// and mark in-progress results as over.
|
2006-03-11 00:17:46 +00:00
|
|
|
//
|
|
|
|
if (strlen(sreq.host.host_cpid)) {
|
|
|
|
if (find_host_by_cpid(user, sreq.host.host_cpid, host)) {
|
2006-05-24 08:31:49 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2006-06-03 14:59:22 +00:00
|
|
|
"[HOST#%d] [USER#%d] User has another host with same CPID.\n",
|
2006-05-24 09:22:34 +00:00
|
|
|
host.id, host.userid
|
2006-05-24 08:31:49 +00:00
|
|
|
);
|
2006-06-06 18:45:40 +00:00
|
|
|
mark_results_over(host);
|
2006-03-11 00:17:46 +00:00
|
|
|
goto got_host;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-08 00:40:53 +00:00
|
|
|
make_new_host:
|
2006-03-11 00:17:46 +00:00
|
|
|
// either of the above cases,
|
|
|
|
// or host ID didn't match user ID,
|
|
|
|
// or RPC seqno was too low.
|
|
|
|
//
|
|
|
|
// Create a new host.
|
2002-08-28 21:50:51 +00:00
|
|
|
// reply.user is filled in and valid at this point
|
|
|
|
//
|
2003-06-04 17:21:26 +00:00
|
|
|
host = sreq.host;
|
|
|
|
host.id = 0;
|
|
|
|
host.create_time = time(0);
|
|
|
|
host.userid = reply.user.id;
|
|
|
|
host.rpc_seqno = 0;
|
2006-01-13 01:07:05 +00:00
|
|
|
host.expavg_time = time(0);
|
2003-06-04 17:21:26 +00:00
|
|
|
strcpy(host.venue, reply.user.venue);
|
2004-01-19 01:12:53 +00:00
|
|
|
host.fix_nans();
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = host.insert();
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2005-01-31 22:19:03 +00:00
|
|
|
USER_MESSAGE um("Couldn't create host record in database", "low");
|
|
|
|
reply.insert_message(um);
|
2003-09-05 21:26:21 +00:00
|
|
|
boinc_db.print_error("host.insert()");
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "host.insert() failed\n");
|
2003-10-21 04:06:55 +00:00
|
|
|
return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-09-05 21:26:21 +00:00
|
|
|
host.id = boinc_db.insert_id();
|
2003-06-04 17:21:26 +00:00
|
|
|
|
2006-03-11 00:17:46 +00:00
|
|
|
got_host:
|
2003-06-04 17:21:26 +00:00
|
|
|
reply.host = host;
|
2002-08-28 21:50:51 +00:00
|
|
|
reply.hostid = reply.host.id;
|
2006-03-03 20:25:31 +00:00
|
|
|
// this tells client to updates its host ID
|
|
|
|
sreq.rpc_seqno = 0;
|
|
|
|
// this value eventually gets written to host DB record;
|
|
|
|
// for new hosts it must be zero.
|
|
|
|
// This kludge forces this.
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-05-03 02:18:35 +00:00
|
|
|
|
|
|
|
// have user record in reply.user at this point
|
|
|
|
//
|
|
|
|
|
2003-02-24 21:31:36 +00:00
|
|
|
if (reply.user.teamid) {
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = team.lookup_id(reply.user.teamid);
|
2003-02-24 21:31:36 +00:00
|
|
|
if (!retval) reply.team = team;
|
|
|
|
}
|
2004-05-03 02:18:35 +00:00
|
|
|
|
|
|
|
// compute email hash
|
|
|
|
//
|
|
|
|
md5_block(
|
|
|
|
(unsigned char*)reply.user.email_addr,
|
|
|
|
strlen(reply.user.email_addr),
|
|
|
|
reply.email_hash
|
|
|
|
);
|
|
|
|
|
2006-03-11 00:17:46 +00:00
|
|
|
// if new user CPID, update user record
|
2004-05-03 02:18:35 +00:00
|
|
|
//
|
|
|
|
if (strlen(sreq.cross_project_id)) {
|
2005-02-09 20:06:15 +00:00
|
|
|
if (strcmp(sreq.cross_project_id, reply.user.cross_project_id)) {
|
2005-04-29 06:55:44 +00:00
|
|
|
user.id = reply.user.id;
|
2005-05-05 20:42:06 +00:00
|
|
|
escape_string(sreq.cross_project_id, sizeof(sreq.cross_project_id));
|
2005-04-29 06:55:44 +00:00
|
|
|
sprintf(buf, "cross_project_id='%s'", sreq.cross_project_id);
|
2005-05-05 20:42:06 +00:00
|
|
|
unescape_string(sreq.cross_project_id, sizeof(sreq.cross_project_id));
|
2005-04-29 06:55:44 +00:00
|
|
|
user.update_field(buf);
|
2004-05-03 02:18:35 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
// somewhat arbitrary formula for credit as a function of CPU time.
|
|
|
|
// Could also include terms for RAM size, network speed etc.
|
|
|
|
//
|
2005-02-16 23:17:43 +00:00
|
|
|
static void compute_credit_rating(HOST& host) {
|
2005-11-01 19:46:46 +00:00
|
|
|
double fpw, intw, scale, x;
|
2005-11-01 04:19:10 +00:00
|
|
|
if (config.use_benchmark_weights) {
|
2005-11-01 19:46:46 +00:00
|
|
|
|
2005-11-01 04:19:10 +00:00
|
|
|
fpw = config.fp_benchmark_weight;
|
2005-11-01 19:46:46 +00:00
|
|
|
intw = 1. - fpw;
|
|
|
|
|
|
|
|
// FP benchmark is 2x int benchmark, on average.
|
|
|
|
// Compute a scaling factor the gives the same credit per day
|
|
|
|
// no matter how benchmarks are weighted
|
|
|
|
//
|
|
|
|
scale = 1.5 / (2*intw + fpw);
|
2005-11-01 04:19:10 +00:00
|
|
|
} else {
|
|
|
|
fpw = .5;
|
|
|
|
intw = .5;
|
2005-11-01 19:46:46 +00:00
|
|
|
scale = 1;
|
2005-11-01 04:19:10 +00:00
|
|
|
}
|
2005-11-01 19:46:46 +00:00
|
|
|
x = fpw*fabs(host.p_fpops) + intw*fabs(host.p_iops);
|
|
|
|
x /= 1e9;
|
|
|
|
x *= COBBLESTONE_FACTOR;
|
|
|
|
x /= SECONDS_PER_DAY;
|
|
|
|
x *= scale;
|
2007-01-12 17:42:29 +00:00
|
|
|
host.claimed_credit_per_cpu_sec = x;
|
2005-06-24 04:34:45 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 18:13:00 +00:00
|
|
|
// modify host struct based on request.
|
2002-04-30 22:22:54 +00:00
|
|
|
// Copy all fields that are determined by the client.
|
|
|
|
//
|
2004-05-30 21:47:11 +00:00
|
|
|
static int modify_host_struct(SCHEDULER_REQUEST& sreq, HOST& host) {
|
2002-04-30 22:22:54 +00:00
|
|
|
host.timezone = sreq.host.timezone;
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.domain_name, sreq.host.domain_name, sizeof(host.domain_name));
|
|
|
|
strncpy(host.serialnum, sreq.host.serialnum, sizeof(host.serialnum));
|
2002-04-30 22:22:54 +00:00
|
|
|
if (strcmp(host.last_ip_addr, sreq.host.last_ip_addr)) {
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.last_ip_addr, sreq.host.last_ip_addr, sizeof(host.last_ip_addr));
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
|
|
|
host.nsame_ip_addr++;
|
|
|
|
}
|
|
|
|
host.on_frac = sreq.host.on_frac;
|
|
|
|
host.connected_frac = sreq.host.connected_frac;
|
|
|
|
host.active_frac = sreq.host.active_frac;
|
2005-06-23 07:42:45 +00:00
|
|
|
host.cpu_efficiency = sreq.host.cpu_efficiency;
|
|
|
|
host.duration_correction_factor = sreq.host.duration_correction_factor;
|
2002-04-30 22:22:54 +00:00
|
|
|
host.p_ncpus = sreq.host.p_ncpus;
|
2003-03-02 19:24:09 +00:00
|
|
|
strncpy(host.p_vendor, sreq.host.p_vendor, sizeof(host.p_vendor));
|
|
|
|
// unlikely this will change
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.p_model, sreq.host.p_model, sizeof(host.p_model));
|
2002-04-30 22:22:54 +00:00
|
|
|
host.p_fpops = sreq.host.p_fpops;
|
|
|
|
host.p_iops = sreq.host.p_iops;
|
|
|
|
host.p_membw = sreq.host.p_membw;
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.os_name, sreq.host.os_name, sizeof(host.os_name));
|
|
|
|
strncpy(host.os_version, sreq.host.os_version, sizeof(host.os_version));
|
2002-04-30 22:22:54 +00:00
|
|
|
host.m_nbytes = sreq.host.m_nbytes;
|
|
|
|
host.m_cache = sreq.host.m_cache;
|
|
|
|
host.m_swap = sreq.host.m_swap;
|
|
|
|
host.d_total = sreq.host.d_total;
|
|
|
|
host.d_free = sreq.host.d_free;
|
2005-10-04 21:44:58 +00:00
|
|
|
host.d_boinc_used_total = sreq.host.d_boinc_used_total;
|
|
|
|
host.d_boinc_used_project = sreq.host.d_boinc_used_project;
|
2002-04-30 22:22:54 +00:00
|
|
|
host.n_bwup = sreq.host.n_bwup;
|
|
|
|
host.n_bwdown = sreq.host.n_bwdown;
|
2005-05-03 21:50:51 +00:00
|
|
|
if (strlen(sreq.host.host_cpid)) {
|
|
|
|
strcpy(host.host_cpid, sreq.host.host_cpid);
|
|
|
|
}
|
2004-01-19 01:12:53 +00:00
|
|
|
host.fix_nans();
|
2002-09-26 05:57:10 +00:00
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
compute_credit_rating(host);
|
2007-01-12 17:42:29 +00:00
|
|
|
sreq.host.claimed_credit_per_cpu_sec=host.claimed_credit_per_cpu_sec;
|
2004-05-27 18:13:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-09-26 05:57:10 +00:00
|
|
|
|
2006-03-03 20:25:31 +00:00
|
|
|
// update the DB record to the values in "xhost"
|
|
|
|
// "initial_host" stores the current DB values;
|
|
|
|
// update only those fields that have changed
|
|
|
|
//
|
2005-05-03 21:50:51 +00:00
|
|
|
static int update_host_record(HOST& initial_host, HOST& xhost, USER& user) {
|
2004-05-27 18:13:00 +00:00
|
|
|
DB_HOST host;
|
|
|
|
int retval;
|
2005-01-20 18:50:49 +00:00
|
|
|
char buf[1024];
|
2004-05-27 18:13:00 +00:00
|
|
|
|
|
|
|
host = xhost;
|
2005-11-10 06:06:11 +00:00
|
|
|
|
|
|
|
// hash the CPID reported by the host with the user's email address.
|
|
|
|
// This prevents one user from spoofing another one's host.
|
|
|
|
//
|
2005-01-20 18:50:49 +00:00
|
|
|
if (strlen(host.host_cpid)) {
|
|
|
|
sprintf(buf, "%s%s", host.host_cpid, user.email_addr);
|
|
|
|
md5_block((const unsigned char*)buf, strlen(buf), host.host_cpid);
|
|
|
|
}
|
2005-01-21 07:54:15 +00:00
|
|
|
|
|
|
|
char* p = getenv("REMOTE_ADDR");
|
|
|
|
if (p) {
|
|
|
|
strlcpy(host.external_ip_addr, p, sizeof(host.external_ip_addr));
|
|
|
|
}
|
2005-05-03 21:50:51 +00:00
|
|
|
retval = host.update_diff(initial_host);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "host.update() failed: %d\n", retval);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-06 18:52:50 +00:00
|
|
|
// 1) Decide which global prefs to use for sched decisions: either
|
|
|
|
// - <working_global_prefs> from request msg
|
|
|
|
// - <global_prefs> from request message
|
|
|
|
// - prefs from user DB record
|
2006-11-14 17:30:59 +00:00
|
|
|
// and parse them into sreq.global_prefs.
|
2006-10-06 18:52:50 +00:00
|
|
|
// 2) update prefs in user record if needed
|
|
|
|
// 2) send global prefs in reply msg if needed
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2002-09-27 20:36:03 +00:00
|
|
|
int handle_global_prefs(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2005-05-01 04:35:22 +00:00
|
|
|
char buf[LARGE_BLOB_SIZE];
|
2002-09-29 00:32:11 +00:00
|
|
|
reply.send_global_prefs = false;
|
2006-10-06 18:52:50 +00:00
|
|
|
bool have_working_prefs = (strlen(sreq.working_global_prefs_xml)>0);
|
|
|
|
bool have_master_prefs = (strlen(sreq.global_prefs_xml)>0);
|
|
|
|
bool have_db_prefs = (strlen(reply.user.global_prefs)>0);
|
|
|
|
bool same_account = !strcmp(
|
|
|
|
sreq.global_prefs_source_email_hash, reply.email_hash
|
|
|
|
);
|
2006-11-07 17:40:55 +00:00
|
|
|
int master_mod_time=0, db_mod_time=0;
|
2006-10-06 18:52:50 +00:00
|
|
|
if (have_master_prefs) {
|
2006-11-07 17:40:55 +00:00
|
|
|
parse_int(sreq.global_prefs_xml, "<mod_time>", master_mod_time);
|
2006-10-06 18:52:50 +00:00
|
|
|
}
|
|
|
|
if (have_db_prefs) {
|
2006-11-07 17:40:55 +00:00
|
|
|
parse_int(reply.user.global_prefs, "<mod_time>", db_mod_time);
|
2006-10-06 18:52:50 +00:00
|
|
|
}
|
2004-03-23 03:59:32 +00:00
|
|
|
|
2006-11-14 17:30:59 +00:00
|
|
|
//log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "have_master:%d have_working: %d have_db: %d\n", have_master_prefs, have_working_prefs, have_db_prefs);
|
|
|
|
|
|
|
|
// decide which prefs to use for sched decisions,
|
|
|
|
// and parse them into sreq.global_prefs
|
2006-10-06 18:52:50 +00:00
|
|
|
//
|
|
|
|
if (have_working_prefs) {
|
|
|
|
sreq.global_prefs.parse(sreq.working_global_prefs_xml, "");
|
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "using working prefs\n");
|
|
|
|
} else {
|
|
|
|
if (have_master_prefs) {
|
|
|
|
if (have_db_prefs && db_mod_time > master_mod_time) {
|
|
|
|
sreq.global_prefs.parse(reply.user.global_prefs, reply.host.venue);
|
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "using db prefs - more recent\n");
|
2004-05-03 02:18:35 +00:00
|
|
|
} else {
|
2006-10-06 18:52:50 +00:00
|
|
|
sreq.global_prefs.parse(sreq.global_prefs_xml, reply.host.venue);
|
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "using master prefs\n");
|
2002-09-29 00:32:11 +00:00
|
|
|
}
|
2004-05-03 02:18:35 +00:00
|
|
|
} else {
|
2006-10-06 18:52:50 +00:00
|
|
|
if (have_db_prefs) {
|
|
|
|
sreq.global_prefs.parse(reply.user.global_prefs, reply.host.venue);
|
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "using db prefs\n");
|
|
|
|
} else {
|
|
|
|
sreq.global_prefs.defaults();
|
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "using default prefs\n");
|
|
|
|
}
|
2004-05-03 02:18:35 +00:00
|
|
|
}
|
2006-10-06 18:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// decide whether to update DB
|
|
|
|
//
|
|
|
|
if (have_master_prefs) {
|
|
|
|
bool update_user_record = false;
|
|
|
|
if (have_db_prefs) {
|
2006-10-12 18:47:21 +00:00
|
|
|
if (master_mod_time > db_mod_time && same_account) {
|
2006-10-06 18:52:50 +00:00
|
|
|
update_user_record = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (same_account) update_user_record = true;
|
|
|
|
}
|
|
|
|
if (update_user_record) {
|
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "updating db prefs\n");
|
2004-05-03 02:18:35 +00:00
|
|
|
strcpy(reply.user.global_prefs, sreq.global_prefs_xml);
|
2005-04-29 06:55:44 +00:00
|
|
|
DB_USER user;
|
|
|
|
user.id = reply.user.id;
|
2005-05-05 20:42:06 +00:00
|
|
|
escape_string(sreq.global_prefs_xml, sizeof(sreq.global_prefs_xml));
|
2005-04-29 06:55:44 +00:00
|
|
|
sprintf(buf, "global_prefs='%s'", sreq.global_prefs_xml);
|
2005-05-05 20:42:06 +00:00
|
|
|
unescape_string(sreq.global_prefs_xml, sizeof(sreq.global_prefs_xml));
|
2005-05-01 04:35:22 +00:00
|
|
|
int retval = user.update_field(buf);
|
|
|
|
if (retval) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
|
2005-05-01 04:35:22 +00:00
|
|
|
"user.update_field() failed: %d\n", retval
|
|
|
|
);
|
|
|
|
}
|
2002-09-29 00:32:11 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2006-10-06 18:52:50 +00:00
|
|
|
|
|
|
|
// decide whether to send DB prefs in reply msg
|
|
|
|
//
|
2006-11-14 17:30:59 +00:00
|
|
|
//log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "have db %d; dbmod %d; global mod %d\n", have_db_prefs, db_mod_time, sreq.global_prefs.mod_time);
|
|
|
|
if (have_db_prefs && db_mod_time > master_mod_time) {
|
2006-10-06 18:52:50 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "sending db prefs in reply\n");
|
|
|
|
reply.send_global_prefs = true;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-07-06 21:44:59 +00:00
|
|
|
|
2005-06-22 02:40:14 +00:00
|
|
|
// handle completed results
|
2004-08-05 22:14:23 +00:00
|
|
|
//
|
2005-05-17 21:08:48 +00:00
|
|
|
int handle_results(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2004-07-06 18:30:22 +00:00
|
|
|
DB_SCHED_RESULT_ITEM_SET result_handler;
|
2004-07-27 22:42:06 +00:00
|
|
|
SCHED_RESULT_ITEM* srip;
|
2002-04-30 22:22:54 +00:00
|
|
|
unsigned int i;
|
|
|
|
int retval;
|
2003-06-04 17:21:26 +00:00
|
|
|
RESULT* rp;
|
2006-01-11 06:12:18 +00:00
|
|
|
bool changed_host=false;
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2004-07-21 23:48:56 +00:00
|
|
|
if (sreq.results.size() == 0) return 0;
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-07-28 08:09:46 +00:00
|
|
|
// copy reported results to a separate vector, "result_handler",
|
|
|
|
// initially with only the "name" field present
|
2004-07-06 18:30:22 +00:00
|
|
|
//
|
2004-07-21 23:48:56 +00:00
|
|
|
for (i=0; i<sreq.results.size(); i++) {
|
|
|
|
result_handler.add_result(sreq.results[i].name);
|
|
|
|
}
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-06-22 02:40:14 +00:00
|
|
|
// read results from database into "result_handler".
|
|
|
|
// Quantities that must be read from the DB are those
|
|
|
|
// where srip (see below) appears as an rval.
|
2006-05-31 20:39:32 +00:00
|
|
|
// These are: id, name, server_state, received_time, hostid, validate_state.
|
2005-06-22 02:40:14 +00:00
|
|
|
// Quantities that must be written to the DB are those for
|
2005-04-01 22:30:08 +00:00
|
|
|
// which srip appears as an lval. These are:
|
2005-06-22 02:40:14 +00:00
|
|
|
// hostid, teamid, received_time, client_state, cpu_time, exit_status,
|
2005-04-01 22:30:08 +00:00
|
|
|
// app_version_num, claimed_credit, server_state, stderr_out,
|
|
|
|
// xml_doc_out, outcome, validate_state
|
2004-12-05 21:53:32 +00:00
|
|
|
//
|
2004-07-21 23:48:56 +00:00
|
|
|
retval = result_handler.enumerate();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2004-07-21 23:48:56 +00:00
|
|
|
"[HOST#%d] Batch query failed\n",
|
|
|
|
reply.host.id
|
|
|
|
);
|
2004-07-06 18:30:22 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2005-04-01 22:30:08 +00:00
|
|
|
// loop over results reported by client
|
2004-12-05 21:53:32 +00:00
|
|
|
//
|
2005-08-16 20:48:21 +00:00
|
|
|
// A note about acks: we send an ack for result received if either
|
|
|
|
// 1) there's some problem with it (wrong state, host, not in DB) or
|
|
|
|
// 2) we update it successfully.
|
|
|
|
// In other words, the only time we don't ack a result is when
|
|
|
|
// it looks OK but the update failed.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<sreq.results.size(); i++) {
|
|
|
|
rp = &sreq.results[i];
|
2003-01-23 08:07:48 +00:00
|
|
|
|
2004-07-27 23:29:27 +00:00
|
|
|
retval = result_handler.lookup_result(rp->name, &srip);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2003-06-14 17:46:08 +00:00
|
|
|
"[HOST#%d] [RESULT#? %s] can't find result\n",
|
2004-05-30 21:47:11 +00:00
|
|
|
reply.host.id, rp->name
|
2003-06-14 17:46:08 +00:00
|
|
|
);
|
2005-07-28 08:09:46 +00:00
|
|
|
|
2005-06-22 06:02:59 +00:00
|
|
|
reply.result_acks.push_back(std::string(rp->name));
|
2003-01-07 22:49:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
|
2003-06-15 00:09:05 +00:00
|
|
|
log_messages.printf(
|
2006-06-03 16:22:34 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL, "[HOST#%d] [RESULT#%d %s] got result (DB: server_state=%d outcome=%d client_state=%d validate_state=%d delete_state=%d)\n",
|
|
|
|
reply.host.id, srip->id, srip->name, srip->server_state, srip->outcome, srip->client_state, srip->validate_state, srip->file_delete_state
|
2003-06-15 00:09:05 +00:00
|
|
|
);
|
|
|
|
|
2005-06-22 02:40:14 +00:00
|
|
|
// Do various sanity checks.
|
|
|
|
// If one of them fails, set srip->id = 0,
|
|
|
|
// which suppresses the DB update later on
|
2005-04-07 20:46:25 +00:00
|
|
|
//
|
2006-05-31 20:39:32 +00:00
|
|
|
|
2006-06-06 18:45:40 +00:00
|
|
|
// If result has server_state OVER
|
|
|
|
// if outcome NO_REPLY accept it (it's just late).
|
|
|
|
// else ignore it
|
2006-05-31 20:39:32 +00:00
|
|
|
//
|
|
|
|
if (srip->server_state == RESULT_SERVER_STATE_OVER) {
|
2006-06-09 23:17:05 +00:00
|
|
|
const char *dont_replace_result = NULL;
|
2006-05-31 20:39:32 +00:00
|
|
|
switch (srip->outcome) {
|
|
|
|
case RESULT_OUTCOME_INIT:
|
|
|
|
// should never happen!
|
2006-07-06 17:30:03 +00:00
|
|
|
dont_replace_result = "this result was never sent";
|
2006-05-31 20:39:32 +00:00
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_SUCCESS:
|
|
|
|
// don't replace a successful result!
|
2006-07-06 17:30:03 +00:00
|
|
|
dont_replace_result = "result already reported as success";
|
2006-05-31 20:39:32 +00:00
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_COULDNT_SEND:
|
|
|
|
// should never happen!
|
2006-07-06 17:30:03 +00:00
|
|
|
dont_replace_result = "this result couldn't be sent";
|
2006-05-31 20:39:32 +00:00
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_CLIENT_ERROR:
|
2006-06-06 18:45:40 +00:00
|
|
|
// should never happen!
|
2006-07-06 17:30:03 +00:00
|
|
|
dont_replace_result = "result already reported as error";
|
2006-05-31 20:39:32 +00:00
|
|
|
break;
|
2006-07-06 17:30:03 +00:00
|
|
|
case RESULT_OUTCOME_CLIENT_DETACHED:
|
2006-05-31 20:39:32 +00:00
|
|
|
case RESULT_OUTCOME_NO_REPLY:
|
|
|
|
// result is late in arriving, but keep it anyhow
|
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_DIDNT_NEED:
|
|
|
|
// should never happen
|
2006-07-06 17:30:03 +00:00
|
|
|
dont_replace_result = "this result wasn't sent (not needed)";
|
2006-05-31 20:39:32 +00:00
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_VALIDATE_ERROR:
|
|
|
|
// we already passed through the validator, so
|
|
|
|
// don't keep the new result
|
2006-07-06 17:30:03 +00:00
|
|
|
dont_replace_result = "result already reported, validate error";
|
2006-05-31 20:39:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dont_replace_result = "server logic bug; please alert BOINC developers";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dont_replace_result) {
|
|
|
|
char buf[256];
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2006-06-01 13:51:10 +00:00
|
|
|
"[HOST#%d] [RESULT#%d %s] result already over [outcome=%d validate_state=%d]: %s\n",
|
|
|
|
reply.host.id, srip->id, srip->name, srip->outcome, srip->validate_state, dont_replace_result
|
2006-05-31 20:39:32 +00:00
|
|
|
);
|
|
|
|
sprintf(buf, "Completed result %s refused: %s", srip->name, dont_replace_result);
|
|
|
|
USER_MESSAGE um(buf, "high");
|
|
|
|
reply.insert_message(um);
|
|
|
|
srip->id = 0;
|
|
|
|
reply.result_acks.push_back(std::string(rp->name));
|
|
|
|
continue;
|
2007-01-30 18:19:30 +00:00
|
|
|
}
|
2006-05-31 20:39:32 +00:00
|
|
|
}
|
|
|
|
|
2004-07-27 22:42:06 +00:00
|
|
|
if (srip->server_state == RESULT_SERVER_STATE_UNSENT) {
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2003-06-14 17:46:08 +00:00
|
|
|
"[HOST#%d] [RESULT#%d %s] got unexpected result: server state is %d\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
reply.host.id, srip->id, srip->name, srip->server_state
|
2003-06-14 17:46:08 +00:00
|
|
|
);
|
2006-05-25 23:15:06 +00:00
|
|
|
srip->id = 0;
|
2005-06-22 06:02:59 +00:00
|
|
|
reply.result_acks.push_back(std::string(rp->name));
|
2003-01-07 22:49:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-08-13 00:37:00 +00:00
|
|
|
|
2004-07-27 22:42:06 +00:00
|
|
|
if (srip->received_time) {
|
2004-01-08 00:51:13 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2004-01-08 00:51:13 +00:00
|
|
|
"[HOST#%d] [RESULT#%d %s] got result twice\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
reply.host.id, srip->id, srip->name
|
2004-01-08 00:51:13 +00:00
|
|
|
);
|
2006-05-25 23:15:06 +00:00
|
|
|
srip->id = 0;
|
2005-06-22 06:02:59 +00:00
|
|
|
reply.result_acks.push_back(std::string(rp->name));
|
2004-01-08 00:51:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-05-17 21:08:48 +00:00
|
|
|
if (srip->hostid != reply.host.id) {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2003-08-02 00:40:44 +00:00
|
|
|
"[HOST#%d] [RESULT#%d %s] got result from wrong host; expected [HOST#%d]\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
reply.host.id, srip->id, srip->name, srip->hostid
|
2003-08-02 00:40:44 +00:00
|
|
|
);
|
2003-06-14 17:46:09 +00:00
|
|
|
DB_HOST result_host;
|
2005-02-16 23:17:43 +00:00
|
|
|
retval = result_host.lookup_id(srip->hostid);
|
2003-06-14 17:46:09 +00:00
|
|
|
|
|
|
|
if (retval) {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2003-08-02 00:40:44 +00:00
|
|
|
"[RESULT#%d %s] Can't lookup [HOST#%d]\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->id, srip->name, srip->hostid
|
2003-08-02 00:40:44 +00:00
|
|
|
);
|
2006-05-25 23:15:06 +00:00
|
|
|
srip->id = 0;
|
2005-06-22 06:02:59 +00:00
|
|
|
reply.result_acks.push_back(std::string(rp->name));
|
2003-06-14 17:46:09 +00:00
|
|
|
continue;
|
2004-05-30 21:47:11 +00:00
|
|
|
} else if (result_host.userid != reply.host.userid) {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2003-08-02 00:40:44 +00:00
|
|
|
"[USER#%d] [HOST#%d] [RESULT#%d %s] Not even the same user; expected [USER#%d]\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
reply.host.userid, reply.host.id, srip->id, srip->name, result_host.userid
|
2003-08-02 00:40:44 +00:00
|
|
|
);
|
2006-05-25 23:15:06 +00:00
|
|
|
srip->id = 0;
|
2005-06-22 06:02:59 +00:00
|
|
|
reply.result_acks.push_back(std::string(rp->name));
|
2003-06-14 17:46:09 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2003-08-02 00:40:44 +00:00
|
|
|
"[HOST#%d] [RESULT#%d %s] Allowing result because same USER#%d\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
reply.host.id, srip->id, srip->name, reply.host.userid
|
2003-08-02 00:40:44 +00:00
|
|
|
);
|
2006-01-18 21:07:04 +00:00
|
|
|
changed_host = true;
|
2003-06-14 17:46:09 +00:00
|
|
|
}
|
2004-12-05 21:53:32 +00:00
|
|
|
} // hostids do not match
|
2002-09-22 23:27:14 +00:00
|
|
|
|
2005-06-22 02:40:14 +00:00
|
|
|
// Modify the in-memory copy obtained from the DB earlier.
|
2005-04-01 22:30:08 +00:00
|
|
|
// If we found a problem above,
|
|
|
|
// we have continued and skipped this modify
|
2003-08-15 20:35:44 +00:00
|
|
|
//
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->hostid = reply.host.id;
|
|
|
|
srip->teamid = reply.user.teamid;
|
|
|
|
srip->received_time = time(0);
|
|
|
|
srip->client_state = rp->client_state;
|
|
|
|
srip->cpu_time = rp->cpu_time;
|
2005-06-26 19:34:17 +00:00
|
|
|
|
|
|
|
// check for impossible CPU time
|
|
|
|
//
|
|
|
|
double elapsed_time = srip->received_time - srip->sent_time;
|
|
|
|
if (elapsed_time < 0) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,
|
2006-01-11 06:12:18 +00:00
|
|
|
"[HOST#%d] [RESULT#%d] inconsistent sent/received times\n", srip->hostid, srip->id
|
2005-06-26 19:34:17 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
if (srip->cpu_time > elapsed_time) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,
|
2006-01-11 06:12:18 +00:00
|
|
|
"[HOST#%d] [RESULT#%d] excessive CPU time: reported %f > elapsed %f%s\n",
|
|
|
|
srip->hostid, srip->id, srip->cpu_time, elapsed_time, changed_host?" [OK: HOST changed]":""
|
2005-06-26 19:34:17 +00:00
|
|
|
);
|
2006-01-11 06:12:18 +00:00
|
|
|
if (!changed_host) srip->cpu_time = elapsed_time;
|
2005-06-26 19:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->exit_status = rp->exit_status;
|
|
|
|
srip->app_version_num = rp->app_version_num;
|
2005-11-03 05:31:21 +00:00
|
|
|
if (rp->fpops_cumulative || rp->intops_cumulative) {
|
|
|
|
srip->claimed_credit = fpops_to_credit(rp->fpops_cumulative, rp->intops_cumulative);
|
|
|
|
} else if (rp->fpops_per_cpu_sec || rp->intops_per_cpu_sec) {
|
|
|
|
srip->claimed_credit = fpops_to_credit(
|
|
|
|
rp->fpops_per_cpu_sec*srip->cpu_time,
|
|
|
|
rp->intops_per_cpu_sec*srip->cpu_time
|
|
|
|
);
|
2005-06-24 04:34:45 +00:00
|
|
|
} else {
|
2007-01-12 17:42:29 +00:00
|
|
|
srip->claimed_credit = srip->cpu_time * reply.host.claimed_credit_per_cpu_sec;
|
2005-06-24 04:34:45 +00:00
|
|
|
}
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
|
2007-01-12 17:42:29 +00:00
|
|
|
"cpu %f cpcs %f, cc %f\n", srip->cpu_time, reply.host.claimed_credit_per_cpu_sec, srip->claimed_credit
|
2004-05-28 20:36:17 +00:00
|
|
|
);
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->server_state = RESULT_SERVER_STATE_OVER;
|
2004-01-30 22:25:33 +00:00
|
|
|
|
2006-01-05 06:42:45 +00:00
|
|
|
strlcpy(srip->stderr_out, rp->stderr_out, sizeof(srip->stderr_out));
|
|
|
|
strlcpy(srip->xml_doc_out, rp->xml_doc_out, sizeof(srip->xml_doc_out));
|
2004-01-30 22:25:33 +00:00
|
|
|
|
2004-04-11 20:20:32 +00:00
|
|
|
// look for exit status and app version in stderr_out
|
2004-03-31 06:07:17 +00:00
|
|
|
// (historical - can be deleted at some point)
|
2004-01-22 01:35:09 +00:00
|
|
|
//
|
2004-07-27 22:42:06 +00:00
|
|
|
parse_int(srip->stderr_out, "<exit_status>", srip->exit_status);
|
|
|
|
parse_int(srip->stderr_out, "<app_version>", srip->app_version_num);
|
2004-01-22 01:35:09 +00:00
|
|
|
|
2004-07-27 22:42:06 +00:00
|
|
|
if ((srip->client_state == RESULT_FILES_UPLOADED) && (srip->exit_status == 0)) {
|
|
|
|
srip->outcome = RESULT_OUTCOME_SUCCESS;
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
|
2004-02-15 18:34:10 +00:00
|
|
|
"[RESULT#%d %s]: setting outcome SUCCESS\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->id, srip->name
|
2004-02-15 18:34:10 +00:00
|
|
|
);
|
2005-02-26 00:24:37 +00:00
|
|
|
reply.got_good_result();
|
2004-01-30 22:25:33 +00:00
|
|
|
} else {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
|
2004-02-15 18:34:10 +00:00
|
|
|
"[RESULT#%d %s]: client_state %d exit_status %d; setting outcome ERROR\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->id, srip->name, srip->client_state, srip->exit_status
|
2004-02-15 18:34:10 +00:00
|
|
|
);
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->outcome = RESULT_OUTCOME_CLIENT_ERROR;
|
|
|
|
srip->validate_state = VALIDATE_STATE_INVALID;
|
2005-02-26 00:24:37 +00:00
|
|
|
reply.got_bad_result();
|
2004-01-30 22:25:33 +00:00
|
|
|
}
|
2005-05-17 21:08:48 +00:00
|
|
|
} // loop over all incoming results
|
2004-01-30 22:25:33 +00:00
|
|
|
|
2005-06-22 02:40:14 +00:00
|
|
|
// Update the result records
|
|
|
|
// (skip items that we previously marked to skip)
|
|
|
|
//
|
2004-07-06 18:30:22 +00:00
|
|
|
for (i=0; i<result_handler.results.size(); i++) {
|
2005-06-22 06:02:59 +00:00
|
|
|
SCHED_RESULT_ITEM& sri = result_handler.results[i];
|
|
|
|
if (sri.id == 0) continue;
|
|
|
|
retval = result_handler.update_result(sri);
|
2005-06-22 02:40:14 +00:00
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2005-06-22 02:40:14 +00:00
|
|
|
"[HOST#%d] [RESULT#%d %s] can't update result: %s\n",
|
2005-06-22 06:02:59 +00:00
|
|
|
reply.host.id, sri.id, sri.name, boinc_db.error_string()
|
2005-06-22 02:40:14 +00:00
|
|
|
);
|
2005-06-22 06:02:59 +00:00
|
|
|
} else {
|
|
|
|
reply.result_acks.push_back(std::string(sri.name));
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-07-27 22:42:06 +00:00
|
|
|
|
2005-06-22 02:40:14 +00:00
|
|
|
// set transition_time for the results' WUs
|
2004-07-21 23:48:56 +00:00
|
|
|
//
|
|
|
|
retval = result_handler.update_workunits();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2004-07-21 23:48:56 +00:00
|
|
|
"[HOST#%d] can't update WUs: %d\n",
|
|
|
|
reply.host.id, retval
|
|
|
|
);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-07-06 21:44:59 +00:00
|
|
|
|
2002-09-22 23:27:14 +00:00
|
|
|
// if the client has an old code sign public key,
|
2002-07-07 20:39:24 +00:00
|
|
|
// send it the new one, with a signature based on the old one.
|
|
|
|
// If they don't have a code sign key, send them one
|
|
|
|
//
|
|
|
|
void send_code_sign_key(
|
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, char* code_sign_key
|
|
|
|
) {
|
|
|
|
char* oldkey, *signature;
|
|
|
|
int i, retval;
|
|
|
|
char path[256];
|
|
|
|
|
2003-04-03 18:35:40 +00:00
|
|
|
if (strlen(sreq.code_sign_key)) {
|
2002-07-07 20:39:24 +00:00
|
|
|
if (strcmp(sreq.code_sign_key, code_sign_key)) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL, "received old code sign key\n");
|
2003-04-03 18:35:40 +00:00
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
// look for a signature file
|
|
|
|
//
|
|
|
|
for (i=0; ; i++) {
|
2002-10-04 20:35:56 +00:00
|
|
|
sprintf(path, "%s/old_key_%d", config.key_dir, i);
|
2002-07-07 20:39:24 +00:00
|
|
|
retval = read_file_malloc(path, oldkey);
|
|
|
|
if (retval) {
|
2005-01-31 22:19:03 +00:00
|
|
|
USER_MESSAGE um(
|
2004-08-04 15:30:52 +00:00
|
|
|
"You may have an outdated code verification key. "
|
|
|
|
"This may prevent you from accepting new executables. "
|
2005-01-31 22:19:03 +00:00
|
|
|
"If the problem persists, detach/attach the project. ",
|
|
|
|
"high"
|
2002-07-07 20:39:24 +00:00
|
|
|
);
|
2005-01-31 22:19:03 +00:00
|
|
|
reply.insert_message(um);
|
2002-07-07 20:39:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!strcmp(oldkey, sreq.code_sign_key)) {
|
2002-10-04 20:35:56 +00:00
|
|
|
sprintf(path, "%s/signature_%d", config.key_dir, i);
|
2002-07-07 20:39:24 +00:00
|
|
|
retval = read_file_malloc(path, signature);
|
|
|
|
if (retval) {
|
2005-01-31 22:19:03 +00:00
|
|
|
USER_MESSAGE um(
|
2004-08-04 15:30:52 +00:00
|
|
|
"You may have an outdated code verification key. "
|
|
|
|
"This may prevent you from accepting new executables. "
|
2005-01-31 22:19:03 +00:00
|
|
|
"If the problem persists, detach/attach the project. ",
|
|
|
|
"high"
|
2002-07-07 20:39:24 +00:00
|
|
|
);
|
2005-01-31 22:19:03 +00:00
|
|
|
reply.insert_message(um);
|
2002-07-07 20:39:24 +00:00
|
|
|
} else {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(reply.code_sign_key, code_sign_key);
|
|
|
|
safe_strcpy(reply.code_sign_key_signature, signature);
|
|
|
|
free(signature);
|
2002-07-07 20:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(oldkey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(reply.code_sign_key, code_sign_key);
|
2002-07-07 20:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-09 04:38:19 +00:00
|
|
|
// This routine examines the <min_core_client_version_announced> value
|
|
|
|
// from config.xml. If set, and the core client version is less than
|
|
|
|
// this version, send a warning to users to upgrade before deadline
|
|
|
|
// given in <min_core_client_upgrade_deadline> in Unix time(2) format
|
|
|
|
// expires.
|
|
|
|
//
|
|
|
|
void warn_user_if_core_client_upgrade_scheduled(
|
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply
|
|
|
|
) {
|
|
|
|
|
|
|
|
int core_ver;
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-02-09 04:38:19 +00:00
|
|
|
core_ver = sreq.core_client_major_version*100;
|
|
|
|
core_ver += sreq.core_client_minor_version;
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-02-09 04:38:19 +00:00
|
|
|
if (core_ver < config.min_core_client_version_announced) {
|
|
|
|
|
|
|
|
// time remaining in hours, before upgrade required
|
|
|
|
int remaining = config.min_core_client_upgrade_deadline-time(0);
|
|
|
|
remaining /= 3600;
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-02-09 04:38:19 +00:00
|
|
|
if (0 < remaining) {
|
|
|
|
char msg[512];
|
|
|
|
int days = remaining / 24;
|
|
|
|
int hours = remaining % 24;
|
|
|
|
sprintf(msg,
|
|
|
|
"Starting in %d days and %d hours, project will require a minimum "
|
2005-11-19 19:49:46 +00:00
|
|
|
"BOINC core client version of %d.%d.0. You are currently using "
|
|
|
|
"version %d.%d.%d; please upgrade before this time.",
|
2005-02-09 04:38:19 +00:00
|
|
|
days, hours,
|
2007-01-30 18:19:30 +00:00
|
|
|
config.min_core_client_version_announced / 100,
|
2005-02-09 04:38:19 +00:00
|
|
|
config.min_core_client_version_announced % 100,
|
|
|
|
sreq.core_client_major_version,
|
2005-11-19 19:49:46 +00:00
|
|
|
sreq.core_client_minor_version,
|
|
|
|
sreq.core_client_release
|
2005-02-09 04:38:19 +00:00
|
|
|
);
|
2005-02-10 06:21:58 +00:00
|
|
|
// make this low priority until three days are left. Then
|
|
|
|
// bump to high.
|
|
|
|
//
|
|
|
|
if (days<3) {
|
|
|
|
USER_MESSAGE um(msg, "high");
|
|
|
|
reply.insert_message(um);
|
|
|
|
} else {
|
|
|
|
USER_MESSAGE um(msg, "low");
|
|
|
|
reply.insert_message(um);
|
|
|
|
}
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_DEBUG,
|
2005-11-19 19:49:46 +00:00
|
|
|
"Sending warning: upgrade client %d.%d.%d within %d days %d hours\n",
|
2005-02-10 06:21:58 +00:00
|
|
|
sreq.core_client_major_version,
|
|
|
|
sreq.core_client_minor_version,
|
2005-11-19 19:49:46 +00:00
|
|
|
sreq.core_client_release,
|
2005-02-10 06:21:58 +00:00
|
|
|
days, hours
|
|
|
|
);
|
2005-02-09 04:38:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-19 18:24:24 +00:00
|
|
|
#ifdef EINSTEIN_AT_HOME
|
|
|
|
bool unacceptable_os(
|
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply
|
|
|
|
) {
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2005-03-19 18:24:24 +00:00
|
|
|
"OS version %s %s\n",
|
|
|
|
sreq.host.os_name, sreq.host.os_version
|
|
|
|
);
|
|
|
|
|
2007-01-30 18:19:30 +00:00
|
|
|
if (!strcmp(sreq.host.os_name, "Darwin") &&
|
|
|
|
(!strncmp(sreq.host.os_version, "5.", 2) ||
|
2005-03-19 18:24:24 +00:00
|
|
|
!strncmp(sreq.host.os_version, "6.", 2)
|
2007-01-30 18:19:30 +00:00
|
|
|
)
|
2005-03-19 18:24:24 +00:00
|
|
|
) {
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2005-03-19 18:24:24 +00:00
|
|
|
"Unacceptable OS %s %s\n",
|
|
|
|
sreq.host.os_name, sreq.host.os_version
|
|
|
|
);
|
2006-11-05 00:15:10 +00:00
|
|
|
USER_MESSAGE um(
|
|
|
|
"Project only supports MacOS Darwin versions 7.X and above",
|
|
|
|
"low"
|
|
|
|
);
|
2005-03-19 18:24:24 +00:00
|
|
|
reply.insert_message(um);
|
2006-11-05 00:15:10 +00:00
|
|
|
reply.set_delay(DELAY_UNACCEPTABLE_OS);
|
2005-03-19 18:24:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
bool unacceptable_os(
|
2007-01-30 18:19:30 +00:00
|
|
|
SCHEDULER_REQUEST& , SCHEDULER_REPLY&
|
2005-03-19 18:24:24 +00:00
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif // EINSTEIN_AT_HOME
|
2005-02-09 04:38:19 +00:00
|
|
|
|
2005-01-19 05:34:18 +00:00
|
|
|
bool wrong_core_client_version(
|
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply
|
|
|
|
) {
|
2005-01-31 22:19:03 +00:00
|
|
|
char msg[256];
|
2005-01-19 05:34:18 +00:00
|
|
|
bool wrong_version = false;
|
2005-07-02 19:01:44 +00:00
|
|
|
if (config.min_core_client_version) {
|
2005-01-19 05:34:18 +00:00
|
|
|
int major = config.min_core_client_version/100;
|
|
|
|
int minor = config.min_core_client_version % 100;
|
2005-07-04 21:47:53 +00:00
|
|
|
if (sreq.core_client_major_version < major ||
|
|
|
|
((sreq.core_client_major_version == major) && (sreq.core_client_minor_version < minor))) {
|
2005-01-19 05:34:18 +00:00
|
|
|
wrong_version = true;
|
2005-01-31 22:19:03 +00:00
|
|
|
sprintf(msg,
|
2005-11-19 19:49:46 +00:00
|
|
|
"Need version %d.%d or higher of the BOINC core client. You have %d.%d.",
|
2005-01-19 05:34:18 +00:00
|
|
|
major, minor,
|
|
|
|
sreq.core_client_major_version, sreq.core_client_minor_version
|
|
|
|
);
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2005-01-19 05:34:18 +00:00
|
|
|
"[HOST#%d] [auth %s] Wrong minor version from user: wanted %d, got %d\n",
|
|
|
|
sreq.hostid, sreq.authenticator,
|
|
|
|
minor, sreq.core_client_minor_version
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wrong_version) {
|
2005-01-31 22:19:03 +00:00
|
|
|
USER_MESSAGE um(msg, "low");
|
|
|
|
reply.insert_message(um);
|
2006-11-05 00:15:10 +00:00
|
|
|
reply.set_delay(DELAY_BAD_CLIENT_VERSION);
|
2002-12-02 04:29:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2002-10-22 21:44:16 +00:00
|
|
|
|
2003-09-21 22:33:43 +00:00
|
|
|
inline static const char* get_remote_addr() {
|
2003-07-29 01:05:13 +00:00
|
|
|
const char * r = getenv("REMOTE_ADDR");
|
|
|
|
return r ? r : "?.?.?.?";
|
2003-07-25 20:48:29 +00:00
|
|
|
}
|
|
|
|
|
2004-06-24 21:00:13 +00:00
|
|
|
void handle_msgs_from_host(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2004-01-08 00:27:59 +00:00
|
|
|
unsigned int i;
|
2004-06-22 22:56:50 +00:00
|
|
|
DB_MSG_FROM_HOST mfh;
|
2004-01-08 00:27:59 +00:00
|
|
|
int retval;
|
|
|
|
|
2004-06-24 21:00:13 +00:00
|
|
|
for (i=0; i<sreq.msgs_from_host.size(); i++) {
|
|
|
|
reply.send_msg_ack = true;
|
|
|
|
MSG_FROM_HOST_DESC& md = sreq.msgs_from_host[i];
|
2004-06-22 22:56:50 +00:00
|
|
|
mfh.clear();
|
|
|
|
mfh.create_time = time(0);
|
2004-07-06 04:10:51 +00:00
|
|
|
safe_strcpy(mfh.variety, md.variety);
|
2004-06-22 22:56:50 +00:00
|
|
|
mfh.hostid = reply.host.id;
|
|
|
|
mfh.handled = false;
|
2004-06-24 21:00:13 +00:00
|
|
|
safe_strcpy(mfh.xml, md.msg_text.c_str());
|
2004-07-06 04:10:51 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2006-01-24 21:38:03 +00:00
|
|
|
"got msg from host; variety %s \n",
|
|
|
|
mfh.variety
|
2004-07-06 04:10:51 +00:00
|
|
|
);
|
2004-06-22 22:56:50 +00:00
|
|
|
retval = mfh.insert();
|
2004-03-17 01:26:44 +00:00
|
|
|
if (retval) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
|
2004-06-24 21:00:13 +00:00
|
|
|
"[HOST#%d] message insert failed: %d\n",
|
2004-05-13 04:48:19 +00:00
|
|
|
reply.host.id, retval
|
2004-03-17 01:26:44 +00:00
|
|
|
);
|
2005-06-17 23:12:00 +00:00
|
|
|
reply.send_msg_ack = false;
|
|
|
|
|
|
|
|
// may as well return; if one insert failed, others will too
|
|
|
|
//
|
|
|
|
return;
|
2004-03-17 01:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
void handle_msgs_to_host(SCHEDULER_REPLY& reply) {
|
2004-06-22 22:56:50 +00:00
|
|
|
DB_MSG_TO_HOST mth;
|
2004-03-17 01:26:44 +00:00
|
|
|
char buf[256];
|
2004-07-10 00:11:20 +00:00
|
|
|
sprintf(buf, "where hostid = %d and handled = %d", reply.host.id, 0);
|
2004-06-22 22:56:50 +00:00
|
|
|
while (!mth.enumerate(buf)) {
|
|
|
|
reply.msgs_to_host.push_back(mth);
|
|
|
|
mth.handled = true;
|
|
|
|
mth.update();
|
2004-01-08 00:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
void process_request(
|
2002-07-07 20:39:24 +00:00
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss,
|
|
|
|
char* code_sign_key
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
|
|
|
PLATFORM* platform;
|
2002-06-21 18:31:32 +00:00
|
|
|
int retval;
|
2003-12-23 19:21:52 +00:00
|
|
|
double last_rpc_time;
|
2004-05-30 10:21:19 +00:00
|
|
|
struct tm *rpc_time_tm;
|
2004-05-30 10:16:57 +00:00
|
|
|
int last_rpc_dayofyear;
|
|
|
|
int current_rpc_dayofyear;
|
2004-07-04 18:55:31 +00:00
|
|
|
bool ok_to_send_work = true;
|
2004-07-24 00:09:28 +00:00
|
|
|
bool have_no_work;
|
2005-01-31 22:19:03 +00:00
|
|
|
char buf[256];
|
2005-05-03 21:50:51 +00:00
|
|
|
HOST initial_host;
|
2004-05-29 21:49:03 +00:00
|
|
|
|
2002-12-02 04:29:40 +00:00
|
|
|
// if different major version of BOINC, just send a message
|
|
|
|
//
|
2005-03-19 18:24:24 +00:00
|
|
|
if (wrong_core_client_version(sreq, reply) || unacceptable_os(sreq, reply)) {
|
2004-07-04 18:55:31 +00:00
|
|
|
ok_to_send_work = false;
|
|
|
|
|
|
|
|
// if no results, return without accessing DB
|
|
|
|
//
|
|
|
|
if (sreq.results.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2005-02-09 04:38:19 +00:00
|
|
|
} else {
|
|
|
|
warn_user_if_core_client_upgrade_scheduled(sreq, reply);
|
2004-07-04 18:55:31 +00:00
|
|
|
}
|
2005-03-19 18:24:24 +00:00
|
|
|
|
2005-03-13 20:10:03 +00:00
|
|
|
if (config.locality_scheduling) {
|
|
|
|
have_no_work = false;
|
|
|
|
} else {
|
|
|
|
lock_sema();
|
|
|
|
have_no_work = ss.no_work(g_pid);
|
|
|
|
unlock_sema();
|
|
|
|
}
|
|
|
|
|
2004-07-04 18:55:31 +00:00
|
|
|
// if there's no work, and client isn't returning results,
|
2004-07-15 18:54:17 +00:00
|
|
|
// this isn't an initial RPC,
|
2004-07-04 18:55:31 +00:00
|
|
|
// and client is requesting work, return without accessing DB
|
|
|
|
//
|
2005-03-13 20:10:03 +00:00
|
|
|
if (
|
|
|
|
config.nowork_skip
|
|
|
|
&& (sreq.work_req_seconds > 0)
|
2004-07-24 00:09:28 +00:00
|
|
|
&& have_no_work
|
2004-07-04 18:55:31 +00:00
|
|
|
&& (sreq.results.size() == 0)
|
2004-07-15 18:54:17 +00:00
|
|
|
&& (sreq.hostid != 0)
|
2004-07-04 18:55:31 +00:00
|
|
|
) {
|
2005-01-31 22:19:03 +00:00
|
|
|
USER_MESSAGE um("No work available", "low");
|
|
|
|
reply.insert_message(um);
|
2006-11-05 00:15:10 +00:00
|
|
|
reply.set_delay(DELAY_NO_WORK_SKIP);
|
2004-08-12 13:36:05 +00:00
|
|
|
if (!config.msg_to_host) {
|
2004-08-05 22:14:23 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL, "No work - skipping DB access\n"
|
2004-08-05 22:14:23 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2004-05-03 19:30:01 +00:00
|
|
|
}
|
2003-06-11 23:36:45 +00:00
|
|
|
|
2004-07-24 00:09:28 +00:00
|
|
|
// FROM HERE ON DON'T RETURN; goto leave instead
|
2004-08-12 13:36:05 +00:00
|
|
|
// because we've tagged an entry in the work array with our process ID
|
2004-07-24 00:09:28 +00:00
|
|
|
|
2004-04-30 18:26:20 +00:00
|
|
|
// now open the database
|
|
|
|
//
|
|
|
|
retval = open_database();
|
|
|
|
if (retval) {
|
2005-06-02 21:38:20 +00:00
|
|
|
send_message("Server can't open database", 3600, false);
|
2004-07-24 00:09:28 +00:00
|
|
|
goto leave;
|
2004-04-30 18:26:20 +00:00
|
|
|
}
|
|
|
|
|
2002-08-26 22:57:17 +00:00
|
|
|
retval = authenticate_user(sreq, reply);
|
2004-07-24 00:09:28 +00:00
|
|
|
if (retval) goto leave;
|
2004-01-10 01:08:50 +00:00
|
|
|
if (reply.user.id == 0) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "No user ID!\n");
|
2004-01-10 01:08:50 +00:00
|
|
|
}
|
2005-05-03 21:50:51 +00:00
|
|
|
initial_host = reply.host;
|
2005-05-12 00:32:03 +00:00
|
|
|
reply.host.rpc_seqno = sreq.rpc_seqno;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-06-02 00:02:01 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2005-11-19 19:49:46 +00:00
|
|
|
"Processing request from [USER#%d] [HOST#%d] [IP %s] [RPC#%d] core client version %d.%d.%d\n",
|
2004-06-02 00:02:01 +00:00
|
|
|
reply.user.id, reply.host.id, get_remote_addr(), sreq.rpc_seqno,
|
2005-11-19 19:49:46 +00:00
|
|
|
sreq.core_client_major_version, sreq.core_client_minor_version,
|
|
|
|
sreq.core_client_release
|
2004-06-02 00:02:01 +00:00
|
|
|
);
|
|
|
|
++log_messages;
|
|
|
|
|
2005-06-03 21:39:38 +00:00
|
|
|
if (strlen(config.sched_lockfile_dir)) {
|
|
|
|
int pid_with_lock = lock_sched(reply);
|
|
|
|
if (pid_with_lock > 0) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
|
2005-06-03 21:39:38 +00:00
|
|
|
"Another scheduler instance [PID=%d] is running for this host\n",
|
|
|
|
pid_with_lock
|
|
|
|
);
|
|
|
|
} else if (pid_with_lock) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
|
2005-06-03 21:39:38 +00:00
|
|
|
"Error acquiring lock for [HOST#%d]\n", reply.host.id
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (pid_with_lock) {
|
|
|
|
send_message(
|
|
|
|
"Another scheduler instance is running for this host",
|
|
|
|
60, false
|
|
|
|
);
|
|
|
|
goto leave;
|
|
|
|
}
|
2005-05-17 05:55:24 +00:00
|
|
|
}
|
|
|
|
|
2003-12-23 19:21:52 +00:00
|
|
|
last_rpc_time = reply.host.rpc_time;
|
2004-05-30 10:16:57 +00:00
|
|
|
rpc_time_tm = localtime((const time_t*)&reply.host.rpc_time);
|
|
|
|
last_rpc_dayofyear = rpc_time_tm->tm_yday;
|
2004-05-29 21:21:35 +00:00
|
|
|
|
2004-05-29 21:56:21 +00:00
|
|
|
reply.host.rpc_time = time(0);
|
2004-05-30 10:21:19 +00:00
|
|
|
rpc_time_tm = localtime((const time_t*)&reply.host.rpc_time);
|
2004-05-30 10:16:57 +00:00
|
|
|
current_rpc_dayofyear = rpc_time_tm->tm_yday;
|
2004-05-29 21:49:03 +00:00
|
|
|
|
2005-03-19 18:24:24 +00:00
|
|
|
if (config.daily_result_quota) {
|
|
|
|
if (reply.host.max_results_day <= 0 || reply.host.max_results_day > config.daily_result_quota) {
|
|
|
|
reply.host.max_results_day = config.daily_result_quota;
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
|
|
|
|
"[HOST#%d] Initializing max_results_day to %d\n",
|
|
|
|
reply.host.id, config.daily_result_quota
|
|
|
|
);
|
2005-03-19 18:24:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-30 10:16:57 +00:00
|
|
|
if (last_rpc_dayofyear != current_rpc_dayofyear) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
|
|
|
|
"[HOST#%d] Resetting nresults_today\n", reply.host.id
|
|
|
|
);
|
2004-05-27 18:13:00 +00:00
|
|
|
reply.host.nresults_today = 0;
|
|
|
|
}
|
|
|
|
retval = modify_host_struct(sreq, reply.host);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// look up the client's platform in the DB
|
|
|
|
//
|
2002-05-24 04:29:10 +00:00
|
|
|
platform = ss.lookup_platform(sreq.platform_name);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!platform) {
|
2005-01-31 22:19:03 +00:00
|
|
|
sprintf(buf, "platform '%s' not found", sreq.platform_name);
|
|
|
|
USER_MESSAGE um(buf, "low");
|
|
|
|
reply.insert_message(um);
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL, "[HOST#%d] platform '%s' not found\n",
|
2003-06-14 17:46:08 +00:00
|
|
|
reply.host.id, sreq.platform_name
|
|
|
|
);
|
2006-11-05 00:15:10 +00:00
|
|
|
reply.set_delay(DELAY_PLATFORM_UNSUPPORTED);
|
2004-07-24 00:09:28 +00:00
|
|
|
goto leave;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2002-09-27 20:36:03 +00:00
|
|
|
handle_global_prefs(sreq, reply);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
handle_results(sreq, reply);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2005-07-28 10:13:30 +00:00
|
|
|
if (config.resend_lost_results && sreq.have_other_results_list) {
|
|
|
|
if (resend_lost_work(sreq, reply, *platform, ss)) {
|
2005-07-28 09:29:12 +00:00
|
|
|
ok_to_send_work = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-31 23:09:21 +00:00
|
|
|
// if last RPC was within config.min_sendwork_interval, don't send work
|
2003-12-23 19:21:52 +00:00
|
|
|
//
|
2004-07-24 00:09:28 +00:00
|
|
|
if (!have_no_work && ok_to_send_work && sreq.work_req_seconds > 0) {
|
2004-05-13 04:48:19 +00:00
|
|
|
if (config.min_sendwork_interval) {
|
|
|
|
double diff = dtime() - last_rpc_time;
|
|
|
|
if (diff < config.min_sendwork_interval) {
|
2004-07-04 18:55:31 +00:00
|
|
|
ok_to_send_work = false;
|
2004-05-13 04:48:19 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2006-04-11 19:54:27 +00:00
|
|
|
"Not sending work - last request too recent: %f\n", diff
|
2004-05-13 04:48:19 +00:00
|
|
|
);
|
2005-01-31 22:19:03 +00:00
|
|
|
sprintf(buf,
|
2006-04-11 19:54:27 +00:00
|
|
|
"Not sending work - last request too recent: %d sec", (int)diff
|
2004-05-13 04:48:19 +00:00
|
|
|
);
|
2005-01-31 22:19:03 +00:00
|
|
|
USER_MESSAGE um(buf, "low");
|
|
|
|
reply.insert_message(um);
|
2005-06-01 22:41:41 +00:00
|
|
|
|
|
|
|
// the 1.01 is in case client's clock
|
|
|
|
// is slightly faster than ours
|
|
|
|
//
|
|
|
|
reply.set_delay(1.01*config.min_sendwork_interval);
|
2004-05-13 04:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-04 18:55:31 +00:00
|
|
|
if (ok_to_send_work) {
|
2004-05-13 04:48:19 +00:00
|
|
|
send_work(sreq, reply, *platform, ss);
|
2003-12-31 23:09:21 +00:00
|
|
|
}
|
2003-12-23 19:21:52 +00:00
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
|
|
|
|
send_code_sign_key(sreq, reply, code_sign_key);
|
2004-01-08 00:27:59 +00:00
|
|
|
|
2004-08-18 01:49:46 +00:00
|
|
|
handle_msgs_from_host(sreq, reply);
|
2004-06-24 21:00:13 +00:00
|
|
|
if (config.msg_to_host) {
|
2005-02-16 23:17:43 +00:00
|
|
|
handle_msgs_to_host(reply);
|
2004-03-17 01:26:44 +00:00
|
|
|
}
|
2004-05-27 18:13:00 +00:00
|
|
|
|
2005-05-03 21:50:51 +00:00
|
|
|
update_host_record(initial_host, reply.host, reply.user);
|
2004-07-24 00:09:28 +00:00
|
|
|
|
|
|
|
leave:
|
|
|
|
if (!have_no_work) {
|
|
|
|
ss.restore_work(g_pid);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2005-05-17 21:08:48 +00:00
|
|
|
void debug_sched(
|
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& sreply, const char *trigger
|
|
|
|
) {
|
2005-01-31 11:45:45 +00:00
|
|
|
char tmpfilename[256];
|
|
|
|
FILE *fp;
|
|
|
|
|
2005-01-31 22:19:03 +00:00
|
|
|
if (!boinc_file_exists(trigger)) {
|
|
|
|
return;
|
|
|
|
}
|
2005-01-31 11:45:45 +00:00
|
|
|
|
|
|
|
sprintf(tmpfilename, "sched_reply_%06d_%06d", sreq.hostid, sreq.rpc_seqno);
|
2005-02-02 18:13:00 +00:00
|
|
|
// use _XXXXXX if you want random filenames rather than
|
|
|
|
// deterministic mkstemp(tmpfilename);
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-01-31 11:45:45 +00:00
|
|
|
fp=fopen(tmpfilename, "w");
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-01-31 11:45:45 +00:00
|
|
|
if (!fp) {
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2005-01-31 22:19:03 +00:00
|
|
|
"Found %s, but can't open %s\n", trigger, tmpfilename
|
|
|
|
);
|
2005-01-31 11:45:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-01-31 11:45:45 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_DEBUG,
|
2005-01-31 22:19:03 +00:00
|
|
|
"Found %s, so writing %s\n", trigger, tmpfilename
|
|
|
|
);
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-01-31 11:45:45 +00:00
|
|
|
sreply.write(fp);
|
|
|
|
fclose(fp);
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-01-31 16:10:49 +00:00
|
|
|
sprintf(tmpfilename, "sched_request_%06d_%06d", sreq.hostid, sreq.rpc_seqno);
|
2005-01-31 22:19:03 +00:00
|
|
|
fp=fopen(tmpfilename, "w");
|
|
|
|
|
2005-01-31 16:10:49 +00:00
|
|
|
if (!fp) {
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2005-01-31 22:19:03 +00:00
|
|
|
"Found %s, but can't open %s\n", trigger, tmpfilename
|
|
|
|
);
|
2005-01-31 16:10:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-01-31 22:19:03 +00:00
|
|
|
|
2005-01-31 16:10:49 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_DEBUG,
|
2005-01-31 22:19:03 +00:00
|
|
|
"Found %s, so writing %s\n", trigger, tmpfilename
|
|
|
|
);
|
|
|
|
|
2005-01-31 16:10:49 +00:00
|
|
|
sreq.write(fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
2005-01-31 11:45:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
void handle_request(
|
|
|
|
FILE* fin, FILE* fout, SCHED_SHMEM& ss, char* code_sign_key
|
|
|
|
) {
|
2002-04-30 22:22:54 +00:00
|
|
|
SCHEDULER_REQUEST sreq;
|
|
|
|
SCHEDULER_REPLY sreply;
|
2002-08-20 00:30:13 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
memset(&sreq, 0, sizeof(sreq));
|
2004-03-23 01:44:13 +00:00
|
|
|
|
2004-03-20 07:57:34 +00:00
|
|
|
if (sreq.parse(fin) == 0){
|
2004-03-23 01:44:13 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2005-12-06 23:00:44 +00:00
|
|
|
"Handling request: IP %s, auth %s, host %d, platform %s, version %d.%d.%d, RSF %f\n",
|
2004-08-05 20:58:26 +00:00
|
|
|
get_remote_addr(), sreq.authenticator, sreq.hostid, sreq.platform_name,
|
2005-11-19 19:49:46 +00:00
|
|
|
sreq.core_client_major_version, sreq.core_client_minor_version,
|
2005-12-06 23:00:44 +00:00
|
|
|
sreq.core_client_release,
|
|
|
|
sreq.resource_share_fraction
|
2004-03-23 01:44:13 +00:00
|
|
|
);
|
|
|
|
process_request(sreq, sreply, ss, code_sign_key);
|
2004-03-20 07:57:34 +00:00
|
|
|
} else {
|
2005-03-21 19:57:44 +00:00
|
|
|
// BOINC scheduler requests use method POST.
|
|
|
|
// So method GET means that someone is trying a browser.
|
|
|
|
//
|
2005-03-19 18:24:24 +00:00
|
|
|
char *rm=getenv("REQUEST_METHOD");
|
2005-03-21 19:57:44 +00:00
|
|
|
if (rm && !strcmp(rm, "GET")) {
|
|
|
|
sreply.probable_user_browser=true;
|
|
|
|
}
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2004-03-23 03:59:32 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_NORMAL,
|
2005-11-19 19:49:46 +00:00
|
|
|
"Incomplete request received %sfrom IP %s, auth %s, platform %s, version %d.%d.%d\n",
|
2005-03-19 18:24:24 +00:00
|
|
|
sreply.probable_user_browser?"(probably a browser) ":"",
|
2004-05-13 04:48:19 +00:00
|
|
|
get_remote_addr(), sreq.authenticator, sreq.platform_name,
|
2005-11-19 19:49:46 +00:00
|
|
|
sreq.core_client_major_version, sreq.core_client_minor_version,
|
|
|
|
sreq.core_client_release
|
2004-03-23 01:44:13 +00:00
|
|
|
);
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-01-31 22:19:03 +00:00
|
|
|
USER_MESSAGE um("Incomplete request received.", "low");
|
|
|
|
sreply.insert_message(um);
|
2004-05-13 04:48:19 +00:00
|
|
|
sreply.nucleus_only = true;
|
2004-03-20 07:57:34 +00:00
|
|
|
}
|
2005-03-19 18:24:24 +00:00
|
|
|
|
|
|
|
#ifdef EINSTEIN_AT_HOME
|
|
|
|
// for testing
|
|
|
|
if (sreply.user.id==3) {
|
|
|
|
USER_MESSAGE um("THIS IS A SHORT MESSAGE. \n AND ANOTHER", "high");
|
|
|
|
// USER_MESSAGE um("THIS IS A VERY LONG TEST MESSAGE. THIS IS A VERY LONG TEST MESSAGE. \n"
|
2005-04-07 20:46:25 +00:00
|
|
|
// "THIS IS A VERY LONG TEST MESSAGE. THIS IS A VERY LONG TEST MESSAGE.", "low");
|
2005-03-19 18:24:24 +00:00
|
|
|
sreply.insert_message(um);
|
|
|
|
// USER_MESSAGE um2("THIS IS A VERY LONG TEST MESSAGE2. THIS IS A VERY LONG TEST MESSAGE. \n"
|
2005-04-07 20:46:25 +00:00
|
|
|
// "THIS IS A VERY LONG TEST MESSAGE. THIS IS A VERY LONG TEST MESSAGE.", "high");
|
2005-03-19 18:24:24 +00:00
|
|
|
// sreply.insert_message(um2);
|
|
|
|
}
|
2006-05-24 19:00:12 +00:00
|
|
|
|
|
|
|
// delete useless files
|
|
|
|
int num_useless = sreq.files_not_needed.size();
|
|
|
|
int i;
|
|
|
|
for (i=0; i<num_useless; i++) {
|
|
|
|
char buf[256];
|
2007-01-30 18:19:30 +00:00
|
|
|
FILE_INFO& fi = sreq.files_not_needed[i];
|
|
|
|
sreply.file_deletes.push_back(fi);
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::MSG_DEBUG,
|
|
|
|
"[HOST#%d]: delete file %s (not needed)\n", sreply.host.id, fi.name
|
2006-05-24 19:00:12 +00:00
|
|
|
);
|
2007-01-30 18:19:30 +00:00
|
|
|
sprintf(buf, "BOINC will delete file %s (no longer needed)", fi.name);
|
|
|
|
USER_MESSAGE um(buf, "low");
|
|
|
|
sreply.insert_message(um);
|
2006-05-24 19:00:12 +00:00
|
|
|
}
|
2005-03-19 18:24:24 +00:00
|
|
|
#endif
|
2006-05-24 19:00:12 +00:00
|
|
|
|
2005-01-31 11:45:45 +00:00
|
|
|
// if we got no work, and we have no file space, delete some files
|
2005-05-17 21:08:48 +00:00
|
|
|
//
|
2005-02-02 18:13:00 +00:00
|
|
|
if (sreply.results.size()==0 && (sreply.wreq.insufficient_disk || sreply.wreq.disk_available<0)) {
|
2005-02-06 21:26:21 +00:00
|
|
|
// try to delete a file to make more space.
|
2005-02-13 15:54:24 +00:00
|
|
|
// Also give some hints to the user about what's going wrong
|
|
|
|
// (lack of disk space).
|
|
|
|
//
|
2005-02-02 18:13:00 +00:00
|
|
|
delete_file_from_host(sreq, sreply);
|
2005-01-31 11:45:45 +00:00
|
|
|
}
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2005-03-19 18:24:24 +00:00
|
|
|
// write all messages to log file
|
|
|
|
for (unsigned int i=0; i<sreply.messages.size(); i++) {
|
|
|
|
USER_MESSAGE um = sreply.messages[i];
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
|
2005-03-19 18:24:24 +00:00
|
|
|
"[HOST#%d] MSG(%4s) %s \n", sreply.host.id, um.priority.c_str(), um.message.c_str()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_sched(sreq, sreply, "../debug_sched");
|
|
|
|
|
|
|
|
#ifdef EINSTEIN_AT_HOME
|
2005-02-02 18:13:00 +00:00
|
|
|
// You can call debug_sched() for whatever situation is of
|
|
|
|
// interest to you. It won't do anything unless you create
|
|
|
|
// (touch) the file 'debug_sched' in the project root directory.
|
|
|
|
//
|
2005-02-06 21:26:21 +00:00
|
|
|
if (sreply.results.size()==0 && sreply.hostid && sreq.work_req_seconds>1.0) {
|
2005-02-02 18:13:00 +00:00
|
|
|
debug_sched(sreq, sreply, "../debug_sched");
|
2005-04-18 18:12:21 +00:00
|
|
|
} else if (max_allowable_disk(sreq, sreply)<0 || (sreply.wreq.insufficient_disk || sreply.wreq.disk_available<0)) {
|
2005-01-31 19:34:43 +00:00
|
|
|
debug_sched(sreq, sreply, "../debug_sched");
|
2005-04-07 20:46:25 +00:00
|
|
|
}
|
2005-01-31 19:34:43 +00:00
|
|
|
#endif
|
2007-01-30 18:19:30 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
sreply.write(fout);
|
2005-06-03 21:39:38 +00:00
|
|
|
|
|
|
|
if (strlen(config.sched_lockfile_dir)) {
|
|
|
|
unlock_sched(sreply);
|
2005-05-17 05:55:24 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_2ac231f9de = "$Id$";
|