2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-05-17 22:33:57 +00:00
|
|
|
// command-line version of the BOINC core client
|
|
|
|
|
2002-10-13 21:51:23 +00:00
|
|
|
// This file contains no GUI-related code,
|
|
|
|
// and is not included in the source code for Mac or Win GUI clients
|
2002-08-09 21:43:19 +00:00
|
|
|
|
2002-11-18 23:09:11 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <unistd.h>
|
2002-11-18 23:09:11 +00:00
|
|
|
#endif
|
2002-10-07 02:07:22 +00:00
|
|
|
|
2002-10-13 21:51:23 +00:00
|
|
|
#include "boinc_api.h"
|
2002-09-26 05:57:10 +00:00
|
|
|
#include "account.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
#include "error_numbers.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "file_names.h"
|
|
|
|
#include "log_flags.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "prefs.h"
|
2002-06-06 18:50:12 +00:00
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-12-17 19:00:43 +00:00
|
|
|
// Display a message to the user.
|
|
|
|
// Depending on the priority, the message may be more or less obtrusive
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2003-03-06 17:42:49 +00:00
|
|
|
void show_message(PROJECT *p, char* message, int priority) {
|
|
|
|
const char* proj = p?p->project_name:"BOINC";
|
|
|
|
switch (priority) {
|
|
|
|
case MSG_ERROR:
|
2003-03-10 21:27:28 +00:00
|
|
|
fprintf(stderr, "%s [%s] %s\n", timestamp(), proj, message);
|
2003-03-06 17:42:49 +00:00
|
|
|
default:
|
2003-03-10 21:27:28 +00:00
|
|
|
printf("%s [%s] %s\n", timestamp(), proj, message);
|
2002-05-17 22:33:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
// Prompt user for project URL and authenticator,
|
2002-09-26 05:57:10 +00:00
|
|
|
// and create an account file
|
2002-06-21 06:52:47 +00:00
|
|
|
//
|
2002-12-19 22:43:38 +00:00
|
|
|
int add_new_project() {
|
2002-06-21 06:52:47 +00:00
|
|
|
char master_url[256];
|
|
|
|
char authenticator[256];
|
|
|
|
|
|
|
|
printf("Enter the URL of the project: ");
|
|
|
|
scanf("%s", master_url);
|
|
|
|
printf(
|
|
|
|
"You should have already registered with the project\n"
|
2002-12-11 19:33:43 +00:00
|
|
|
"and received an account key by email.\n"
|
2003-02-20 00:58:55 +00:00
|
|
|
"Paste the account key here: "
|
2002-06-21 06:52:47 +00:00
|
|
|
);
|
|
|
|
scanf("%s", authenticator);
|
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
write_account_file(master_url, authenticator);
|
2002-06-21 06:52:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-08-12 23:18:47 +00:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
int retval;
|
2003-02-26 00:47:57 +00:00
|
|
|
double dt;
|
2002-07-29 00:39:45 +00:00
|
|
|
|
2002-08-12 23:18:47 +00:00
|
|
|
setbuf(stdout, 0);
|
2002-12-16 23:51:33 +00:00
|
|
|
if (lock_file(LOCK_FILE_NAME)) {
|
|
|
|
fprintf(stderr, "Another copy of BOINC is already running\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-08-12 23:18:47 +00:00
|
|
|
read_log_flags();
|
2002-07-15 05:34:32 +00:00
|
|
|
gstate.parse_cmdline(argc, argv);
|
2002-12-19 00:13:46 +00:00
|
|
|
gstate.parse_env_vars();
|
2002-08-12 23:18:47 +00:00
|
|
|
retval = gstate.init();
|
|
|
|
if (retval) exit(retval);
|
2002-04-30 22:22:54 +00:00
|
|
|
while (1) {
|
2002-07-15 05:34:32 +00:00
|
|
|
if (!gstate.do_something()) {
|
2003-03-03 19:13:16 +00:00
|
|
|
dt = dtime();
|
2003-02-18 03:31:47 +00:00
|
|
|
gstate.net_sleep(1.);
|
2003-03-03 19:13:16 +00:00
|
|
|
dt = dtime() - dt;
|
2003-02-26 00:47:57 +00:00
|
|
|
if (log_flags.time_debug) printf("SLEPT %f SECONDS\n", dt);
|
2002-04-30 22:22:54 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
2002-08-12 23:18:47 +00:00
|
|
|
|
|
|
|
if (gstate.time_to_exit()) {
|
2002-07-05 05:33:40 +00:00
|
|
|
printf("time to exit\n");
|
2002-07-01 18:16:31 +00:00
|
|
|
break;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-07 01:02:08 +00:00
|
|
|
gstate.cleanup_and_exit();
|
2002-06-21 06:52:47 +00:00
|
|
|
return 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|