~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to client/cs_cmdline.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
// command-line parsing, and handling of 1-time actions
19
19
 
 
20
#include "cpp.h"
 
21
 
20
22
#ifdef _WIN32
21
23
#include "boinc_win.h"
 
24
#ifdef _MSC_VER
 
25
#define chdir _chdir
 
26
#endif
22
27
#else
23
28
#include "config.h"
24
 
#include <stdio.h>
 
29
#include <cstdio>
25
30
#include <unistd.h>
26
31
#endif
27
32
 
28
 
#include "main.h"
29
33
#include "str_util.h"
 
34
#include "url.h"
 
35
#include "str_replace.h"
30
36
#include "util.h"
 
37
 
 
38
#include "main.h"
31
39
#include "client_msgs.h"
32
40
#include "client_state.h"
33
41
#include "sandbox.h"
 
42
#include "cs_proxy.h"
34
43
 
35
44
static void print_options(char* prog) {
36
45
    printf(
39
48
        "Run boinccmd in the same directory as %s.\n"
40
49
        "\n"
41
50
        "Usage: %s [options]\n"
 
51
        "    --abort_jobs_on_exit           when client exits, abort and report jobs\n"
42
52
        "    --allow_remote_gui_rpc         allow remote GUI RPC connections\n"
43
53
        "    --allow_multiple_clients       allow >1 instances per host\n"
44
54
        "    --attach_project <URL> <key>   attach to a project\n"
48
58
        "    --detach_project <URL>         detach from a project\n"
49
59
        "    --dir <path>                   use given dir as BOINC home\n"
50
60
        "    --exit_after_app_start N       exit N seconds after an app starts\n"
 
61
        "    --exit_after_finish            exit right after finishing a job\n"
51
62
        "    --exit_before_start            exit right before starting a job\n"
52
63
        "    --exit_before_upload           exit right before starting an upload \n"
53
 
        "    --exit_after_finish            exit right after finishing a job\n"
54
64
        "    --exit_when_idle               exit when there are no results\n"
 
65
        "    --fetch_minimal_work           fetch only 1 job per device\n"
55
66
        "    --file_xfer_giveup_period N    give up on file xfers after N sec\n"
56
67
        "    --gui_rpc_port <port>          port for GUI RPCs\n"
57
68
        "    --help                         show options\n"
59
70
        "    --insecure                     disable app sandboxing (Unix)\n"
60
71
#endif
61
72
        "    --launched_by_manager          client was launched by Manager\n"
 
73
        "    --master_fetch_interval N      limiting period of master retry\n"
62
74
        "    --master_fetch_period N        reload master URL after N RPC failures\n"
63
75
        "    --master_fetch_retry_cap N     exponential backoff limit\n"
64
 
        "    --master_fetch_interval N      limiting period of master retry\n"
 
76
        "    --no_gpus                      don't check for GPUs\n"
65
77
        "    --no_gui_rpc                   don't allow GUI RPC, don't make socket\n"
 
78
        "    --no_info_fetch                don't fetch project list or client version info\n"
 
79
        "    --no_priority_change           run apps at same priority as client\n"
66
80
        "    --pers_giveup N                giveup time for persistent file xfer\n"
 
81
        "    --pers_retry_delay_max N       max for file xfer exponential backoff\n"
67
82
        "    --pers_retry_delay_min N       min for file xfer exponential backoff\n"
68
 
        "    --pers_retry_delay_max N       max for file xfer exponential backoff\n"
 
83
        "    --redirectio                   redirect stdout and stderr to log files\n"
69
84
        "    --reset_project <URL>          reset (clear) a project\n"
70
 
        "    --redirectio                   redirect stdout and stderr to log files\n"
71
85
        "    --retry_cap N                  exponential backoff limit\n"
72
86
        "    --run_cpu_benchmarks           run the CPU benchmarks\n"
73
87
        "    --run_by_updater               set by updater\n"
74
88
        "    --saver                        client was launched by screensaver\n"
 
89
        "    --sched_retry_delay_max N      max for RPC exponential backoff\n"
75
90
        "    --sched_retry_delay_min N      min for RPC exponential backoff\n"
76
 
        "    --sched_retry_delay_max N      max for RPC exponential backoff\n"
77
91
        "    --show_projects                show attached projects\n"
78
92
        "    --skip_cpu_benchmarks          don't run CPU benchmarks\n"
79
93
        "    --start_delay X                delay starting apps for X secs\n"
 
94
        "    --unsigned_apps_ok             allow unsigned apps (for testing)\n"
80
95
        "    --update_prefs <URL>           contact a project to update preferences\n"
81
96
        "    --version                      show version info\n"
82
97
        ,
99
114
    int i;
100
115
    bool show_options = false;
101
116
 
 
117
    // NOTE: if you change or add anything, make the same chane
 
118
    // in show_options() (above) and in doc/client.php
 
119
 
102
120
    for (i=1; i<argc; i++) {
103
 
        if (ARG(exit_when_idle)) {
104
 
            exit_when_idle = true;
105
 
            config.report_results_immediately = true;
106
 
        } else if (ARG(exit_before_start)) {
107
 
            exit_before_start = true;
108
 
        } else if (ARG(exit_after_finish)) {
109
 
            exit_after_finish = true;
 
121
        if (0) {
 
122
        } else if (ARG(abort_jobs_on_exit)) {
 
123
            config.abort_jobs_on_exit = true;
 
124
        } else if (ARG(allow_multiple_clients)) {
 
125
            config.allow_multiple_clients = true;
 
126
        } else if (ARG(allow_remote_gui_rpc)) {
 
127
            config.allow_remote_gui_rpc = true;
 
128
        } else if (ARG(attach_project)) {
 
129
            if (i >= argc-2) {
 
130
                show_options = true;
 
131
            } else {
 
132
                safe_strcpy(attach_project_url, argv[++i]);
 
133
                safe_strcpy(attach_project_auth, argv[++i]);
 
134
            }
110
135
        } else if (ARG(check_all_logins)) {
111
136
            check_all_logins = true;
112
137
        } else if (ARG(daemon)) {
113
138
            executing_as_daemon = true;
114
 
        } else if (ARG(skip_cpu_benchmarks)) {
115
 
            skip_cpu_benchmarks = true;
116
 
        } else if (ARG(exit_after_app_start)) {
117
 
            if (i == argc-1) show_options = true;
118
 
            else exit_after_app_start_secs = atoi(argv[++i]);
119
 
        } else if (ARG(file_xfer_giveup_period)) {
120
 
            if (i == argc-1) show_options = true;
121
 
            else file_xfer_giveup_period = atoi(argv[++i]);
122
 
        } else if (ARG(saver)) {
123
 
            started_by_screensaver = true;
124
 
        } else if (!strncmp(argv[i], "-psn_", strlen("-psn_"))) {
125
 
            // ignore -psn argument on Mac OS X
126
 
        } else if (ARG(exit_before_upload)) {
127
 
            exit_before_upload = true;
128
 
        // The following are only used for testing to alter scheduler/file transfer
129
 
        // backoff rates
130
 
        } else if (ARG(master_fetch_period)) {
131
 
            if (i == argc-1) show_options = true;
132
 
            else master_fetch_period = atoi(argv[++i]);
133
 
        } else if (ARG(retry_cap)) {
134
 
            if (i == argc-1) show_options = true;
135
 
            else retry_cap = atoi(argv[++i]);
136
 
        } else if (ARG(master_fetch_retry_cap)) {
137
 
            if (i == argc-1) show_options = true;
138
 
            else master_fetch_retry_cap = atoi(argv[++i]);
139
 
        } else if (ARG(master_fetch_interval)) {
140
 
            if (i == argc-1) show_options = true;
141
 
            else master_fetch_interval = atoi(argv[++i]);
142
 
        } else if (ARG(sched_retry_delay_min)) {
143
 
            if (i == argc-1) show_options = true;
144
 
            else sched_retry_delay_min = atoi(argv[++i]);
145
 
        } else if (ARG(sched_retry_delay_max)) {
146
 
            if (i == argc-1) show_options = true;
147
 
            else sched_retry_delay_max = atoi(argv[++i]);
148
 
        } else if (ARG(pers_retry_delay_min)) {
149
 
            if (i == argc-1) show_options = true;
150
 
            else pers_retry_delay_min = atoi(argv[++i]);
151
 
        } else if (ARG(pers_retry_delay_max)) {
152
 
            if (i == argc-1) show_options = true;
153
 
            else pers_retry_delay_max = atoi(argv[++i]);
154
 
        } else if (ARG(pers_giveup)) {
155
 
            if (i == argc-1) show_options = true;
156
 
            else pers_giveup = atoi(argv[++i]);
157
139
        } else if (ARG(detach_phase_two)) {
158
140
            detach_console = true;
159
 
 
160
 
        // the above options are private (i.e. not shown by -help)
161
 
        // Public options follow.
162
 
        // NOTE: if you change or add anything, make the same chane
163
 
        // in show_options() (above) and in doc/client.php
164
 
 
165
 
        } else if (ARG(show_projects)) {
166
 
            show_projects = true;
167
141
        } else if (ARG(detach_project)) {
168
142
            if (i == argc-1) show_options = true;
169
143
            else safe_strcpy(detach_project_url, argv[++i]);
170
 
        } else if (ARG(reset_project)) {
171
 
            if (i == argc-1) show_options = true;
172
 
            else safe_strcpy(reset_project_url, argv[++i]);
173
 
        } else if (ARG(update_prefs)) {
174
 
            if (i == argc-1) show_options = true;
175
 
            else safe_strcpy(update_prefs_url, argv[++i]);
176
 
        } else if (ARG(run_cpu_benchmarks)) {
177
 
            run_cpu_benchmarks = true;
178
 
        } else if (ARG(attach_project)) {
179
 
            if (i >= argc-2) {
180
 
                show_options = true;
181
 
            } else {
182
 
                safe_strcpy(attach_project_url, argv[++i]);
183
 
                safe_strcpy(attach_project_auth, argv[++i]);
184
 
            }
185
 
        } else if (ARG(version)) {
186
 
            printf(BOINC_VERSION_STRING " " HOSTTYPE "\n");
187
 
            exit(0);
188
 
        } else if (ARG(allow_remote_gui_rpc)) {
189
 
            allow_remote_gui_rpc = true;
190
 
        } else if (ARG(gui_rpc_port)) {
191
 
            cmdline_gui_rpc_port = atoi(argv[++i]);
192
 
        } else if (ARG(redirectio)) {
193
 
            redirect_io = true;
194
 
        } else if (ARG(help)) {
195
 
            print_options(argv[0]);
196
 
            exit(0);
197
144
        } else if (ARG(dir)) {
198
145
            if (i == argc-1) {
199
146
                show_options = true;
203
150
                    exit(1);
204
151
                }
205
152
            }
206
 
        } else if (ARG(no_gui_rpc)) {
207
 
            no_gui_rpc = true;
 
153
        } else if (ARG(exit_after_app_start)) {
 
154
            if (i == argc-1) show_options = true;
 
155
            else exit_after_app_start_secs = atoi(argv[++i]);
 
156
        } else if (ARG(exit_after_finish)) {
 
157
            config.exit_after_finish = true;
 
158
        } else if (ARG(exit_before_start)) {
 
159
            exit_before_start = true;
 
160
        } else if (ARG(exit_before_upload)) {
 
161
            exit_before_upload = true;
 
162
        } else if (ARG(exit_when_idle)) {
 
163
            config.exit_when_idle = true;
 
164
            config.report_results_immediately = true;
 
165
        } else if (ARG(fetch_minimal_work)) {
 
166
            config.fetch_minimal_work = true;
 
167
        } else if (ARG(file_xfer_giveup_period)) {
 
168
            if (i == argc-1) show_options = true;
 
169
            else file_xfer_giveup_period = atoi(argv[++i]);
 
170
        } else if (ARG(gui_rpc_port)) {
 
171
            cmdline_gui_rpc_port = atoi(argv[++i]);
 
172
        } else if (ARG(help)) {
 
173
            print_options(argv[0]);
 
174
            exit(0);
208
175
        } else if (ARG(insecure)) {
209
176
#ifdef SANDBOX
210
177
            g_use_sandbox = false;
211
178
#endif
212
179
        } else if (ARG(launched_by_manager)) {
213
180
            launched_by_manager = true;
 
181
        } else if (ARG(master_fetch_interval)) {
 
182
            if (i == argc-1) show_options = true;
 
183
            else master_fetch_interval = atoi(argv[++i]);
 
184
        } else if (ARG(master_fetch_period)) {
 
185
            if (i == argc-1) show_options = true;
 
186
            else master_fetch_period = atoi(argv[++i]);
 
187
        } else if (ARG(master_fetch_retry_cap)) {
 
188
            if (i == argc-1) show_options = true;
 
189
            else master_fetch_retry_cap = atoi(argv[++i]);
 
190
        } else if (ARG(no_gpus)) {
 
191
            config.no_gpus = true;
 
192
        } else if (ARG(no_gui_rpc)) {
 
193
            no_gui_rpc = true;
 
194
        } else if (ARG(no_info_fetch)) {
 
195
            config.no_info_fetch = true;
 
196
        } else if (ARG(no_priority_change)) {
 
197
            config.no_priority_change = true;
 
198
        } else if (ARG(pers_giveup)) {
 
199
            if (i == argc-1) show_options = true;
 
200
            else pers_giveup = atoi(argv[++i]);
 
201
        } else if (ARG(pers_retry_delay_max)) {
 
202
            if (i == argc-1) show_options = true;
 
203
            else pers_retry_delay_max = atoi(argv[++i]);
 
204
        } else if (ARG(pers_retry_delay_min)) {
 
205
            if (i == argc-1) show_options = true;
 
206
            else pers_retry_delay_min = atoi(argv[++i]);
 
207
        } else if (!strncmp(argv[i], "-psn_", strlen("-psn_"))) {
 
208
            // ignore -psn argument on Mac OS X
 
209
        } else if (ARG(redirectio)) {
 
210
            redirect_io = true;
 
211
        } else if (ARG(reset_project)) {
 
212
            if (i == argc-1) show_options = true;
 
213
            else safe_strcpy(reset_project_url, argv[++i]);
 
214
        } else if (ARG(retry_cap)) {
 
215
            if (i == argc-1) show_options = true;
 
216
            else retry_cap = atoi(argv[++i]);
214
217
        } else if (ARG(run_by_updater)) {
215
218
            run_by_updater = true;
 
219
        } else if (ARG(run_cpu_benchmarks)) {
 
220
            run_cpu_benchmarks = true;
 
221
        } else if (ARG(saver)) {
 
222
            started_by_screensaver = true;
 
223
        } else if (ARG(sched_retry_delay_max)) {
 
224
            if (i == argc-1) show_options = true;
 
225
            else sched_retry_delay_max = atoi(argv[++i]);
 
226
        } else if (ARG(sched_retry_delay_min)) {
 
227
            if (i == argc-1) show_options = true;
 
228
            else sched_retry_delay_min = atoi(argv[++i]);
 
229
        } else if (ARG(show_projects)) {
 
230
            show_projects = true;
 
231
        } else if (ARG(skip_cpu_benchmarks)) {
 
232
            config.skip_cpu_benchmarks = true;
216
233
        } else if (ARG(start_delay)) {
217
234
            if (i == argc-1) show_options = true;
218
235
            else config.start_delay = atof(argv[++i]);
219
 
        } else if (ARG(allow_multiple_clients)) {
220
 
            config.allow_multiple_clients = true;
 
236
        } else if (ARG(unsigned_apps_ok)) {
 
237
            config.unsigned_apps_ok = true;
 
238
        } else if (ARG(update_prefs)) {
 
239
            if (i == argc-1) show_options = true;
 
240
            else safe_strcpy(update_prefs_url, argv[++i]);
 
241
        } else if (ARG(version)) {
 
242
#if (defined (__APPLE__) && (defined(__i386__) || defined(__x86_64__)))
 
243
            CLIENT_STATE cs;
 
244
            cs.detect_platforms();
 
245
            printf(BOINC_VERSION_STRING " %s\n", HOSTTYPE);
 
246
#else
 
247
            printf(BOINC_VERSION_STRING " " HOSTTYPE "\n");
 
248
#endif
 
249
            exit(0);
221
250
        } else {
222
251
            printf("Unknown option: %s\n", argv[i]);
223
252
            show_options = true;
233
262
#undef ARGX2
234
263
 
235
264
void CLIENT_STATE::parse_env_vars() {
236
 
    char *p, temp[256];
 
265
    char *p;
 
266
    PARSED_URL purl;
237
267
 
238
268
    p = getenv("HTTP_PROXY");
239
269
    if (p && strlen(p) > 0) {
240
 
        proxy_info.use_http_proxy = true;
241
 
        parse_url(p, proxy_info.http_server_name, proxy_info.http_server_port, temp);
 
270
        parse_url(p, purl);
 
271
        switch (purl.protocol) {
 
272
        case URL_PROTOCOL_HTTP:
 
273
        case URL_PROTOCOL_HTTPS:
 
274
            env_var_proxy_info.present = true;
 
275
            env_var_proxy_info.use_http_proxy = true;
 
276
            strcpy(env_var_proxy_info.http_user_name, purl.user);
 
277
            strcpy(env_var_proxy_info.http_user_passwd, purl.passwd);
 
278
            strcpy(env_var_proxy_info.http_server_name, purl.host);
 
279
            env_var_proxy_info.http_server_port = purl.port;
 
280
            break;
 
281
        default:
 
282
            msg_printf_notice(0, false,
 
283
                "http://boinc.berkeley.edu/manager_links.php?target=notice&controlid=proxy_env",
 
284
                _("The HTTP_PROXY environment variable must specify an HTTP proxy")
 
285
            );
 
286
        }
242
287
    }
243
288
    p = getenv("HTTP_USER_NAME");
244
289
    if (p) {
245
 
        proxy_info.use_http_auth = true;
246
 
        safe_strcpy(proxy_info.http_user_name, p);
 
290
        env_var_proxy_info.use_http_auth = true;
 
291
        strcpy(env_var_proxy_info.http_user_name, p);
247
292
        p = getenv("HTTP_USER_PASSWD");
248
293
        if (p) {
249
 
            safe_strcpy(proxy_info.http_user_passwd, p);
 
294
            strcpy(env_var_proxy_info.http_user_passwd, p);
250
295
        }
251
296
    }
252
297
 
253
 
    proxy_info.socks_version = SOCKS_VERSION_5;
254
 
    if (getenv("SOCKS4_SERVER")) {
255
 
        proxy_info.socks_version = SOCKS_VERSION_4;
256
 
    }
257
 
 
258
 
    p = getenv("SOCKS4_SERVER");
259
 
    if (p && strlen(p)) {
260
 
        proxy_info.use_socks_proxy = true;
261
 
        parse_url(p, proxy_info.socks_server_name, proxy_info.socks_server_port, temp);
262
 
    }
263
 
 
264
298
        p = getenv("SOCKS_SERVER");
265
299
        if (!p) p = getenv("SOCKS5_SERVER");
266
300
    if (p && strlen(p)) {
267
 
        proxy_info.use_socks_proxy = true;
268
 
        parse_url(p, proxy_info.socks_server_name, proxy_info.socks_server_port, temp);
 
301
        parse_url(p, purl);
 
302
        env_var_proxy_info.present = true;
 
303
        env_var_proxy_info.use_socks_proxy = true;
 
304
        strcpy(env_var_proxy_info.socks5_user_name, purl.user);
 
305
        strcpy(env_var_proxy_info.socks5_user_passwd, purl.passwd);
 
306
        strcpy(env_var_proxy_info.socks_server_name, purl.host);
 
307
        env_var_proxy_info.socks_server_port = purl.port;
269
308
    }
270
309
 
271
310
        p = getenv("SOCKS5_USER");
272
311
        if (!p) p = getenv("SOCKS_USER");
273
312
    if (p) {
274
 
        safe_strcpy(proxy_info.socks5_user_name, p);
 
313
        strcpy(env_var_proxy_info.socks5_user_name, p);
275
314
    }
276
315
 
277
316
        p = getenv("SOCKS5_PASSWD");
278
317
    if (p) {
279
 
        safe_strcpy(proxy_info.socks5_user_passwd, p);
 
318
        strcpy(env_var_proxy_info.socks5_user_passwd, p);
280
319
    }
281
320
}
282
321
 
302
341
            msg_printf(project, MSG_INFO, "detaching from %s\n", detach_project_url);
303
342
            detach_project(project);
304
343
        } else {
305
 
            msg_printf(NULL, MSG_USER_ERROR, "project %s not found\n", detach_project_url);
 
344
            msg_printf(NULL, MSG_INFO, "project %s not found\n", detach_project_url);
306
345
        }
307
346
        exit(0);
308
347
    }
314
353
            reset_project(project, false);
315
354
            msg_printf(project, MSG_INFO, "Project %s has been reset", reset_project_url);
316
355
        } else {
317
 
            msg_printf(NULL, MSG_USER_ERROR, "project %s not found\n", reset_project_url);
 
356
            msg_printf(NULL, MSG_INFO, "project %s not found\n", reset_project_url);
318
357
        }
319
358
        exit(0);
320
359
    }
325
364
        if (project) {
326
365
            project->sched_rpc_pending = RPC_REASON_USER_REQ;
327
366
        } else {
328
 
            msg_printf(NULL, MSG_USER_ERROR, "project %s not found\n", update_prefs_url);
 
367
            msg_printf(NULL, MSG_INFO, "project %s not found\n", update_prefs_url);
329
368
        }
330
369
    }
331
370
 
335
374
    }
336
375
}
337
376
 
338
 
const char *BOINC_RCSID_829bd0f60b = "$Id: cs_cmdline.cpp 16328 2008-10-28 02:21:26Z davea $";