2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-11-12 18:11:31 +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-11-23 00:08:49 +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.
|
2003-10-19 01:48:32 +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
|
2003-10-19 01:48:32 +00:00
|
|
|
|
2004-01-30 22:19:19 +00:00
|
|
|
// command-line parsing, and handling of 1-time actions
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2005-04-15 21:05:58 +00:00
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2003-10-19 01:48:32 +00:00
|
|
|
#include <stdio.h>
|
2005-04-15 21:05:58 +00:00
|
|
|
#include <unistd.h>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2003-10-19 01:48:32 +00:00
|
|
|
|
2005-03-08 03:50:11 +00:00
|
|
|
#include "main.h"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2004-04-07 06:51:42 +00:00
|
|
|
#include "util.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
2003-10-19 01:48:32 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
|
|
|
|
static void print_options(char* prog) {
|
|
|
|
printf(
|
|
|
|
"Usage: %s [options]\n"
|
2007-02-12 23:53:16 +00:00
|
|
|
" --help show options\n"
|
|
|
|
" --version show version info\n"
|
|
|
|
" --exit_when_idle Get/process/report work, then exit\n"
|
|
|
|
" --show_projects show attached projects\n"
|
|
|
|
" --return_results_immediately contact server when have results\n"
|
|
|
|
" --detach_project <URL> detach from a project\n"
|
|
|
|
" --reset_project <URL> reset (clear) a project\n"
|
|
|
|
" --attach_project <URL> <key> attach to a project\n"
|
|
|
|
" --update_prefs <URL> contact a project to update preferences\n"
|
|
|
|
" --run_cpu_benchmarks run the CPU benchmarks\n"
|
|
|
|
" --check_all_logins for idle detection, check remote logins\n too"
|
|
|
|
" --allow_remote_gui_rpc allow remote GUI RPC connections\n"
|
|
|
|
" --gui_rpc_port port for GUI RPCs\n"
|
|
|
|
" --redirectio redirect stdout and stderr to log files\n"
|
|
|
|
" --detach detach from console (Windows)\n"
|
|
|
|
" --dir <path> use given dir as BOINC home\n"
|
|
|
|
" --no_gui_rpc don't allow GUI RPC, don't make socket\n"
|
|
|
|
" --daemon run as daemon (Unix)\n"
|
|
|
|
" --insecure disable BOINC security users and permissions (Unix, Linux)\n"
|
|
|
|
" --launched_by_manager core client was launched by Manager\n"
|
2005-07-23 08:10:39 +00:00
|
|
|
,
|
2003-10-19 01:48:32 +00:00
|
|
|
prog
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the command line arguments passed to the client
|
|
|
|
// NOTE: init() has not been called at this point
|
|
|
|
// (i.e. client_state.xml has not been parsed)
|
2005-03-23 06:26:19 +00:00
|
|
|
// So just record the args here.
|
|
|
|
// The actions get done in do_cmdline_actions()
|
2003-10-19 01:48:32 +00:00
|
|
|
//
|
2007-02-12 23:53:16 +00:00
|
|
|
// Check for both -X (deprecated) and --X
|
|
|
|
//
|
2004-01-19 20:53:40 +00:00
|
|
|
#define ARGX2(s1,s2) (!strcmp(argv[i], s1)||!strcmp(argv[i], s2))
|
|
|
|
#define ARG(S) ARGX2("-"#S, "--"#S)
|
|
|
|
|
2003-10-19 01:48:32 +00:00
|
|
|
void CLIENT_STATE::parse_cmdline(int argc, char** argv) {
|
|
|
|
int i;
|
|
|
|
bool show_options = false;
|
|
|
|
|
|
|
|
for (i=1; i<argc; i++) {
|
2003-11-23 00:08:49 +00:00
|
|
|
if (ARG(exit_when_idle)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
exit_when_idle = true;
|
2004-06-15 00:46:59 +00:00
|
|
|
} else if (ARG(check_all_logins)) {
|
|
|
|
check_all_logins = true;
|
2005-01-07 20:47:40 +00:00
|
|
|
} else if (ARG(daemon)) {
|
|
|
|
executing_as_daemon = true;
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(return_results_immediately)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
return_results_immediately = true;
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(skip_cpu_benchmarks)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
skip_cpu_benchmarks = true;
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(exit_after_app_start)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else exit_after_app_start_secs = atoi(argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(file_xfer_giveup_period)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else file_xfer_giveup_period = atoi(argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(saver)) {
|
2003-10-22 18:39:22 +00:00
|
|
|
started_by_screensaver = true;
|
2003-10-19 01:48:32 +00:00
|
|
|
} else if (!strncmp(argv[i], "-psn_", strlen("-psn_"))) {
|
|
|
|
// ignore -psn argument on Mac OS X
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(exit_before_upload)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
exit_before_upload = true;
|
|
|
|
// The following are only used for testing to alter scheduler/file transfer
|
|
|
|
// backoff rates
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(master_fetch_period)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else master_fetch_period = atoi(argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(retry_cap)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else retry_cap = atoi(argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(master_fetch_retry_cap)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else master_fetch_retry_cap = atoi(argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(master_fetch_interval)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else master_fetch_interval = atoi(argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(sched_retry_delay_min)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else sched_retry_delay_min = atoi(argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(sched_retry_delay_max)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else sched_retry_delay_max = atoi(argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(pers_retry_delay_min)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else pers_retry_delay_min = atoi(argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(pers_retry_delay_max)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else pers_retry_delay_max = atoi(argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(pers_giveup)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else pers_giveup = atoi(argv[++i]);
|
2005-12-01 08:07:07 +00:00
|
|
|
} else if (ARG(detach_phase_two)) {
|
|
|
|
detach_console = true;
|
2003-10-19 01:48:32 +00:00
|
|
|
|
|
|
|
// the above options are private (i.e. not shown by -help)
|
|
|
|
// Public options follow.
|
|
|
|
// NOTE: if you change or add anything, make the same chane
|
|
|
|
// in show_options() (above) and in doc/client.php
|
|
|
|
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(show_projects)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
show_projects = true;
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(detach_project)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else strcpy(detach_project_url, argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(reset_project)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else strcpy(reset_project_url, argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(update_prefs)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else strcpy(update_prefs_url, argv[++i]);
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(run_cpu_benchmarks)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
run_cpu_benchmarks = true;
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(attach_project)) {
|
2005-06-09 21:37:34 +00:00
|
|
|
if (i >= argc-2) {
|
2005-03-23 06:26:19 +00:00
|
|
|
show_options = true;
|
|
|
|
} else {
|
2005-04-19 22:22:02 +00:00
|
|
|
strcpy(attach_project_url, argv[++i]);
|
|
|
|
strcpy(attach_project_auth, argv[++i]);
|
2005-03-23 06:26:19 +00:00
|
|
|
}
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(version)) {
|
2004-07-13 15:07:42 +00:00
|
|
|
printf(BOINC_VERSION_STRING " " HOSTTYPE "\n");
|
2003-10-19 01:48:32 +00:00
|
|
|
exit(0);
|
2004-06-11 00:04:51 +00:00
|
|
|
} else if (ARG(allow_remote_gui_rpc)) {
|
|
|
|
allow_remote_gui_rpc = true;
|
2005-12-13 08:04:57 +00:00
|
|
|
} else if (ARG(gui_rpc_port)) {
|
|
|
|
cmdline_gui_rpc_port = atoi(argv[++i]);
|
2005-03-08 03:50:11 +00:00
|
|
|
} else if (ARG(redirectio)) {
|
|
|
|
redirect_io = true;
|
2003-11-23 00:08:49 +00:00
|
|
|
} else if (ARG(help)) {
|
2003-10-19 01:48:32 +00:00
|
|
|
print_options(argv[0]);
|
|
|
|
exit(0);
|
2005-04-15 21:05:58 +00:00
|
|
|
} else if (ARG(dir)) {
|
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
if (chdir(argv[++i])) {
|
|
|
|
perror("chdir");
|
|
|
|
}
|
2005-07-23 08:10:39 +00:00
|
|
|
} else if (ARG(no_gui_rpc)) {
|
|
|
|
no_gui_rpc = true;
|
2006-08-01 12:36:19 +00:00
|
|
|
} else if (ARG(insecure)) {
|
|
|
|
g_use_sandbox = false;
|
2006-12-13 00:54:27 +00:00
|
|
|
} else if (ARG(launched_by_manager)) {
|
|
|
|
launched_by_manager = true;
|
2003-10-19 01:48:32 +00:00
|
|
|
} else {
|
|
|
|
printf("Unknown option: %s\n", argv[i]);
|
|
|
|
show_options = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (show_options) {
|
|
|
|
print_options(argv[0]);
|
2003-11-23 00:08:49 +00:00
|
|
|
exit(1);
|
2003-10-19 01:48:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-19 20:53:40 +00:00
|
|
|
#undef ARG
|
|
|
|
#undef ARGX2
|
|
|
|
|
2003-10-19 01:48:32 +00:00
|
|
|
void CLIENT_STATE::parse_env_vars() {
|
|
|
|
char *p, temp[256];
|
|
|
|
|
2004-07-13 18:35:47 +00:00
|
|
|
p = getenv("HTTP_PROXY");
|
|
|
|
if (p && strlen(p) > 0) {
|
2004-09-26 04:16:52 +00:00
|
|
|
proxy_info.use_http_proxy = true;
|
|
|
|
parse_url(p, proxy_info.http_server_name, proxy_info.http_server_port, temp);
|
2004-07-13 18:35:47 +00:00
|
|
|
}
|
|
|
|
p = getenv("HTTP_USER_NAME");
|
|
|
|
if (p) {
|
2004-09-26 04:16:52 +00:00
|
|
|
proxy_info.use_http_auth = true;
|
|
|
|
strcpy(proxy_info.http_user_name, p);
|
2004-07-13 18:35:47 +00:00
|
|
|
p = getenv("HTTP_USER_PASSWD");
|
|
|
|
if (p) {
|
2004-09-26 04:16:52 +00:00
|
|
|
strcpy(proxy_info.http_user_passwd, p);
|
2003-10-19 01:48:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-26 04:16:52 +00:00
|
|
|
proxy_info.socks_version =
|
2004-03-27 00:45:27 +00:00
|
|
|
getenv("SOCKS5_SERVER")?SOCKS_VERSION_5:
|
|
|
|
getenv("SOCKS4_SERVER")?SOCKS_VERSION_4:
|
|
|
|
getenv("SOCKS_SERVER")?SOCKS_VERSION_5:
|
|
|
|
SOCKS_VERSION_5;
|
|
|
|
|
2004-07-13 18:35:47 +00:00
|
|
|
p = getenv("SOCKS4_SERVER");
|
2006-11-20 17:12:55 +00:00
|
|
|
if (p && strlen(p)) {
|
2004-09-26 04:16:52 +00:00
|
|
|
proxy_info.use_socks_proxy = true;
|
|
|
|
parse_url(p, proxy_info.socks_server_name, proxy_info.socks_server_port, temp);
|
2004-03-27 00:45:27 +00:00
|
|
|
}
|
|
|
|
|
2006-11-20 17:12:55 +00:00
|
|
|
p = getenv("SOCKS_SERVER");
|
|
|
|
if (!p) p = getenv("SOCKS5_SERVER");
|
|
|
|
if (p && strlen(p)) {
|
|
|
|
proxy_info.use_socks_proxy = true;
|
|
|
|
parse_url(p, proxy_info.socks_server_name, proxy_info.socks_server_port, temp);
|
2003-10-19 01:48:32 +00:00
|
|
|
}
|
|
|
|
|
2006-11-20 17:12:55 +00:00
|
|
|
p = getenv("SOCKS5_USER");
|
|
|
|
if (!p) p = getenv("SOCKS_USER");
|
|
|
|
if (p) {
|
2004-09-26 04:16:52 +00:00
|
|
|
safe_strcpy(proxy_info.socks5_user_name, p);
|
2003-10-19 01:48:32 +00:00
|
|
|
}
|
|
|
|
|
2006-11-20 17:12:55 +00:00
|
|
|
p = getenv("SOCKS5_PASSWD");
|
|
|
|
if (p) {
|
2004-09-26 04:16:52 +00:00
|
|
|
safe_strcpy(proxy_info.socks5_user_passwd, p);
|
2003-10-19 01:48:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::do_cmdline_actions() {
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (show_projects) {
|
|
|
|
printf("projects:\n");
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "URL: %s name: %s\n",
|
|
|
|
projects[i]->master_url, projects[i]->project_name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(detach_project_url)) {
|
|
|
|
PROJECT* project = lookup_project(detach_project_url);
|
|
|
|
if (project) {
|
|
|
|
detach_project(project);
|
|
|
|
msg_printf(project, MSG_INFO, "detached from %s\n", detach_project_url);
|
|
|
|
} else {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(NULL, MSG_USER_ERROR, "project %s not found\n", detach_project_url);
|
2003-10-19 01:48:32 +00:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(reset_project_url)) {
|
|
|
|
PROJECT* project = lookup_project(reset_project_url);
|
|
|
|
if (project) {
|
|
|
|
reset_project(project);
|
|
|
|
msg_printf(project, MSG_INFO, "Project %s has been reset", reset_project_url);
|
|
|
|
} else {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(NULL, MSG_USER_ERROR, "project %s not found\n", reset_project_url);
|
2003-10-19 01:48:32 +00:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(update_prefs_url)) {
|
|
|
|
PROJECT* project = lookup_project(update_prefs_url);
|
|
|
|
if (project) {
|
2006-09-01 22:21:20 +00:00
|
|
|
project->sched_rpc_pending = RPC_REASON_USER_REQ;
|
2003-10-19 01:48:32 +00:00
|
|
|
} else {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(NULL, MSG_USER_ERROR, "project %s not found\n", update_prefs_url);
|
2003-10-19 01:48:32 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-23 06:26:19 +00:00
|
|
|
|
|
|
|
if (strlen(attach_project_url)) {
|
2006-12-26 00:37:25 +00:00
|
|
|
add_project(attach_project_url, attach_project_auth, "", false);
|
2005-03-23 06:26:19 +00:00
|
|
|
}
|
2003-10-19 01:48:32 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_829bd0f60b = "$Id$";
|