forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcs_statefile.cpp
1036 lines (988 loc) · 32.5 KB
/
cs_statefile.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC 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 3 of the License, or (at your option) any later version.
//
// BOINC 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#ifdef _WIN32
#include "boinc_win.h"
#include "win_util.h"
#else
#include "config.h"
#include <cstring>
#include <errno.h>
#endif
#include "error_numbers.h"
#include "filesys.h"
#include "md5_file.h"
#include "parse.h"
#include "str_replace.h"
#include "str_util.h"
#include "util.h"
#include "client_msgs.h"
#include "client_state.h"
#include "cs_proxy.h"
#include "file_names.h"
#include "project.h"
#include "result.h"
#define MAX_STATE_FILE_WRITE_ATTEMPTS 2
void CLIENT_STATE::set_client_state_dirty(const char* source) {
if (log_flags.statefile_debug) {
msg_printf(0, MSG_INFO, "[statefile] set dirty: %s\n", source);
}
client_state_dirty = true;
}
static bool valid_state_file(const char* fname) {
char buf[256];
FILE* f = boinc_fopen(fname, "r");
if (!f) return false;
if (!fgets(buf, 256, f)) {
fclose(f);
return false;
}
if (!match_tag(buf, "<client_state>")) {
fclose(f);
return false;
}
while (fgets(buf, 256, f)) {
if (match_tag(buf, "</client_state>")) {
fclose(f);
return true;
}
}
fclose(f);
return false;
}
// return true if r0 arrived before r1,
// with tie-break based on name hash.
// used to sort result list
//
static inline bool arrived_first(RESULT* r0, RESULT* r1) {
if (r0->received_time < r1->received_time) {
return true;
}
if (r0->received_time > r1->received_time) {
return false;
}
return (r0->name_md5 < r1->name_md5);
}
// Parse the client_state.xml file
//
int CLIENT_STATE::parse_state_file() {
const char *fname;
// Look for a valid state file:
// First the regular one, then the "next" one.
//
if (valid_state_file(STATE_FILE_NEXT)) {
fname = STATE_FILE_NEXT;
} else if (valid_state_file(STATE_FILE_NAME)) {
fname = STATE_FILE_NAME;
} else if (valid_state_file(STATE_FILE_PREV)) {
fname = STATE_FILE_PREV;
} else {
if (log_flags.statefile_debug) {
msg_printf(0, MSG_INFO,
"[statefile] CLIENT_STATE::parse_state_file(): No state file; will create one"
);
}
// avoid warning messages about version
//
old_major_version = BOINC_MAJOR_VERSION;
old_minor_version = BOINC_MINOR_VERSION;
old_release = BOINC_RELEASE;
return ERR_FOPEN;
}
return parse_state_file_aux(fname);
}
int CLIENT_STATE::parse_state_file_aux(const char* fname) {
PROJECT *project=NULL;
int retval=0;
int failnum;
bool btemp;
string stemp;
FILE* f = fopen(fname, "r");
if (!f) return ERR_FOPEN;
MIOFILE mf;
XML_PARSER xp(&mf);
mf.init_file(f);
while (!xp.get_tag()) {
if (xp.match_tag("/client_state")) {
break;
}
if (xp.match_tag("client_state")) {
continue;
}
if (xp.match_tag("project")) {
PROJECT temp_project;
retval = temp_project.parse_state(xp);
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse project in state file");
} else {
#ifdef SIM
project = new PROJECT;
*project = temp_project;
projects.push_back(project);
#else
project = lookup_project(temp_project.master_url);
if (project) {
project->copy_state_fields(temp_project);
} else {
msg_printf(&temp_project, MSG_INTERNAL_ERROR,
"Project %s is in state file but no account file found",
temp_project.get_project_name()
);
}
#endif
}
continue;
}
if (xp.match_tag("app")) {
APP* app = new APP;
retval = app->parse(xp);
if (!project) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Application %s outside project in state file",
app->name
);
delete app;
continue;
}
if (project->anonymous_platform) {
delete app;
continue;
}
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Can't parse application in state file"
);
delete app;
continue;
}
retval = link_app(project, app);
if (retval) {
msg_printf(project, MSG_INTERNAL_ERROR,
"Can't handle application %s in state file",
app->name
);
delete app;
continue;
}
apps.push_back(app);
continue;
}
if (xp.match_tag("file_info") || xp.match_tag("file")) {
FILE_INFO* fip = new FILE_INFO;
retval = fip->parse(xp);
if (!project) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"File info outside project in state file"
);
delete fip;
continue;
}
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Can't handle file info in state file"
);
delete fip;
continue;
}
retval = link_file_info(project, fip);
if (project->anonymous_platform && retval == ERR_NOT_UNIQUE) {
delete fip;
continue;
}
if (retval) {
msg_printf(project, MSG_INTERNAL_ERROR,
"Can't handle file info %s in state file",
fip->name
);
delete fip;
continue;
}
file_infos.push_back(fip);
#ifndef SIM
// If the file had a failure before,
// don't start another file transfer
//
if (fip->had_failure(failnum)) {
if (fip->pers_file_xfer) {
delete fip->pers_file_xfer;
fip->pers_file_xfer = NULL;
}
}
if (fip->pers_file_xfer) {
retval = fip->pers_file_xfer->init(fip, fip->pers_file_xfer->is_upload);
if (retval) {
msg_printf(project, MSG_INTERNAL_ERROR,
"Can't initialize file transfer for %s",
fip->name
);
}
retval = pers_file_xfers->insert(fip->pers_file_xfer);
if (retval) {
msg_printf(project, MSG_INTERNAL_ERROR,
"Can't start persistent file transfer for %s",
fip->name
);
}
}
#endif
continue;
}
if (xp.match_tag("app_version")) {
APP_VERSION* avp = new APP_VERSION;
retval = avp->parse(xp);
if (!project) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Application version outside project in state file"
);
delete avp;
continue;
}
if (project->anonymous_platform) {
delete avp;
continue;
}
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Can't parse application version in state file"
);
delete avp;
continue;
}
if (strlen(avp->platform) == 0) {
safe_strcpy(avp->platform, get_primary_platform());
} else {
if (!is_supported_platform(avp->platform)) {
// if it's a platform we haven't heard of,
// must be that the user tried out a 64 bit client
// and then reverted to a 32-bit client.
// Let's not throw away the app version and its WUs
//
#ifndef SIM
msg_printf(project, MSG_INTERNAL_ERROR,
"App version has unsupported platform %s; changing to %s",
avp->platform, get_primary_platform()
);
#endif
safe_strcpy(avp->platform, get_primary_platform());
}
}
if (avp->missing_coproc) {
msg_printf(project, MSG_INFO,
"Application uses missing %s GPU",
avp->missing_coproc_name
);
}
retval = link_app_version(project, avp);
if (retval) {
delete avp;
continue;
}
app_versions.push_back(avp);
continue;
}
if (xp.match_tag("workunit")) {
WORKUNIT* wup = new WORKUNIT;
retval = wup->parse(xp);
if (!project) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Workunit outside project in state file"
);
delete wup;
continue;
}
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Can't parse workunit in state file"
);
delete wup;
continue;
}
retval = link_workunit(project, wup);
if (retval) {
msg_printf(project, MSG_INTERNAL_ERROR,
"Can't handle workunit in state file"
);
delete wup;
continue;
}
workunits.push_back(wup);
continue;
}
if (xp.match_tag("result")) {
RESULT* rp = new RESULT;
retval = rp->parse_state(xp);
if (!project) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Task %s outside project in state file",
rp->name
);
delete rp;
continue;
}
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Can't parse task in state file"
);
delete rp;
continue;
}
retval = link_result(project, rp);
if (retval) {
msg_printf(project, MSG_INTERNAL_ERROR,
"Can't link task %s in state file",
rp->name
);
delete rp;
continue;
}
// handle transition from old clients which didn't store result.platform;
// skip for anon platform
if (!project->anonymous_platform) {
if (!strlen(rp->platform) || !is_supported_platform(rp->platform)) {
safe_strcpy(rp->platform, get_primary_platform());
rp->version_num = latest_version(rp->wup->app, rp->platform);
}
}
rp->avp = lookup_app_version(
rp->wup->app, rp->platform, rp->version_num, rp->plan_class
);
if (!rp->avp) {
msg_printf(project, MSG_INTERNAL_ERROR,
"No application found for task: %s %d %s; discarding",
rp->platform, rp->version_num, rp->plan_class
);
delete rp;
continue;
}
if (rp->avp->missing_coproc) {
msg_printf(project, MSG_INFO,
"Missing coprocessor for task %s", rp->name
);
rp->coproc_missing = true;
}
rp->wup->version_num = rp->version_num;
results.push_back(rp);
continue;
}
if (xp.match_tag("project_files")) {
if (!project) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Project files outside project in state file"
);
xp.skip_unexpected();
continue;
}
parse_project_files(xp, project->project_files);
project->link_project_files();
continue;
}
if (xp.match_tag("host_info")) {
#ifdef SIM
retval = host_info.parse(xp, false);
coprocs = host_info.coprocs;
#else
retval = host_info.parse(xp, true);
#endif
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Can't parse host info in state file"
);
}
continue;
}
if (xp.match_tag("time_stats")) {
retval = time_stats.parse(xp);
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Can't parse time stats in state file"
);
}
continue;
}
if (xp.match_tag("net_stats")) {
retval = net_stats.parse(xp);
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Can't parse network stats in state file"
);
}
continue;
}
if (xp.match_tag("active_task_set")) {
retval = active_tasks.parse(xp);
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Can't parse active tasks in state file"
);
}
continue;
}
if (xp.parse_string("platform_name", statefile_platform_name)) {
continue;
}
if (xp.parse_string("alt_platform", stemp)) {
continue;
}
if (xp.parse_int("user_run_request", retval)) {
cpu_run_mode.set(retval, 0);
continue;
}
if (xp.parse_int("user_run_prev_request", retval)) {
cpu_run_mode.set_prev(retval);
continue;
}
if (xp.parse_int("user_gpu_request", retval)) {
gpu_run_mode.set(retval, 0);
continue;
}
if (xp.parse_int("user_gpu_prev_request", retval)) {
gpu_run_mode.set_prev(retval);
continue;
}
if (xp.parse_int("user_network_request", retval)) {
network_run_mode.set(retval, 0);
continue;
}
if (xp.parse_int("core_client_major_version", old_major_version)) {
continue;
}
if (xp.parse_int("core_client_minor_version", old_minor_version)) {
continue;
}
if (xp.parse_int("core_client_release", old_release)) {
continue;
}
if (xp.parse_bool("cpu_benchmarks_pending", btemp)) {
if (btemp) run_cpu_benchmarks = true;
continue;
}
if (xp.match_tag("proxy_info")) {
retval = gui_proxy_info.parse(xp);
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Can't parse proxy info in state file"
);
}
continue;
}
if (xp.parse_str("host_venue", main_host_venue, sizeof(main_host_venue))) {
continue;
}
if (xp.parse_double("new_version_check_time", new_version_check_time)) {
continue;
}
if (xp.parse_double("all_projects_list_check_time", all_projects_list_check_time)) {
continue;
}
if (xp.parse_string("newer_version", newer_version)) {
continue;
}
#ifdef ENABLE_AUTO_UPDATE
if (xp.match_tag("auto_update")) {
if (!project) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"auto update outside project in state file"
);
xp.skip_unexpected();
continue;
}
if (!auto_update.parse(xp) && !auto_update.validate_and_link(project)) {
auto_update.present = true;
}
continue;
}
#endif
if (log_flags.unparsed_xml) {
msg_printf(0, MSG_INFO,
"[unparsed_xml] state_file: unrecognized: %s",
xp.parsed_tag
);
}
xp.skip_unexpected();
}
sort_results();
fclose(f);
// if total resource share is zero, set all shares to 1
//
if (projects.size()) {
unsigned int i;
double x=0;
for (i=0; i<projects.size(); i++) {
x += projects[i]->resource_share;
}
if (!x) {
msg_printf(NULL, MSG_INFO,
"All projects have zero resource share; setting to 100"
);
for (i=0; i<projects.size(); i++) {
projects[i]->resource_share = 100;
}
}
}
return 0;
}
// this is called whenever new results are added,
// namely at startup and after a scheduler RPC.
// Sort results based on (arrival time, name),
// then set result.index to their position in this order.
// This determines the order in which results are run.
//
void CLIENT_STATE::sort_results() {
unsigned int i;
for (i=0; i<results.size(); i++) {
RESULT* rp = results[i];
rp->name_md5 = md5_string(string(rp->name));
}
std::sort(
results.begin(),
results.end(),
arrived_first
);
for (i=0; i<results.size(); i++) {
RESULT* rp = results[i];
rp->index = i;
}
}
#ifndef SIM
// Write the client_state.xml file
//
int CLIENT_STATE::write_state_file() {
MFILE mf;
int retval, ret1, ret2, attempt;
#ifdef _WIN32
char win_error_msg[4096];
#endif
for (attempt=1; attempt<=MAX_STATE_FILE_WRITE_ATTEMPTS; attempt++) {
if (attempt > 1) boinc_sleep(1.0);
if (log_flags.statefile_debug) {
msg_printf(0, MSG_INFO,
"[statefile] Writing state file"
);
}
#ifdef _WIN32
retval = mf.open(STATE_FILE_NEXT, "wc");
#else
retval = mf.open(STATE_FILE_NEXT, "w");
#endif
if (retval) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
msg_printf(0, MSG_INTERNAL_ERROR,
"Can't open %s: %s",
STATE_FILE_NEXT, boincerror(retval)
);
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ERR_FOPEN;
}
MIOFILE miof;
miof.init_mfile(&mf);
ret1 = write_state(miof);
ret2 = mf.close();
if (ret1) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Couldn't write state file: %s", boincerror(retval)
);
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ret1;
}
if (ret2) {
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ret2;
}
// only attempt to rename the current state file if it exists.
//
if (boinc_file_exists(STATE_FILE_NAME)) {
if (boinc_file_exists(STATE_FILE_PREV)) {
retval = boinc_delete_file(STATE_FILE_PREV);
if (retval) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
#ifdef _WIN32
msg_printf(0, MSG_INFO,
"Can't delete previous state file; %s",
windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg))
);
#else
msg_printf(0, MSG_INFO,
"Can't delete previous state file: %s",
strerror(errno)
);
#endif
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
}
}
retval = boinc_rename(STATE_FILE_NAME, STATE_FILE_PREV);
if (retval) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
#ifdef _WIN32
msg_printf(0, MSG_INFO,
"Can't rename current state file to previous state file; %s",
windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg))
);
#else
msg_printf(0, MSG_INFO,
"Can't rename current state file to previous state file: %s",
strerror(errno)
);
#endif
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
}
}
retval = boinc_rename(STATE_FILE_NEXT, STATE_FILE_NAME);
if (log_flags.statefile_debug) {
msg_printf(0, MSG_INFO,
"[statefile] Done writing state file"
);
}
if (!retval) break; // Success!
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) {
#ifdef _WIN32
msg_printf(0, MSG_INFO,
"rename error: %s",
windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg))
);
#elif defined (__APPLE__)
if (log_flags.statefile_debug) {
system("ls -al /Library/Application\\ Support/BOINC\\ Data/client*.*");
}
#endif
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ERR_RENAME;
}
return 0;
}
int CLIENT_STATE::write_state(MIOFILE& f) {
unsigned int i, j;
int retval;
#ifdef SIM
fprintf(stderr, "simulator shouldn't write state file\n");
exit(1);
#endif
f.printf("<client_state>\n");
retval = host_info.write(f, true, true);
if (retval) return retval;
retval = time_stats.write(f, false);
if (retval) return retval;
retval = net_stats.write(f);
if (retval) return retval;
for (j=0; j<projects.size(); j++) {
PROJECT* p = projects[j];
retval = p->write_state(f);
if (retval) return retval;
for (i=0; i<apps.size(); i++) {
if (apps[i]->project == p) {
retval = apps[i]->write(f);
if (retval) return retval;
}
}
for (i=0; i<file_infos.size(); i++) {
if (file_infos[i]->project != p) continue;
FILE_INFO* fip = file_infos[i];
// don't write file infos for anonymous platform app files
//
if (fip->anonymous_platform_file) continue;
retval = fip->write(f, false);
if (retval) return retval;
}
for (i=0; i<app_versions.size(); i++) {
if (app_versions[i]->project == p) {
app_versions[i]->write(f);
}
}
for (i=0; i<workunits.size(); i++) {
if (workunits[i]->project == p) workunits[i]->write(f);
}
for (i=0; i<results.size(); i++) {
if (results[i]->project == p) results[i]->write(f, false);
}
p->write_project_files(f);
#ifdef ENABLE_AUTO_UPDATE
if (auto_update.present && auto_update.project==p) {
auto_update.write(f);
}
#endif
}
active_tasks.write(f);
f.printf(
"<platform_name>%s</platform_name>\n"
"<core_client_major_version>%d</core_client_major_version>\n"
"<core_client_minor_version>%d</core_client_minor_version>\n"
"<core_client_release>%d</core_client_release>\n"
"<user_run_request>%d</user_run_request>\n"
"<user_run_prev_request>%d</user_run_prev_request>\n"
"<user_gpu_request>%d</user_gpu_request>\n"
"<user_gpu_prev_request>%d</user_gpu_prev_request>\n"
"<user_network_request>%d</user_network_request>\n"
"%s"
"<new_version_check_time>%f</new_version_check_time>\n"
"<all_projects_list_check_time>%f</all_projects_list_check_time>\n",
get_primary_platform(),
core_client_version.major,
core_client_version.minor,
core_client_version.release,
cpu_run_mode.get_perm(),
cpu_run_mode.get_prev(),
gpu_run_mode.get_perm(),
gpu_run_mode.get_prev(),
network_run_mode.get_perm(),
cpu_benchmarks_pending?"<cpu_benchmarks_pending/>\n":"",
new_version_check_time,
all_projects_list_check_time
);
if (newer_version.size()) {
f.printf("<newer_version>%s</newer_version>\n", newer_version.c_str());
}
for (i=1; i<platforms.size(); i++) {
f.printf("<alt_platform>%s</alt_platform>\n", platforms[i].name.c_str());
}
if (gui_proxy_info.present) {
gui_proxy_info.write(f);
}
if (strlen(main_host_venue)) {
f.printf("<host_venue>%s</host_venue>\n", main_host_venue);
}
f.printf("</client_state>\n");
return 0;
}
// Write the client_state.xml file if necessary
// TODO: write no more often than X seconds
//
int CLIENT_STATE::write_state_file_if_needed() {
int retval;
if (client_state_dirty) {
client_state_dirty = false;
retval = write_state_file();
if (retval) return retval;
}
return 0;
}
#endif // ifndef SIM
// look for app_versions.xml file in project dir.
// If find, get app versions from there,
// and use "anonymous platform" mechanism for this project
//
void CLIENT_STATE::check_anonymous() {
unsigned int i;
char path[MAXPATHLEN];
FILE* f;
int retval;
for (i=0; i<projects.size(); i++) {
PROJECT* p = projects[i];
sprintf(path, "%s/%s", p->project_dir(), APP_INFO_FILE_NAME);
f = fopen(path, "r");
if (!f) continue;
msg_printf(p, MSG_INFO,
"Found %s; using anonymous platform", APP_INFO_FILE_NAME
);
p->anonymous_platform = true;
// flag as anonymous even if can't parse file
retval = parse_app_info(p, f);
if (retval) {
msg_printf_notice(p, false,
"http://boinc.berkeley.edu/manager_links.php?target=notice&controlid=app_info",
"%s",
_("Syntax error in app_info.xml")
);
}
fclose(f);
}
}
// parse a project's app_info.xml (anonymous platform) file
//
int CLIENT_STATE::parse_app_info(PROJECT* p, FILE* in) {
char buf[256], path[MAXPATHLEN];
MIOFILE mf;
mf.init_file(in);
XML_PARSER xp(&mf);
while (!xp.get_tag()) {
if (xp.match_tag("app_info")) continue;
if (xp.match_tag("/app_info")) return 0;
if (xp.match_tag("file_info")) {
FILE_INFO* fip = new FILE_INFO;
if (fip->parse(xp)) {
delete fip;
continue;
}
if (!fip->download_urls.empty() || !fip->upload_urls.empty()) {
msg_printf(p, MSG_INFO,
"Can't specify URLs in app_info.xml"
);
delete fip;
continue;
}
if (link_file_info(p, fip)) {
delete fip;
continue;
}
// check that the file is actually there
//
get_pathname(fip, path, sizeof(path));
if (!boinc_file_exists(path)) {
safe_strcpy(buf,
_("File referenced in app_info.xml does not exist: ")
);
strcat(buf, fip->name);
msg_printf(p, MSG_USER_ALERT, "%s", buf);
delete fip;
continue;
}
fip->status = FILE_PRESENT;
fip->anonymous_platform_file = true;
file_infos.push_back(fip);
continue;
}
if (xp.match_tag("app")) {
APP* app = new APP;
if (app->parse(xp)) {
delete app;
continue;
}
if (lookup_app(p, app->name)) {
delete app;
continue;
}
link_app(p, app);
apps.push_back(app);
continue;
}
if (xp.match_tag("app_version")) {
APP_VERSION* avp = new APP_VERSION;
if (avp->parse(xp)) {
delete avp;
continue;
}
if (strlen(avp->platform) == 0) {
safe_strcpy(avp->platform, get_primary_platform());
}
if (link_app_version(p, avp)) {
delete avp;
continue;
}
app_versions.push_back(avp);
continue;
}
if (log_flags.unparsed_xml) {
msg_printf(p, MSG_INFO,
"Unparsed line in app_info.xml: %s",
xp.parsed_tag
);
}
}
return ERR_XML_PARSE;
}
#ifndef SIM
int CLIENT_STATE::write_state_gui(MIOFILE& f) {
unsigned int i, j;
int retval;
f.printf("<client_state>\n");
retval = host_info.write(f, true, true);
if (retval) return retval;
// the following are for compatibility with old managers
//
if (coprocs.have_nvidia()) {
f.printf("<have_cuda/>\n");
}
if (coprocs.have_ati()) {
f.printf("<have_ati/>\n");
}
#if 1
// NOTE: the following is not in CC_STATE.
// However, BoincView (which does its own parsing) expects it
// to be in the get_state() reply, so leave it in for now
//
retval = net_stats.write(f);
if (retval) return retval;
#endif
retval = time_stats.write(f, true);
if (retval) return retval;
for (j=0; j<projects.size(); j++) {
PROJECT* p = projects[j];
retval = p->write_state(f, true);
if (retval) return retval;
for (i=0; i<apps.size(); i++) {
if (apps[i]->project == p) {
retval = apps[i]->write(f);
if (retval) return retval;
}
}
for (i=0; i<app_versions.size(); i++) {
if (app_versions[i]->project == p) app_versions[i]->write(f);
}
for (i=0; i<workunits.size(); i++) {
if (workunits[i]->project == p) workunits[i]->write(f);
}
for (i=0; i<results.size(); i++) {
if (results[i]->project == p) results[i]->write_gui(f);
}
}
f.printf(
"<platform_name>%s</platform_name>\n"
"<core_client_major_version>%d</core_client_major_version>\n"
"<core_client_minor_version>%d</core_client_minor_version>\n"
"<core_client_release>%d</core_client_release>\n"
"<executing_as_daemon>%d</executing_as_daemon>\n",
get_primary_platform(),
core_client_version.major,
core_client_version.minor,
core_client_version.release,
executing_as_daemon?1:0
);
for (i=0; i<platforms.size(); i++) {
f.printf(
"<platform>%s</platform>\n", platforms[i].name.c_str()
);
}
global_prefs.write(f);
// the following used by BoincView - don't remove
//
if (strlen(main_host_venue)) {
f.printf("<host_venue>%s</host_venue>\n", main_host_venue);
}
f.printf("</client_state>\n");