Example #1
0
int SCHED_CONFIG::parse(FILE* f) {
    char buf[256];
    MIOFILE mf;
    XML_PARSER xp(&mf);
    int retval, itemp;
    regex_t re;
    double x;

    mf.init_file(f);

    memset(this, 0, sizeof(*this));
    ban_os = new vector<regex_t>;
    ban_cpu = new vector<regex_t>;
    locality_scheduling_workunit_file = new vector<regex_t>;
    locality_scheduling_sticky_file = new vector<regex_t>;
    max_wus_to_send = 10;
    default_disk_max_used_gb = 100.;
    default_disk_max_used_pct = 50.;
    default_disk_min_free_gb = .001;
    sched_debug_level = MSG_NORMAL;
    fuh_debug_level = MSG_NORMAL;
    strcpy(httpd_user, "apache");
    max_ncpus = MAX_NCPUS;
    scheduler_log_buffer = 32768;
    version_select_random_factor = .1;

    if (!xp.parse_start("boinc")) return ERR_XML_PARSE;
    if (!xp.parse_start("config")) return ERR_XML_PARSE;
    while (!xp.get_tag()) {
        if (!xp.is_tag) {
            fprintf(stderr,
                "SCHED_CONFIG::parse(): unexpected text %s\n",
                xp.parsed_tag
            );
            continue;
        }
        if (xp.match_tag("/config")) {
            char hostname[256];
            gethostname(hostname, 256);
            if (!strcmp(hostname, db_host)) strcpy(db_host, "localhost");
            if (!strlen(replica_db_host)) {
                strcpy(replica_db_host, db_host);
            }
            if (!strlen(replica_db_name)) {
                strcpy(replica_db_name, db_name);
            }
            if (!strlen(replica_db_user)) {
                strcpy(replica_db_user, db_user);
            }
            if (!strlen(replica_db_passwd)) {
                strcpy(replica_db_passwd, db_passwd);
            }
            return 0;
        }
        if (xp.parse_str("master_url", master_url, sizeof(master_url))) continue;
        if (xp.parse_str("long_name", long_name, sizeof(long_name))) continue;
        if (xp.parse_str("db_name", db_name, sizeof(db_name))) continue;
        if (xp.parse_str("db_user", db_user, sizeof(db_user))) continue;
        if (xp.parse_str("db_passwd", db_passwd, sizeof(db_passwd))) continue;
        if (xp.parse_str("db_host", db_host, sizeof(db_host))) continue;
        if (xp.parse_str("replica_db_name", replica_db_name, sizeof(replica_db_name))) continue;
        if (xp.parse_str("replica_db_user", replica_db_user, sizeof(replica_db_user))) continue;
        if (xp.parse_str("replica_db_passwd", replica_db_passwd, sizeof(replica_db_passwd))) continue;
        if (xp.parse_str("replica_db_host", replica_db_host, sizeof(replica_db_host))) continue;
        if (xp.parse_str("project_dir", project_dir, sizeof(project_dir))) continue;
        if (xp.parse_int("shmem_key", shmem_key)) continue;
        if (xp.parse_str("key_dir", key_dir, sizeof(key_dir))) continue;
        if (xp.parse_str("download_url", download_url, sizeof(download_url))) continue;
        if (xp.parse_str("download_dir", download_dir, sizeof(download_dir))) continue;
        if (xp.parse_str("upload_url", upload_url, sizeof(upload_url))) continue;
        if (xp.parse_str("upload_dir", upload_dir, sizeof(upload_dir))) continue;
        if (xp.parse_bool("non_cpu_intensive", non_cpu_intensive)) continue;
        if (xp.parse_bool("verify_files_on_app_start", verify_files_on_app_start)) continue;
        if (xp.parse_int("homogeneous_redundancy", homogeneous_redundancy)) continue;
        if (xp.parse_bool("hr_allocate_slots", hr_allocate_slots)) continue;
        if (xp.parse_bool("msg_to_host", msg_to_host)) continue;
        if (xp.parse_bool("ignore_upload_certificates", ignore_upload_certificates)) continue;
        if (xp.parse_bool("dont_generate_upload_certificates", dont_generate_upload_certificates)) continue;
        if (xp.parse_int("uldl_dir_fanout", uldl_dir_fanout)) continue;
        if (xp.parse_bool("cache_md5_info", cache_md5_info)) continue;
        if (xp.parse_int("fuh_debug_level", fuh_debug_level)) continue;
        if (xp.parse_int("reliable_priority_on_over", reliable_priority_on_over)) continue;
        if (xp.parse_int("reliable_priority_on_over_except_error", reliable_priority_on_over_except_error)) continue;
        if (xp.parse_int("reliable_on_priority", reliable_on_priority)) continue;
        if (xp.parse_double("grace_period_hours", x)) {
            report_grace_period = (int)(x*3600);
            continue;
        }
        if (xp.parse_int("report_grace_period", report_grace_period)) continue;
        if (xp.parse_double("delete_delay_hours", x)) {
            delete_delay = x*3600;
            continue;
        }
        if (xp.parse_bool("distinct_beta_apps", distinct_beta_apps)) continue;
        if (xp.parse_bool("ended", ended)) continue;
        if (xp.parse_int("shmem_work_items", shmem_work_items)) continue;
        if (xp.parse_int("feeder_query_size", feeder_query_size)) continue;
        if (xp.parse_str("httpd_user", httpd_user, sizeof(httpd_user))) continue;
        if (xp.parse_bool("enable_vda", enable_vda)) continue;
        if (xp.parse_double("vda_host_timeout", vda_host_timeout)) continue;
        if (xp.parse_bool("enable_assignment", enable_assignment)) continue;
        if (xp.parse_bool("enable_assignment_multi", enable_assignment_multi)) continue;
        if (xp.parse_bool("job_size_matching", job_size_matching)) continue;
        if (xp.parse_bool("dont_send_jobs", dont_send_jobs)) continue;

        //////////// STUFF RELEVANT ONLY TO SCHEDULER STARTS HERE ///////

        if (xp.parse_str("ban_cpu", buf, sizeof(buf))) {
            retval = regcomp(&re, buf, REG_EXTENDED|REG_NOSUB);
            if (retval) {
                log_messages.printf(MSG_CRITICAL, "BAD REGEXP: %s\n", buf);
            } else {
                ban_cpu->push_back(re);
            }
            continue;
        }
        if (xp.parse_str("ban_os", buf, sizeof(buf))) {
            retval = regcomp(&re, buf, REG_EXTENDED|REG_NOSUB);
            if (retval) {
                log_messages.printf(MSG_CRITICAL, "BAD REGEXP: %s\n", buf);
            } else {
                ban_os->push_back(re);
            }
            continue;
        }
        if (xp.parse_int("dont_search_host_for_user", retval)) {
            dont_search_host_for_userid.push_back(retval);
            continue;
        }
        if (xp.parse_int("daily_result_quota", daily_result_quota)) continue;
        if (xp.parse_double("default_disk_max_used_gb", default_disk_max_used_gb)) continue;
        if (xp.parse_double("default_disk_max_used_pct", default_disk_max_used_pct)) continue;
        if (xp.parse_double("default_disk_min_free_gb", default_disk_min_free_gb)) continue;
        if (xp.parse_bool("dont_store_success_stderr", dont_store_success_stderr)) continue;
        if (xp.parse_int("file_deletion_strategy", file_deletion_strategy)) continue;
        if (xp.parse_int("gpu_multiplier", gpu_multiplier)) continue;
        if (xp.parse_bool("ignore_delay_bound", ignore_delay_bound)) continue;
        if (xp.parse_bool("locality_scheduling", locality_scheduling)) continue;
        if (xp.parse_double("locality_scheduler_fraction", locality_scheduler_fraction)) continue;
        if (xp.parse_bool("locality_scheduling_sorted_order", locality_scheduling_sorted_order)) continue;
        if (xp.parse_int("locality_scheduling_wait_period", locality_scheduling_wait_period)) continue;
        if (xp.parse_int("locality_scheduling_send_timeout", locality_scheduling_send_timeout)) continue;
        if (xp.parse_str("locality_scheduling_workunit_file", buf, sizeof(buf))) {
            retval = regcomp(&re, buf, REG_EXTENDED|REG_NOSUB);
            if (retval) {
                log_messages.printf(MSG_CRITICAL, "BAD REGEXP: %s\n", buf);
            } else {
                locality_scheduling_workunit_file->push_back(re);
            }
            continue;
        }
        if (xp.parse_str("locality_scheduling_sticky_file", buf, sizeof(buf))) {
            retval = regcomp(&re, buf, REG_EXTENDED|REG_NOSUB);
            if (retval) {
                log_messages.printf(MSG_CRITICAL, "BAD REGEXP: %s\n", buf);
            } else {
                locality_scheduling_sticky_file->push_back(re);
            }
            continue;
        }
        if (xp.parse_bool("matchmaker", matchmaker)) continue;
        if (xp.parse_int("max_ncpus", max_ncpus)) continue;
        if (xp.parse_int("max_wus_in_progress", itemp)) {
            max_jobs_in_progress.project_limits.cpu.base_limit = itemp;
            max_jobs_in_progress.project_limits.cpu.per_proc = true;
            continue;
        }
        if (xp.parse_int("max_wus_in_progress_gpu", itemp)) {
            max_jobs_in_progress.project_limits.gpu.base_limit = itemp;
            max_jobs_in_progress.project_limits.gpu.per_proc = true;
            continue;
        }
        if (xp.parse_int("max_results_accepted", max_results_accepted)) continue;
        if (xp.parse_int("max_wus_to_send", max_wus_to_send)) continue;
        if (xp.parse_int("min_core_client_version", min_core_client_version)) {
            if (min_core_client_version && min_core_client_version < 10000) {
                log_messages.printf(MSG_CRITICAL,
                    "min_core_client_version too small; multiplying by 100\n"
                );
                min_core_client_version *= 100;
            }
            continue;
        }
        if (xp.parse_int("min_core_client_version_announced", min_core_client_version_announced)) {
            if (min_core_client_version_announced && min_core_client_version_announced < 10000) {
                log_messages.printf(MSG_CRITICAL,
                    "min_core_client_version_announced too small; multiplying by 100\n"
                );
                min_core_client_version_announced *= 100;
            }
            continue;
        }
        if (xp.parse_int("min_core_client_upgrade_deadline", min_core_client_upgrade_deadline)) continue;
        if (xp.parse_int("min_sendwork_interval", min_sendwork_interval)) continue;
        if (xp.parse_int("mm_min_slots", mm_min_slots)) continue;
        if (xp.parse_int("mm_max_slots", mm_max_slots)) continue;
        if (xp.parse_double("next_rpc_delay", next_rpc_delay)) continue;
        if (xp.parse_bool("no_amd_k6", no_amd_k6)) {
            if (no_amd_k6) {
                regcomp(&re, ".*AMD.*\t.*Family 5 Model 8 Stepping 0.*", REG_EXTENDED|REG_NOSUB);
                ban_cpu->push_back(re);
            }
            continue;
        }
        if (xp.parse_bool("no_vista_sandbox", no_vista_sandbox)) continue;
        if (xp.parse_bool("nowork_skip", nowork_skip)) continue;
        if (xp.parse_bool("one_result_per_host_per_wu", one_result_per_host_per_wu)) continue;
        if (xp.parse_bool("one_result_per_user_per_wu", one_result_per_user_per_wu)) continue;
        if (xp.parse_int("reliable_max_avg_turnaround", reliable_max_avg_turnaround)) continue;
        if (xp.parse_double("reliable_max_error_rate", reliable_max_error_rate)) continue;
        if (xp.parse_double("reliable_reduced_delay_bound", reliable_reduced_delay_bound)) continue;
        if (xp.parse_str("replace_download_url_by_timezone", replace_download_url_by_timezone, sizeof(replace_download_url_by_timezone))) continue;
        if (xp.parse_int("max_download_urls_per_file", max_download_urls_per_file)) continue;
        if (xp.parse_int("report_max", report_max)) continue;
        if (xp.parse_bool("request_time_stats_log", request_time_stats_log)) continue;
        if (xp.parse_bool("resend_lost_results", resend_lost_results)) continue;
        if (xp.parse_int("sched_debug_level", sched_debug_level)) continue;
        if (xp.parse_int("scheduler_log_buffer", scheduler_log_buffer)) continue;
        if (xp.parse_str("sched_lockfile_dir", sched_lockfile_dir, sizeof(sched_lockfile_dir))) continue;
        if (xp.parse_bool("send_result_abort", send_result_abort)) continue;
        if (xp.parse_str("symstore", symstore, sizeof(symstore))) continue;

        if (xp.parse_bool("user_filter", user_filter)) continue;
        if (xp.parse_bool("workload_sim", workload_sim)) continue;
        if (xp.parse_bool("prefer_primary_platform", prefer_primary_platform)) continue;
        if (xp.parse_double("version_select_random_factor", version_select_random_factor)) continue;

        //////////// SCHEDULER LOG FLAGS /////////

        if (xp.parse_bool("debug_array", debug_array)) continue;
        if (xp.parse_bool("debug_assignment", debug_assignment)) continue;
        if (xp.parse_bool("debug_credit", debug_credit)) continue;
        if (xp.parse_bool("debug_edf_sim_detail", debug_edf_sim_detail)) continue;
        if (xp.parse_bool("debug_edf_sim_workload", debug_edf_sim_workload)) continue;
        if (xp.parse_bool("debug_fcgi", debug_fcgi)) continue;
        if (xp.parse_bool("debug_handle_results", debug_handle_results)) continue;
        if (xp.parse_bool("debug_locality", debug_locality)) continue;
        if (xp.parse_bool("debug_prefs", debug_prefs)) continue;
        if (xp.parse_bool("debug_quota", debug_quota)) continue;
        if (xp.parse_bool("debug_request_details", debug_request_details)) continue;
        if (xp.parse_bool("debug_request_headers", debug_request_headers)) continue;
        if (xp.parse_bool("debug_resend", debug_resend)) continue;
        if (xp.parse_bool("debug_send", debug_send)) continue;
        if (xp.parse_bool("debug_user_messages", debug_user_messages)) continue;
        if (xp.parse_bool("debug_vda", debug_vda)) continue;
        if (xp.parse_bool("debug_version_select", debug_version_select)) continue;

        if (xp.parse_str("debug_req_reply_dir", debug_req_reply_dir, sizeof(debug_req_reply_dir))) continue;

        // don't complain about unparsed XML;
        // there are lots of tags the scheduler doesn't know about

        xp.skip_unexpected(false, "SCHED_CONFIG::parse");
    }   
    return ERR_XML_PARSE;
}
Example #2
0
// Write a scheduler request to a disk file,
// to be sent to a scheduling server
//
int CLIENT_STATE::make_scheduler_request(PROJECT* p) {
    char buf[1024];
    MIOFILE mf;
    unsigned int i;
    RESULT* rp;

    get_sched_request_filename(*p, buf, sizeof(buf));
    FILE* f = boinc_fopen(buf, "wb");
    if (!f) return ERR_FOPEN;

    double trs = total_resource_share();
    double rrs = runnable_resource_share(RSC_TYPE_ANY);
    double prrs = potentially_runnable_resource_share();
    double resource_share_fraction, rrs_fraction, prrs_fraction;
    if (trs) {
        resource_share_fraction = p->resource_share / trs;
    } else {
        resource_share_fraction = 1;
    }
    if (rrs) {
        rrs_fraction = p->resource_share / rrs;
    } else {
        rrs_fraction = 1;
    }
    if (prrs) {
        prrs_fraction = p->resource_share / prrs;
    } else {
        prrs_fraction = 1;
    }

    // if hostid is zero, rpc_seqno better be also
    //
    if (!p->hostid) {
        p->rpc_seqno = 0;
    }

    mf.init_file(f);
    fprintf(f,
        "<scheduler_request>\n"
        "    <authenticator>%s</authenticator>\n"
        "    <hostid>%d</hostid>\n"
        "    <rpc_seqno>%d</rpc_seqno>\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"
        "    <resource_share_fraction>%f</resource_share_fraction>\n"
        "    <rrs_fraction>%f</rrs_fraction>\n"
        "    <prrs_fraction>%f</prrs_fraction>\n"
        "    <duration_correction_factor>%f</duration_correction_factor>\n"
        "    <allow_multiple_clients>%d</allow_multiple_clients>\n"
        "    <sandbox>%d</sandbox>\n",
        p->authenticator,
        p->hostid,
        p->rpc_seqno,
        core_client_version.major,
        core_client_version.minor,
        core_client_version.release,
        resource_share_fraction,
        rrs_fraction,
        prrs_fraction,
        p->duration_correction_factor,
        config.allow_multiple_clients?1:0,
        g_use_sandbox?1:0
    );
    work_fetch.write_request(f, p);

    // write client capabilities
    //
    fprintf(f,
        "    <client_cap_plan_class>1</client_cap_plan_class>\n"
    );

    write_platforms(p, mf);

    if (strlen(p->code_sign_key)) {
        fprintf(f, "    <code_sign_key>\n%s\n</code_sign_key>\n", p->code_sign_key);
    }

    // send working prefs
    //
    fprintf(f, "<working_global_preferences>\n");
    global_prefs.write(mf);
    fprintf(f, "</working_global_preferences>\n");

    // send master global preferences if present and not host-specific
    //
    if (!global_prefs.host_specific && boinc_file_exists(GLOBAL_PREFS_FILE_NAME)) {
        FILE* fprefs = fopen(GLOBAL_PREFS_FILE_NAME, "r");
        if (fprefs) {
            copy_stream(fprefs, f);
            fclose(fprefs);
        }
        PROJECT* pp = lookup_project(global_prefs.source_project);
        if (pp && strlen(pp->email_hash)) {
            fprintf(f,
                "<global_prefs_source_email_hash>%s</global_prefs_source_email_hash>\n",
                pp->email_hash
            );
        }
    }

    // Of the projects with same email hash as this one,
    // send the oldest cross-project ID.
    // Use project URL as tie-breaker.
    //
    PROJECT* winner = p;
    for (i=0; i<projects.size(); i++ ) {
        PROJECT* project = projects[i];
        if (project == p) continue;
        if (strcmp(project->email_hash, p->email_hash)) continue;
        if (project->cpid_time < winner->cpid_time) {
            winner = project;
        } else if (project->cpid_time == winner->cpid_time) {
            if (strcmp(project->master_url, winner->master_url) < 0) {
                winner = project;
            }
        }
    }
    fprintf(f,
        "<cross_project_id>%s</cross_project_id>\n",
        winner->cross_project_id
    );

    time_stats.write(mf, true);
    net_stats.write(mf);
    if (global_prefs.daily_xfer_period_days) {
        daily_xfer_history.write_scheduler_request(
            mf, global_prefs.daily_xfer_period_days
        );
    }

    // update hardware info, and write host info
    //
    host_info.get_host_info();
    set_ncpus();
    host_info.write(mf, !config.suppress_net_info, false);

    // get and write disk usage
    //
    get_disk_usages();
    get_disk_shares();
    fprintf(f,
        "    <disk_usage>\n"
        "        <d_boinc_used_total>%f</d_boinc_used_total>\n"
        "        <d_boinc_used_project>%f</d_boinc_used_project>\n"
        "        <d_project_share>%f</d_project_share>\n"
        "    </disk_usage>\n",
        total_disk_usage, p->disk_usage, p->disk_share
    );

    // copy request values from RSC_WORK_FETCH to COPROC
    //
    int j = rsc_index(GPU_TYPE_NVIDIA);
    if (j > 0) {
        coprocs.nvidia.req_secs = rsc_work_fetch[j].req_secs;
        coprocs.nvidia.req_instances = rsc_work_fetch[j].req_instances;
        coprocs.nvidia.estimated_delay = rsc_work_fetch[j].req_secs?rsc_work_fetch[j].busy_time_estimator.get_busy_time():0;
    }
    j = rsc_index(GPU_TYPE_ATI);
    if (j > 0) {
        coprocs.ati.req_secs = rsc_work_fetch[j].req_secs;
        coprocs.ati.req_instances = rsc_work_fetch[j].req_instances;
        coprocs.ati.estimated_delay = rsc_work_fetch[j].req_secs?rsc_work_fetch[j].busy_time_estimator.get_busy_time():0;
    }
    j = rsc_index(GPU_TYPE_INTEL);
    if (j > 0) {
        coprocs.intel_gpu.req_secs = rsc_work_fetch[j].req_secs;
        coprocs.intel_gpu.req_instances = rsc_work_fetch[j].req_instances;
        coprocs.intel_gpu.estimated_delay = rsc_work_fetch[j].req_secs?rsc_work_fetch[j].busy_time_estimator.get_busy_time():0;
    }

    if (coprocs.n_rsc > 1) {
        coprocs.write_xml(mf, true);
    }

    // report completed jobs
    //
    unsigned int last_reported_index = 0;
    p->nresults_returned = 0;
    for (i=0; i<results.size(); i++) {
        rp = results[i];
        if (rp->project == p && rp->ready_to_report) {
            p->nresults_returned++;
            rp->write(mf, true);
        }
        if (config.max_tasks_reported
            && (p->nresults_returned >= config.max_tasks_reported)
        ) {
            last_reported_index = i;
            break;
        }
    }

    read_trickle_files(p, f);

    // report sticky files as needed
    //
    for (i=0; i<file_infos.size(); i++) {
        FILE_INFO* fip = file_infos[i];
        if (fip->project != p) continue;
        if (!fip->sticky) continue;
        fprintf(f,
            "    <file_info>\n"
            "        <name>%s</name>\n"
            "        <nbytes>%f</nbytes>\n"
            "        <status>%d</status>\n"
            "    </file_info>\n",
            fip->name, fip->nbytes, fip->status
        );
    }

    if (p->send_time_stats_log) {
        fprintf(f, "<time_stats_log>\n");
        time_stats.get_log_after(p->send_time_stats_log, mf);
        fprintf(f, "</time_stats_log>\n");
    }
    if (p->send_job_log) {
        fprintf(f, "<job_log>\n");
        job_log_filename(*p, buf, sizeof(buf));
        send_log_after(buf, p->send_job_log, mf);
        fprintf(f, "</job_log>\n");
    }

    // send descriptions of app versions
    //
    fprintf(f, "<app_versions>\n");
    j=0;
    for (i=0; i<app_versions.size(); i++) {
        APP_VERSION* avp = app_versions[i];
        if (avp->project != p) continue;
        avp->write(mf, false);
        avp->index = j++;
    }
    fprintf(f, "</app_versions>\n");

    // send descriptions of jobs in progress for this project
    //
    fprintf(f, "<other_results>\n");
    for (i=0; i<results.size(); i++) {
        rp = results[i];
        if (rp->project != p) continue;
        if ((last_reported_index && (i > last_reported_index)) || !rp->ready_to_report) {
            fprintf(f,
                "    <other_result>\n"
                "        <name>%s</name>\n"
                "        <app_version>%d</app_version>\n",
                rp->name,
                rp->avp->index
            );
            // the following is for backwards compatibility w/ old schedulers
            //
            if (strlen(rp->avp->plan_class)) {
                fprintf(f,
                    "        <plan_class>%s</plan_class>\n",
                    rp->avp->plan_class
                );
            }
            fprintf(f,
                "    </other_result>\n"
            );
        }
    }
    fprintf(f, "</other_results>\n");

    // if requested by project, send summary of all in-progress results
    // (for EDF simulation by scheduler)
    //
    if (p->send_full_workload) {
        fprintf(f, "<in_progress_results>\n");
        for (i=0; i<results.size(); i++) {
            rp = results[i];
            double x = rp->estimated_runtime_remaining();
            if (x == 0) continue;
            strcpy(buf, "");
            int rt = rp->avp->gpu_usage.rsc_type;
            if (rt) {
                if (rt == rsc_index(GPU_TYPE_NVIDIA)) {
                    sprintf(buf,
                        "        <ncudas>%f</ncudas>\n",
                        rp->avp->gpu_usage.usage
                    );
                } else if (rt == rsc_index(GPU_TYPE_ATI)) {
                    sprintf(buf,
                        "        <natis>%f</natis>\n",
                        rp->avp->gpu_usage.usage
                    );
                } else if (rt == rsc_index(GPU_TYPE_INTEL)) {
                    sprintf(buf,
                        "        <nintel_gpus>%f</nintel_gpus>\n",
                        rp->avp->gpu_usage.usage
                    );
                }
            }
            fprintf(f,
                "    <ip_result>\n"
                "        <name>%s</name>\n"
                "        <report_deadline>%.0f</report_deadline>\n"
                "        <time_remaining>%.2f</time_remaining>\n"
                "        <avg_ncpus>%f</avg_ncpus>\n"
                "%s"
                "    </ip_result>\n",
                rp->name,
                rp->report_deadline,
                x,
                rp->avp->avg_ncpus,
                buf
            );
        }
        fprintf(f, "</in_progress_results>\n");
    }
    FILE* cof = boinc_fopen(CLIENT_OPAQUE_FILENAME, "r");
    if (cof) {
        fprintf(f, "<client_opaque>\n<![CDATA[\n");
        copy_stream(cof, f);
        fprintf(f, "\n]]>\n</client_opaque>\n");
        fclose(cof);
    }

    fprintf(f, "</scheduler_request>\n");

    fclose(f);
    return 0;
}
Example #3
0
void do_client_simulation() {
    char buf[256], buf2[256];
    int retval;
    FILE* f;

    sprintf(buf, "%s%s", infile_prefix, CONFIG_FILE);
    cc_config.defaults();
    read_config_file(true, buf);

    log_flags.init();
    sprintf(buf, "%s%s", outfile_prefix, "log_flags.xml");
    f = fopen(buf, "r");
    if (f) {
        MIOFILE mf;
        mf.init_file(f);
        XML_PARSER xp(&mf);
        xp.get_tag();   // skip open tag
        log_flags.parse(xp);
        fclose(f);
    }

    gstate.add_platform("client simulator");
    sprintf(buf, "%s%s", infile_prefix, STATE_FILE_NAME);
    if (!boinc_file_exists(buf)) {
        fprintf(stderr, "No client state file\n");
        exit(1);
    }
    retval = gstate.parse_state_file_aux(buf);
    if (retval) {
        fprintf(stderr, "state file parse error %d\n", retval);
        exit(1);
    }

    // if tasks have pending transfers, mark as completed
    //
    for (unsigned int i=0; i<gstate.results.size(); i++) {
        RESULT* rp = gstate.results[i];
        if (rp->state() < RESULT_FILES_DOWNLOADED) {
            rp->set_state(RESULT_FILES_DOWNLOADED, "init");
        } else if (rp->state() == RESULT_FILES_UPLOADING) {
            rp->set_state(RESULT_FILES_UPLOADED, "init");
        }
    }

    check_app_config(infile_prefix);
    show_app_config();
    cc_config.show();
    log_flags.show();

    sprintf(buf, "%s%s", infile_prefix, GLOBAL_PREFS_FILE_NAME);
    sprintf(buf2, "%s%s", infile_prefix, GLOBAL_PREFS_OVERRIDE_FILE);
    gstate.read_global_prefs(buf, buf2);
    fprintf(index_file,
        "<h3>Output files</h3>\n"
        "<a href=%s>Summary</a>\n"
        "<br><a href=%s>Log file</a>\n",
        SUMMARY_FNAME, LOG_FNAME
    );

    // fill in GPU device nums and OpenCL flags
    //
    for (int i=0; i<coprocs.n_rsc; i++) {
        COPROC& cp = coprocs.coprocs[i];
        for (int j=0; j<cp.count; j++) {
            cp.device_nums[j] = j;
            if (cp.have_opencl) {
                cp.instance_has_opencl[j] = true;
            }
        }
    }
    set_no_rsc_config();
    process_gpu_exclusions();

    get_app_params();
    if (!include_empty_projects) {
        cull_projects();
    }
    fprintf(summary_file, "--------------------------\n");

    int j=0;
    for (unsigned int i=0; i<gstate.projects.size(); i++) {
        gstate.projects[i]->index = j++;
    }

    clear_backoff();

    gstate.log_show_projects();
    gstate.set_ncpus();
    work_fetch.init();

    //set_initial_rec();

    rec_adjust_period = delta;

    gstate.request_work_fetch("init");
    simulate();

    sim_results.compute_figures_of_merit();

    sprintf(buf, "%s%s", outfile_prefix, RESULTS_DAT_FNAME);
    f = fopen(buf, "w");
    sim_results.print(f);
    fclose(f);
    sprintf(buf, "%s%s", outfile_prefix, RESULTS_TXT_FNAME);
    f = fopen(buf, "w");
    sim_results.print(f, true);
    fclose(f);

    fprintf(summary_file,
        "Simulation done.\n"
        "-------------------------\n"
        "Figures of merit:\n"
    );

    sim_results.print(summary_file, true);

    double cpu_time;
    boinc_calling_thread_cpu_time(cpu_time);
    fprintf(summary_file,
        "-------------------------\n"
        "Simulator CPU time: %f secs\n"
        "-------------------------\n"
        "Peak FLOPS: CPU %.2fG GPU %.2fG\n",
        cpu_time,
        cpu_peak_flops()/1e9,
        gpu_peak_flops()/1e9
    );
    print_project_results(summary_file);

    fclose(rec_file);
    make_graph("REC", "rec", 0);
}
Example #4
0
// initialize the diagnostics environment.
//
int diagnostics_init(
    int _flags, const char* stdout_prefix, const char* stderr_prefix
) {
    // Check to see if we have already been called
    if (diagnostics_initialized) {
        return ERR_INVALID_PARAM;
    }
    diagnostics_initialized = true;

    // Setup initial values
    flags = _flags;
    snprintf(stdout_log, sizeof(stdout_log), "%s.txt", stdout_prefix);
    snprintf(stdout_archive, sizeof(stdout_archive), "%s.old", stdout_prefix);
    snprintf(stderr_log, sizeof(stderr_log), "%s.txt", stderr_prefix);
    snprintf(stderr_archive, sizeof(stderr_archive), "%s.old", stderr_prefix);
    strcpy(boinc_dir, "");
    strcpy(boinc_install_dir, "");
    boinc_proxy_enabled = 0;
    strcpy(boinc_proxy, "");
    strcpy(symstore, "");

    // Check for invalid parameter combinations
    if ((flags & BOINC_DIAG_REDIRECTSTDERR) && (flags & BOINC_DIAG_REDIRECTSTDERROVERWRITE)) {
        return ERR_INVALID_PARAM;
    }

    if ((flags & BOINC_DIAG_REDIRECTSTDOUT) && (flags & BOINC_DIAG_REDIRECTSTDOUTOVERWRITE)) {
        return ERR_INVALID_PARAM;
    }


    // Archive any old stderr.txt and stdout.txt files, if requested
    if (flags & BOINC_DIAG_ARCHIVESTDERR) {
        boinc_copy(stderr_log, stderr_archive);
    }

    if (flags & BOINC_DIAG_ARCHIVESTDOUT) {
        boinc_copy(stdout_log, stdout_archive);
    }


    // Redirect stderr and/or stdout, if requested
    //
    if (flags & BOINC_DIAG_REDIRECTSTDERR) {
        file_size(stderr_log, stderr_file_size);
        stderr_file = freopen(stderr_log, "a", stderr);
        if (!stderr_file) {
            return ERR_FOPEN;
        }
        setbuf(stderr_file, 0);
    }

    if (flags & BOINC_DIAG_REDIRECTSTDERROVERWRITE) {
        stderr_file = freopen(stderr_log, "w", stderr);
        if (!stderr_file) {
            return ERR_FOPEN;
        }
        setbuf(stderr_file, 0);
    }

    if (flags & BOINC_DIAG_REDIRECTSTDOUT) {
        file_size(stdout_log, stdout_file_size);
        stdout_file = freopen(stdout_log, "a", stdout);
        if (!stdout_file) {
            return ERR_FOPEN;
        }
    }

    if (flags & BOINC_DIAG_REDIRECTSTDOUTOVERWRITE) {
        stdout_file = freopen(stdout_log, "w", stdout);
        if (!stdout_file) {
            return ERR_FOPEN;
        }
    }


#if defined(_WIN32)

#if defined(_DEBUG)

    _CrtSetReportHook(boinc_message_reporting);

    if (flags & BOINC_DIAG_MEMORYLEAKCHECKENABLED) {
        SET_CRT_DEBUG_FIELD(_CRTDBG_LEAK_CHECK_DF);
    }

    if (flags & BOINC_DIAG_HEAPCHECKENABLED) {
        if (flags & BOINC_DIAG_HEAPCHECKEVERYALLOC) {
            SET_CRT_DEBUG_FIELD(_CRTDBG_CHECK_ALWAYS_DF);
        } else {
            SET_CRT_DEBUG_FIELD(_CRTDBG_CHECK_EVERY_1024_DF);
        }
    }

    if (flags & BOINC_DIAG_BOINCAPPLICATION) {
        if (flags & BOINC_DIAG_MEMORYLEAKCHECKENABLED) {
            _CrtMemCheckpoint(&start_snapshot); 
        }
    }

#endif // defined(_DEBUG)

    // Initialize the thread list structure
    //   The data for this structure should be set by
    //   boinc_init or boinc_init_graphics.
    diagnostics_init_thread_list();

    diagnostics_init_unhandled_exception_monitor();

    diagnostics_init_message_monitor();

#endif // defined(_WIN32)


    // Install unhandled exception filters and signal traps.
    if (BOINC_SUCCESS != boinc_install_signal_handlers()) {
        return ERR_SIGNAL_OP;
    }


    // Store various pieces of inforation for future use.
    if (flags & BOINC_DIAG_BOINCAPPLICATION) {
        char    buf[256];
        char    proxy_address[256];
        int     proxy_port;
        MIOFILE mf;
        FILE*   p;
#ifdef _WIN32
        LONG    lReturnValue;
        HKEY    hkSetupHive;
        DWORD   dwSize = 0;
#endif

        strcpy(buf, "");
        strcpy(proxy_address, "");
        proxy_port = 0;

#ifndef _USING_FCGI_
        p = fopen(INIT_DATA_FILE, "r");
#else
        p = FCGI::fopen(INIT_DATA_FILE, "r");
#endif
 
		if (p) {
			mf.init_file(p);
			while(mf.fgets(buf, sizeof(buf))) {
				if (match_tag(buf, "</app_init_data>")) break;
				else if (parse_str(buf, "<boinc_dir>", boinc_dir, 256)) continue;
				else if (parse_str(buf, "<symstore>", symstore, 256)) continue;
				else if (match_tag(buf, "<use_http_proxy/>")) {
					boinc_proxy_enabled = true;
					continue;
				}
				else if (parse_str(buf, "<http_server_name>", proxy_address, 256)) continue;
				else if (parse_int(buf, "<http_server_port>", proxy_port)) continue;
			}
			fclose(p);
		}

        if (boinc_proxy_enabled) {
            int buffer_used = snprintf(boinc_proxy, sizeof(boinc_proxy), "%s:%d", proxy_address, proxy_port);
            if ((sizeof(boinc_proxy) == buffer_used) || (-1 == buffer_used)) { 
                boinc_proxy[sizeof(boinc_proxy)-1] = '\0';
            }
        }

#ifdef _WIN32
        // Lookup the location of where BOINC was installed to and store
        //   that for future use.
        lReturnValue = RegOpenKeyEx(
            HKEY_LOCAL_MACHINE, 
            _T("SOFTWARE\\Space Sciences Laboratory, U.C. Berkeley\\BOINC Setup"),  
	        0, 
            KEY_READ,
            &hkSetupHive
        );
        if (lReturnValue == ERROR_SUCCESS) {
            // How large does our buffer need to be?
            dwSize = sizeof(boinc_install_dir);

            lReturnValue = RegQueryValueEx(
                hkSetupHive,
                _T("INSTALLDIR"),
                NULL,
                NULL,
                (LPBYTE)&boinc_install_dir,
                &dwSize
            );
        }

        if (hkSetupHive) RegCloseKey(hkSetupHive);
#endif
    }

    return BOINC_SUCCESS;
}
Example #5
0
int VBOX_JOB::parse() {
    MIOFILE mf;
    std::string str;
    char buf[1024];

    boinc_resolve_filename(JOB_FILENAME, buf, sizeof(buf));
    FILE* f = boinc_fopen(buf, "r");
    if (!f) {
        vboxlog_msg("VBOX_JOB::parse(): can't open job file %s", buf);
        return ERR_FOPEN;
    }
    mf.init_file(f);
    XML_PARSER xp(&mf);

    if (!xp.parse_start("vbox_job")) return ERR_XML_PARSE;
    while (!xp.get_tag()) {
        if (!xp.is_tag) {
            vboxlog_msg("VBOX_JOB::parse(): unexpected text %s", xp.parsed_tag);
            continue;
        }
        if (xp.match_tag("/vbox_job")) {
            fclose(f);
            return 0;
        }
        else if (xp.parse_string("vm_disk_controller_type", vm_disk_controller_type)) continue;
        else if (xp.parse_string("vm_disk_controller_model", vm_disk_controller_model)) continue;
        else if (xp.parse_string("os_name", os_name)) continue;
        else if (xp.parse_double("memory_size_mb", memory_size_mb)) continue;
        else if (xp.parse_double("job_duration", job_duration)) continue;
        else if (xp.parse_double("minimum_checkpoint_interval", minimum_checkpoint_interval)) continue;
        else if (xp.parse_double("minimum_heartbeat_interval", minimum_heartbeat_interval)) continue;
        else if (xp.parse_string("fraction_done_filename", fraction_done_filename)) continue;
        else if (xp.parse_string("heartbeat_filename", heartbeat_filename)) continue;
        else if (xp.parse_string("completion_trigger_file", completion_trigger_file)) continue;
        else if (xp.parse_string("temporary_exit_trigger_file", temporary_exit_trigger_file)) continue;
        else if (xp.parse_bool("enable_cern_dataformat", enable_cern_dataformat)) continue;
        else if (xp.parse_bool("enable_network", enable_network)) continue;
        else if (xp.parse_bool("network_bridged_mode", network_bridged_mode)) continue;
        else if (xp.parse_bool("enable_shared_directory", enable_shared_directory)) continue;
        else if (xp.parse_bool("enable_scratch_directory", enable_scratch_directory)) continue;
        else if (xp.parse_bool("enable_floppyio", enable_floppyio)) continue;
        else if (xp.parse_bool("enable_cache_disk", enable_cache_disk)) continue;
        else if (xp.parse_bool("enable_isocontextualization", enable_isocontextualization)) continue;
        else if (xp.parse_bool("enable_remotedesktop", enable_remotedesktop)) continue;
        else if (xp.parse_bool("enable_gbac", enable_gbac)) continue;
        else if (xp.parse_bool("enable_screenshots_on_error", enable_screenshots_on_error)) continue;
        else if (xp.parse_bool("enable_graphics_support", enable_graphics_support)) continue;
        else if (xp.parse_bool("enable_vm_savestate_usage", enable_vm_savestate_usage)) continue;
        else if (xp.parse_bool("disable_automatic_checkpoints", disable_automatic_checkpoints)) continue;
        else if (xp.parse_bool("boot_iso", boot_iso)) continue;
        else if (xp.parse_int("pf_guest_port", pf_guest_port)) continue;
        else if (xp.parse_int("pf_host_port", pf_host_port)) continue;
        else if (xp.parse_string("copy_to_shared", str)) {
            copy_to_shared.push_back(str);
            continue;
        }
        else if (xp.parse_string("trickle_trigger_file", str)) {
            trickle_trigger_files.push_back(str);
            continue;
        }
        else if (xp.parse_string("intermediate_upload_file", str)) {
            VBOX_INTERMEDIATE_UPLOAD iu;
            iu.clear();
            iu.file = str;
            intermediate_upload_files.push_back(iu);
            continue;
        }
        else if (xp.match_tag("port_forward")) {
            VBOX_PORT_FORWARD pf;
            pf.clear();
            pf.parse(xp);
            if (pf.nports) {
                VBOX_PORT_FORWARD pf_range;
                pf_range = pf;
                pf_range.nports = 0;
                for (int i = 0; i < pf.nports; ++i) {
                    port_forwards.push_back(pf_range);
                    pf_range.host_port++;
                    pf_range.guest_port++;
                }
            } else {
                port_forwards.push_back(pf);
            }
        }
        vboxlog_msg("VBOX_JOB::parse(): unexpected text %s", xp.parsed_tag);
    }
    fclose(f);
    return ERR_XML_PARSE;
}
Example #6
0
// parse an account_*.xml file, ignoring <venue> elements
// (since we don't know the host venue yet)
//
int PROJECT::parse_account(FILE* in) {
    char buf2[256];
    int retval;
    bool in_project_prefs = false, btemp;
    double dtemp;

    for (int i=0; i<coprocs.n_rsc; i++) {
        no_rsc_pref[i] = false;
    }
    MIOFILE mf;
    XML_PARSER xp(&mf);
    mf.init_file(in);

    strcpy(master_url, "");
    strcpy(authenticator, "");
    while (!xp.get_tag()) {
        if (xp.match_tag("account")) continue;
        if (xp.match_tag("project_preferences")) {
            in_project_prefs = true;
            continue;
        }
        if (xp.match_tag("/project_preferences")) {
            in_project_prefs = false;
            continue;
        }
        if (xp.match_tag("/account")) {
            return 0;
        } else if (xp.match_tag("venue")) {
            std::string devnull;
            retval = copy_element_contents(xp.f->f, "</venue>", devnull);
            if (retval) return retval;
            continue;
        } else if (xp.parse_str("master_url", master_url, sizeof(master_url))) {
            canonicalize_master_url(master_url, sizeof(master_url));
            continue;
        } else if (xp.parse_str("authenticator", authenticator, sizeof(authenticator))) continue;
        else if (xp.parse_double("resource_share", dtemp)) {
            if (ams_resource_share < 0) {
                resource_share = dtemp;
            }
            continue;
        }
        else if (xp.parse_bool("no_cpu", btemp)) {
            if (btemp) handle_no_rsc_pref(this, "CPU");
            continue;
        }

        // deprecated
        else if (xp.parse_bool("no_cuda", btemp)) {
            if (btemp) handle_no_rsc_pref(this, GPU_TYPE_NVIDIA);
            continue;
        }
        else if (xp.parse_bool("no_ati", btemp)) {
            if (btemp) handle_no_rsc_pref(this, GPU_TYPE_ATI);
            continue;
        }
        else if (xp.parse_bool("no_intel_gpu", btemp)) {
            if (btemp) handle_no_rsc_pref(this, GPU_TYPE_INTEL);
            continue;
        }

        else if (xp.parse_str("no_rsc", buf2, sizeof(buf2))) {
            handle_no_rsc_pref(this, buf2);
            continue;
        }
        else if (xp.parse_str("project_name", project_name, sizeof(project_name))) continue;
        else if (xp.match_tag("gui_urls")) {
            string foo;
            retval = copy_element_contents(xp.f->f, "</gui_urls>", foo);
            if (retval) return retval;
            gui_urls = "<gui_urls>\n"+foo+"</gui_urls>\n";
            continue;
        } else if (xp.match_tag("project_specific")) {
            retval = copy_element_contents(
                xp.f->f,
                "</project_specific>",
                project_specific_prefs
            );
            if (retval) return retval;
            continue;
        } else {
            // don't show unparsed XML errors if we're in project prefs
            //
            if (!in_project_prefs && log_flags.unparsed_xml) {
                msg_printf(0, MSG_INFO,
                    "[unparsed_xml] PROJECT::parse_account(): unrecognized: %s\n",
                    xp.parsed_tag
                );
            }
        }
    }
    return ERR_XML_PARSE;
}
Example #7
0
// do an account manager RPC;
// if URL is null, detach from current account manager
//
int ACCT_MGR_OP::do_rpc(ACCT_MGR_INFO& _ami, bool _via_gui) {
    int retval;
    unsigned int i;
    char buf[256];

    ami = _ami;

    error_num = ERR_IN_PROGRESS;
    error_str = "";
    via_gui = _via_gui;
    global_prefs_xml = "";

    // if null URL, detach from current AMS
    //
    if (!strlen(ami.master_url) && strlen(gstate.acct_mgr_info.master_url)) {
        msg_printf(NULL, MSG_INFO, "Removing account manager info");
        gstate.acct_mgr_info.clear();
        boinc_delete_file(ACCT_MGR_URL_FILENAME);
        boinc_delete_file(ACCT_MGR_LOGIN_FILENAME);
        error_num = 0;
        for (i=0; i<gstate.projects.size(); i++) {
            gstate.projects[i]->detach_ams();
        }
        ::rss_feeds.update_feed_list();
        gstate.set_client_state_dirty("detach from AMS");
        return 0;
    }

    canonicalize_master_url(ami.master_url, sizeof(ami.master_url));
    if (!valid_master_url(ami.master_url)) {
        error_num = ERR_INVALID_URL;
        return 0;
    }

    FILE* f = boinc_fopen(ACCT_MGR_REQUEST_FILENAME, "w");
    if (!f) return ERR_FOPEN;
    fprintf(f,
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
        "<acct_mgr_request>\n"
    );
    if (strlen(ami.authenticator)) {
        fprintf(f,
            "   <authenticator>%s</authenticator>\n",
            ami.authenticator
        );
    } else {
        fprintf(f,
            "   <name>%s</name>\n"
            "   <password_hash>%s</password_hash>\n",
            ami.login_name, ami.password_hash
        );
    }
    fprintf(f,
        "   <host_cpid>%s</host_cpid>\n"
        "   <domain_name>%s</domain_name>\n"
        "   <client_version>%d.%d.%d</client_version>\n"
        "   <run_mode>%s</run_mode>\n",
        gstate.host_info.host_cpid,
        gstate.host_info.domain_name,
        gstate.core_client_version.major,
        gstate.core_client_version.minor,
        gstate.core_client_version.release,
        run_mode_name[gstate.cpu_run_mode.get_perm()]
    );
    gstate.write_platforms(NULL, f);
    if (strlen(gstate.acct_mgr_info.previous_host_cpid)) {
        fprintf(f,
            "   <previous_host_cpid>%s</previous_host_cpid>\n",
            gstate.acct_mgr_info.previous_host_cpid
        );
    }

    // If the AMS requested it, send GUI RPC port and password.
    // This is for the "farm" account manager so it
    // can know where to send GUI RPC requests to
    // without having to configure each host
    //
    if (gstate.acct_mgr_info.send_gui_rpc_info) {
        if (gstate.cmdline_gui_rpc_port) {
            fprintf(f,"   <gui_rpc_port>%d</gui_rpc_port>\n", gstate.cmdline_gui_rpc_port);
        } else {
            fprintf(f,"   <gui_rpc_port>%d</gui_rpc_port>\n", GUI_RPC_PORT);
        }
        if (boinc_file_exists(GUI_RPC_PASSWD_FILE)) {
            char gui_rpc_password[256];
            safe_strcpy(gui_rpc_password, "");
            FILE* pwdf = fopen(GUI_RPC_PASSWD_FILE, "r");
            if (pwdf) {
                if (fgets(gui_rpc_password, 256, pwdf)) {
                    strip_whitespace(gui_rpc_password);
                }
                fclose(pwdf);
            }
            fprintf(f,
                "   <gui_rpc_password>%s</gui_rpc_password>\n",
                gui_rpc_password
            );
        }
    }
    for (i=0; i<gstate.projects.size(); i++) {
        PROJECT* p = gstate.projects[i];
        double not_started_dur, in_progress_dur;
        p->get_task_durs(not_started_dur, in_progress_dur);
        fprintf(f,
            "   <project>\n"
            "      <url>%s</url>\n"
            "      <project_name>%s</project_name>\n"
            "      <suspended_via_gui>%d</suspended_via_gui>\n"
            "      <hostid>%d</hostid>\n"
            "      <not_started_dur>%f</not_started_dur>\n"
            "      <in_progress_dur>%f</in_progress_dur>\n"
            "      <attached_via_acct_mgr>%d</attached_via_acct_mgr>\n"
            "      <dont_request_more_work>%d</dont_request_more_work>\n"
            "      <detach_when_done>%d</detach_when_done>\n"
            "      <ended>%d</ended>\n"
            "      <resource_share>%f</resource_share>\n"
            "      <disk_usage>%f</disk_usage>\n"
            "      <disk_share>%f</disk_share>\n",
            p->master_url,
            p->project_name,
            p->suspended_via_gui?1:0,
            p->hostid,
            not_started_dur,
            in_progress_dur,
            p->attached_via_acct_mgr?1:0,
            p->dont_request_more_work?1:0,
            p->detach_when_done?1:0,
            p->ended?1:0,
            p->resource_share,
            p->disk_usage,
            p->disk_share
        );
        
        // send work and starvation-related info
        //
        if (ami.dynamic) {
            fprintf(f,
                "      <nrpc_failures>%d</nrpc_failures>\n"
                "      <cpu_ec>%f</cpu_ec>\n"
                "      <cpu_time>%f</cpu_time>\n"
                "      <gpu_ec>%f</gpu_ec>\n"
                "      <gpu_time>%f</gpu_time>\n"
                "      <njobs_success>%d</njobs_success>\n"
                "      <njobs_error>%d</njobs_error>\n",
                p->nrpc_failures,
                p->cpu_ec,
                p->cpu_time,
                p->gpu_ec,
                p->gpu_time,
                p->njobs_success,
                p->njobs_error
            );
            for (int j=0; j<coprocs.n_rsc; j++) {
                if (p->sched_req_no_work[j]) {
                    fprintf(f,
                        "    <sched_req_no_work>%s</sched_req_no_work>\n",
                        coprocs.coprocs[j].type
                    );
                }
            }
        }

        if (p->attached_via_acct_mgr) {
            fprintf(f,
                "      <account_key>%s</account_key>\n",
                p->authenticator
            );
        }
        fprintf(f,
            "   </project>\n"
        );
    }
    MIOFILE mf;
    mf.init_file(f);

    // send working prefs
    //
    fprintf(f, "<working_global_preferences>\n");
    gstate.global_prefs.write(mf);
    fprintf(f, "</working_global_preferences>\n");

    if (boinc_file_exists(GLOBAL_PREFS_FILE_NAME)) {
        FILE* fprefs = fopen(GLOBAL_PREFS_FILE_NAME, "r");
        if (fprefs) {
            copy_stream(fprefs, f);
            fclose(fprefs);
        }
    }
    gstate.host_info.write(mf, !cc_config.suppress_net_info, true);
    if (strlen(gstate.acct_mgr_info.opaque)) {
        fprintf(f,
            "   <opaque>\n%s\n"
            "   </opaque>\n",
            gstate.acct_mgr_info.opaque
        );
    }
    gstate.time_stats.write(mf, true);
    gstate.net_stats.write(mf);
    fprintf(f, "</acct_mgr_request>\n");
    fclose(f);
    snprintf(buf, sizeof(buf), "%srpc.php", ami.master_url);
    retval = gui_http->do_rpc_post(
        this, buf, ACCT_MGR_REQUEST_FILENAME, ACCT_MGR_REPLY_FILENAME, true
    );
    if (retval) {
        error_num = retval;
        return retval;
    }
    msg_printf(NULL, MSG_INFO, "Contacting account manager at %s", ami.master_url);

    return 0;
}
Example #8
0
int parse_init_data_file(FILE* f, APP_INIT_DATA& ai) {
    int retval;
    bool flag;

    MIOFILE mf;
    mf.init_file(f);
    XML_PARSER xp(&mf);

    if (!xp.parse_start("app_init_data")) {
        fprintf(stderr, "%s: no start tag in app init data\n",
            time_to_string(dtime())
        );
        return ERR_XML_PARSE;
    }

    if (ai.project_preferences) {
        free(ai.project_preferences);
        ai.project_preferences = 0;
    }
    ai.clear();
    ai.fraction_done_start = 0;
    ai.fraction_done_end = 1;

    while (!xp.get_tag()) {
        if (!xp.is_tag) {
            fprintf(stderr,
                "%s: unexpected text in init_data.xml: %s\n",
                time_to_string(dtime()), xp.parsed_tag
            );
            continue;
        }
        if (xp.match_tag("/app_init_data")) return 0;
        if (xp.match_tag("project_preferences")) {
            retval = dup_element(f, "project_preferences", &ai.project_preferences);
            if (retval) return retval;
            continue;
        }
        if (xp.match_tag("global_preferences")) {
            GLOBAL_PREFS_MASK mask;
            retval = ai.global_prefs.parse(xp, "", flag, mask);
            if (retval) return retval;
            continue;
        }
        if (xp.match_tag("host_info")) {
            ai.host_info.parse(xp);
            continue;
        }
        if (xp.match_tag("proxy_info")) {
            ai.proxy_info.parse(xp);
            continue;
        }
        if (xp.parse_int("major_version", ai.major_version)) continue;
        if (xp.parse_int("minor_version", ai.minor_version)) continue;
        if (xp.parse_int("release", ai.release)) continue;
        if (xp.parse_int("app_version", ai.app_version)) continue;
        if (xp.parse_str("app_name", ai.app_name, sizeof(ai.app_name))) continue;
        if (xp.parse_str("symstore", ai.symstore, sizeof(ai.symstore))) continue;
        if (xp.parse_str("acct_mgr_url", ai.acct_mgr_url, sizeof(ai.acct_mgr_url))) continue;
        if (xp.parse_int("userid", ai.userid)) continue;
        if (xp.parse_int("teamid", ai.teamid)) continue;
        if (xp.parse_int("hostid", ai.hostid)) continue;
        if (xp.parse_str("user_name", ai.user_name, sizeof(ai.user_name))) {
            xml_unescape(ai.user_name);
            continue;
        }
        if (xp.parse_str("team_name", ai.team_name, sizeof(ai.team_name))) {
            xml_unescape(ai.team_name);
            continue;
        }
        if (xp.parse_str("project_dir", ai.project_dir, sizeof(ai.project_dir))) continue;
        if (xp.parse_str("boinc_dir", ai.boinc_dir, sizeof(ai.boinc_dir))) continue;
        if (xp.parse_str("authenticator", ai.authenticator, sizeof(ai.authenticator))) continue;
        if (xp.parse_str("wu_name", ai.wu_name, sizeof(ai.wu_name))) continue;
        if (xp.parse_str("result_name", ai.result_name, sizeof(ai.result_name))) continue;
#ifdef _WIN32
        if (xp.parse_str("comm_obj_name", ai.shmem_seg_name, sizeof(ai.shmem_seg_name))) continue;
#else
        if (xp.parse_int("shm_key", ai.shmem_seg_name)) continue;
#endif
        if (xp.parse_int("slot", ai.slot)) continue;
        if (xp.parse_int("client_pid", ai.client_pid)) continue;
        if (xp.parse_double("user_total_credit", ai.user_total_credit)) continue;
        if (xp.parse_double("user_expavg_credit", ai.user_expavg_credit)) continue;
        if (xp.parse_double("host_total_credit", ai.host_total_credit)) continue;
        if (xp.parse_double("host_expavg_credit", ai.host_expavg_credit)) continue;
        if (xp.parse_double("resource_share_fraction", ai.resource_share_fraction)) continue;
        if (xp.parse_double("rsc_fpops_est", ai.rsc_fpops_est)) continue;
        if (xp.parse_double("rsc_fpops_bound", ai.rsc_fpops_bound)) continue;
        if (xp.parse_double("rsc_memory_bound", ai.rsc_memory_bound)) continue;
        if (xp.parse_double("rsc_disk_bound", ai.rsc_disk_bound)) continue;
        if (xp.parse_double("computation_deadline", ai.computation_deadline)) continue;
        if (xp.parse_double("wu_cpu_time", ai.wu_cpu_time)) continue;
        if (xp.parse_double("starting_elapsed_time", ai.starting_elapsed_time)) continue;
        if (xp.parse_bool("using_sandbox", ai.using_sandbox)) continue;
        if (xp.parse_bool("vm_extensions_disabled", ai.vm_extensions_disabled)) continue;
        if (xp.parse_double("checkpoint_period", ai.checkpoint_period)) continue;
        if (xp.parse_str("gpu_type", ai.gpu_type, sizeof(ai.gpu_type))) continue;
        if (xp.parse_int("gpu_device_num", ai.gpu_device_num)) continue;
        if (xp.parse_int("gpu_opencl_dev_index", ai.gpu_opencl_dev_index)) continue;
        if (xp.parse_double("gpu_usage", ai.gpu_usage)) continue;
        if (xp.parse_double("ncpus", ai.ncpus)) continue;
        if (xp.parse_double("fraction_done_start", ai.fraction_done_start)) continue;
        if (xp.parse_double("fraction_done_end", ai.fraction_done_end)) continue;
        if (xp.parse_bool("vbox_window", ai.vbox_window)) continue;
        xp.skip_unexpected(false, "parse_init_data_file");
    }
    fprintf(stderr, "%s: parse_init_data_file: no end tag\n",
        time_to_string(dtime())
    );
    return ERR_XML_PARSE;
}
Example #9
0
// called at client startup.
// If currently using an AM, read its URL and login files
//
int ACCT_MGR_INFO::init() {
    MIOFILE mf;
    FILE*   p;
    int retval;

    clear();
    p = fopen(ACCT_MGR_URL_FILENAME, "r");
    if (!p) {
        // if not using acct mgr, make sure projects not flagged,
        // otherwise won't be able to detach them.
        //
        for (unsigned int i=0; i<gstate.projects.size(); i++) {
            gstate.projects[i]->attached_via_acct_mgr = false;
        }
        return 0;
    }
    mf.init_file(p);
    XML_PARSER xp(&mf);
    if (!xp.parse_start("acct_mgr")) {
        //
    }
    while (!xp.get_tag()) {
        if (!xp.is_tag) {
            printf("unexpected text: %s\n", xp.parsed_tag);
            continue;
        }
        if (xp.match_tag("/acct_mgr")) break;
        else if (xp.parse_str("name", project_name, 256)) continue;
        else if (xp.parse_str("url", master_url, 256)) continue;
        else if (xp.parse_bool("send_gui_rpc_info", send_gui_rpc_info)) continue;
        else if (xp.match_tag("signing_key")) {
            retval = xp.element_contents("</signing_key>", signing_key, sizeof(signing_key));
            if (retval) {
                msg_printf(NULL, MSG_INFO,
                    "error parsing <signing_key> in acct_mgr_url.xml"
                );
            }
            continue;
        }
        else if (xp.parse_bool("cookie_required", cookie_required)) continue;
        else if (xp.parse_str("cookie_failure_url", cookie_failure_url, 256)) continue;
        if (log_flags.unparsed_xml) {
            msg_printf(NULL, MSG_INFO,
                "[unparsed_xml] ACCT_MGR_INFO::init: unrecognized %s",
                xp.parsed_tag
            );
        }
        xp.skip_unexpected(log_flags.unparsed_xml, "ACCT_MGR_INFO::init");
    }
    fclose(p);

    p = fopen(ACCT_MGR_LOGIN_FILENAME, "r");
    if (p) {
        parse_login_file(p);
        fclose(p);
    }
    if (using_am()) {
        msg_printf(NULL, MSG_INFO, "Using account manager %s", project_name);
        if (strlen(user_name)) {
            msg_printf(NULL, MSG_INFO, "Account manager login: %s", user_name);
        }
    }
    return 0;
}
Example #10
0
// parse RPC reply from account manager
//
int ACCT_MGR_OP::parse(FILE* f) {
    string message;
    int retval;
    MIOFILE mf;
    mf.init_file(f);
    XML_PARSER xp(&mf);

    accounts.clear();
    error_str = "";
    error_num = 0;
    repeat_sec = 0;
    safe_strcpy(host_venue, "");
    safe_strcpy(ami.opaque, "");
    ami.no_project_notices = false;
    ami.dynamic = false;
    rss_feeds.clear();
    if (!xp.parse_start("acct_mgr_reply")) return ERR_XML_PARSE;
    while (!xp.get_tag()) {
        if (!xp.is_tag) {
            if (log_flags.unparsed_xml) {
                msg_printf(0, MSG_INFO,
                    "[unparsed_xml] ACCT_MGR_OP::parse: unexpected text %s",
                    xp.parsed_tag
                );
            }
            continue;
        }
        if (xp.match_tag("/acct_mgr_reply")) return 0;
        if (xp.parse_str("name", ami.project_name, 256)) continue;
        if (xp.parse_str("user_name", ami.user_name, sizeof(ami.user_name))) {
            xml_unescape(ami.user_name);
            continue;
        }
        if (xp.parse_str("team_name", ami.team_name, sizeof(ami.team_name))) {
            xml_unescape(ami.team_name);
            continue;
        }
        if (xp.parse_str("authenticator", ami.authenticator, 256)) continue;
        if (xp.parse_int("error_num", error_num)) continue;
        if (xp.parse_string("error", error_str)) continue;
        if (xp.parse_string("error_msg", error_str)) continue;
        if (xp.parse_double("repeat_sec", repeat_sec)) continue;
        if (xp.parse_bool("dynamic", ami.dynamic)) continue;
        if (xp.parse_string("message", message)) {
            msg_printf(NULL, MSG_INFO, "Account manager: %s", message.c_str());
            continue;
        }
        if (xp.match_tag("opaque")) {
            retval = xp.element_contents("</opaque>", ami.opaque, sizeof(ami.opaque));
            if (retval) return retval;
            continue;
        }
        if (xp.match_tag("signing_key")) {
            retval = xp.element_contents("</signing_key>", ami.signing_key, sizeof(ami.signing_key));
            if (retval) return retval;
            continue;
        }
        if (xp.match_tag("account")) {
            AM_ACCOUNT account;
            retval = account.parse(xp);
            if (retval) {
                msg_printf(NULL, MSG_INTERNAL_ERROR,
                    "Can't parse account in account manager reply: %s",
                    boincerror(retval)
                );
            } else {
                accounts.push_back(account);
            }
            continue;
        }
        if (xp.match_tag("global_preferences")) {
            retval = copy_element_contents(
                f,
                "</global_preferences>",
                global_prefs_xml
            );
            if (retval) {
                msg_printf(NULL, MSG_INTERNAL_ERROR,
                    "Can't parse global prefs in account manager reply: %s",
                    boincerror(retval)
                );
                return retval;
            }
            continue;
        }
        if (xp.parse_str("host_venue", host_venue, sizeof(host_venue))) {
            continue;
        }
        if (xp.match_tag("rss_feeds")) {
            got_rss_feeds = true;
            parse_rss_feed_descs(xp, rss_feeds);
            continue;
        }
        if (xp.parse_bool("no_project_notices", ami.no_project_notices)) {
            continue;
        }
        if (xp.match_tag("user_keywords")) {
            retval = ami.user_keywords.parse(xp);
            if (retval) return retval;
            continue;
        }
        if (log_flags.unparsed_xml) {
            msg_printf(NULL, MSG_INFO,
                "[unparsed_xml] ACCT_MGR_OP::parse: unrecognized tag <%s>",
                xp.parsed_tag
            );
        }
        xp.skip_unexpected(log_flags.unparsed_xml, "ACCT_MGR_OP::parse");
    }
    return ERR_XML_PARSE;
}
// do an account manager RPC;
// if URL is null, detach from current account manager
//
int ACCT_MGR_OP::do_rpc(
    std::string _url, std::string name, std::string password_hash,
    bool _via_gui
) {
    int retval;
    unsigned int i;
    char url[256], password[256], buf[256];
    FILE *pwdf;

    strlcpy(url, _url.c_str(), sizeof(url));

    error_num = ERR_IN_PROGRESS;
    via_gui = _via_gui;
    if (global_prefs_xml) {
        free(global_prefs_xml);
        global_prefs_xml = 0;
    }

    // if null URL, detach from current AMS
    //
    if (!strlen(url) && strlen(gstate.acct_mgr_info.master_url)) {
        msg_printf(NULL, MSG_INFO, "Removing account manager info");
        gstate.acct_mgr_info.clear();
        boinc_delete_file(ACCT_MGR_URL_FILENAME);
        boinc_delete_file(ACCT_MGR_LOGIN_FILENAME);
        error_num = 0;
        for (i=0; i<gstate.projects.size(); i++) {
            gstate.projects[i]->detach_ams();
        }
        return 0;
    }

    canonicalize_master_url(url);
    if (!valid_master_url(url)) {
        error_num = ERR_INVALID_URL;
        return 0;
    }

    strlcpy(ami.master_url, url, sizeof(ami.master_url));
    strlcpy(ami.project_name, "", sizeof(ami.project_name));
    strlcpy(ami.login_name, name.c_str(), sizeof(ami.login_name));
    strlcpy(ami.password_hash, password_hash.c_str(), sizeof(ami.password_hash));

    FILE* f = boinc_fopen(ACCT_MGR_REQUEST_FILENAME, "w");
    if (!f) return ERR_FOPEN;
    fprintf(f,
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
        "<acct_mgr_request>\n"
        "   <name>%s</name>\n"
        "   <password_hash>%s</password_hash>\n"
        "   <host_cpid>%s</host_cpid>\n"
        "   <domain_name>%s</domain_name>\n"
        "   <client_version>%d.%d.%d</client_version>\n"
        "   <run_mode>%s</run_mode>\n",
        name.c_str(), password_hash.c_str(),
        gstate.host_info.host_cpid,
        gstate.host_info.domain_name,
        gstate.core_client_version.major,
        gstate.core_client_version.minor,
        gstate.core_client_version.release,
        run_mode_name[gstate.cpu_run_mode.get_perm()]
    );
    if (strlen(gstate.acct_mgr_info.previous_host_cpid)) {
        fprintf(f,
            "   <previous_host_cpid>%s</previous_host_cpid>\n",
            gstate.acct_mgr_info.previous_host_cpid
        );
    }

    // If the AMS requested it, send GUI RPC port and password hash.
    // This is for the "farm" account manager so it
    // can know where to send GUI RPC requests to
    // without having to configure each host
    //
    if (gstate.acct_mgr_info.send_gui_rpc_info) {
        if (gstate.cmdline_gui_rpc_port) {
            fprintf(f,"   <gui_rpc_port>%d</gui_rpc_port>\n", gstate.cmdline_gui_rpc_port);
        } else {
            fprintf(f,"   <gui_rpc_port>%d</gui_rpc_port>\n", GUI_RPC_PORT);
        }
        if (boinc_file_exists(GUI_RPC_PASSWD_FILE)) {
            strcpy(password, "");
            pwdf = fopen(GUI_RPC_PASSWD_FILE, "r");
            if (pwdf) {
                if (fgets(password, 256, pwdf)) {
                    strip_whitespace(password);
                }
                fclose(pwdf);
            }
            fprintf(f,"   <gui_rpc_password>%s</gui_rpc_password>\n", password);
        }
    }
    for (i=0; i<gstate.projects.size(); i++) {
        PROJECT* p = gstate.projects[i];
        double not_started_dur, in_progress_dur;
        p->get_task_durs(not_started_dur, in_progress_dur);
        fprintf(f,
            "   <project>\n"
            "      <url>%s</url>\n"
            "      <project_name>%s</project_name>\n"
            "      <suspended_via_gui>%d</suspended_via_gui>\n"
            "      <account_key>%s</account_key>\n"
            "      <hostid>%d</hostid>\n"
            "      <not_started_dur>%f</not_started_dur>\n"
            "      <in_progress_dur>%f</in_progress_dur>\n"
            "      <attached_via_acct_mgr>%d</attached_via_acct_mgr>\n"
            "      <dont_request_more_work>%d</dont_request_more_work>\n"
            "      <detach_when_done>%d</detach_when_done>\n"
            "      <ended>%d</ended>\n"
            "   </project>\n",
            p->master_url,
            p->project_name,
            p->suspended_via_gui?1:0,
            p->authenticator,
            p->hostid,
            not_started_dur,
            in_progress_dur,
            p->attached_via_acct_mgr?1:0,
            p->dont_request_more_work?1:0,
            p->detach_when_done?1:0,
            p->ended?1:0
        );
    }
    MIOFILE mf;
    mf.init_file(f);

    // send working prefs
    //
    fprintf(f, "<working_global_preferences>\n");
    gstate.global_prefs.write(mf);
    fprintf(f, "</working_global_preferences>\n");

    if (boinc_file_exists(GLOBAL_PREFS_FILE_NAME)) {
        FILE* fprefs = fopen(GLOBAL_PREFS_FILE_NAME, "r");
        if (fprefs) {
            copy_stream(fprefs, f);
            fclose(fprefs);
        }
    }
    gstate.host_info.write(mf, !config.suppress_net_info, true);
    if (strlen(gstate.acct_mgr_info.opaque)) {
        fprintf(f,
            "   <opaque>\n%s\n"
            "   </opaque>\n",
            gstate.acct_mgr_info.opaque
        );
    }
    gstate.time_stats.write(mf, true);
    gstate.net_stats.write(mf);
    fprintf(f, "</acct_mgr_request>\n");
    fclose(f);
    sprintf(buf, "%srpc.php", url);
    retval = gui_http->do_rpc_post(
        this, buf, ACCT_MGR_REQUEST_FILENAME, ACCT_MGR_REPLY_FILENAME, true
    );
    if (retval) {
        error_num = retval;
        return retval;
    }
    msg_printf(NULL, MSG_INFO, "Contacting account manager at %s", url);

    return 0;
}
Example #12
0
bool wu_is_infeasible_custom(WORKUNIT& wu, APP& app, BEST_APP_VERSION& bav) {
#if 0
    // example: if WU name contains "_v1", don't use GPU apps.
    // Note: this is slightly suboptimal.
    // If the host is able to accept both GPU and CPU jobs,
    // we'll skip this job rather than send it for the CPU.
    // Fixing this would require a big architectural change.
    //
    if (strstr(wu.name, "_v1") && bav.host_usage.uses_gpu()) {
        return true;
    }
#endif
#if 0
    // example: for NVIDIA GPU app,
    // wu.batch is the minimum number of GPU processors.
    // Don't send if #procs is less than this.
    //
    if (!strcmp(app.name, "foobar") && bav.host_usage.proc_type == PROC_TYPE_NVIDIA_GPU) {
        int n = g_request->coprocs.nvidia.prop.multiProcessorCount;
        if (n < wu.batch) {
           return true;
        }
    }
#endif
#if defined(SETIATHOME)
    bool infeasible=false;
    static bool send_vlar_to_gpu=false;
    static bool sah_config_checked=false;
    char buff[256];

    // check the projects app config whether to send vlar wus to gpus 
    if (!sah_config_checked) {
        MIOFILE mf;
        XML_PARSER xp(&mf);
#ifndef _USING_FCGI_
        FILE *f=fopen(config.project_path("sah_config.xml"),"r");
#else
        FCGI_FILE *f=FCGI::fopen(config.project_path("sah_config.xml"),"r");
#endif
        if (f) {
            mf.init_file(f);
            if (xp.parse_start("sah") && xp.parse_start("config")) {
                while (!xp.get_tag()) {
                   if (!xp.is_tag) continue;
                   if (xp.parse_bool("send_vlar_to_gpu",send_vlar_to_gpu)) continue;
                   if (xp.match_tag("/config")) break;
                   xp.skip_unexpected(false, "wu_is_infeasible_custom");
                }
            }
            fclose(f);
        }
        sah_config_checked=true;
    } 
    // example: if CUDA app and WU name contains ".vlar", don't send
    // to NVIDIA, INTEL or older ATI cards
    //
    if (bav.host_usage.uses_gpu() && strstr(wu.name, ".vlar")) {
        if (send_vlar_to_gpu) {
            if (bav.host_usage.proc_type == PROC_TYPE_AMD_GPU) {
                // ATI GPUs older than HD7870
                COPROC_ATI &cp = g_request->coprocs.ati;
                if (cp.count && (cp.attribs.target < 15)) {
                  infeasible=true;
                }
            } else if (bav.host_usage.proc_type == PROC_TYPE_NVIDIA_GPU)  {
                COPROC_NVIDIA &cp = g_request->coprocs.nvidia;
                if (cp.count) {
                    int v = (cp.prop.major)*100 + cp.prop.minor;
                    if (v < 300) {
                        infeasible=true;
                    }
                }
            } else {   
              // all other GPUS
              infeasible=true;
            }
        } else {
            infeasible=true;
        }
    }
    if (infeasible && config.debug_version_select) {
        log_messages.printf(MSG_NORMAL,
            "[version] [setiathome] VLAR workunit is infeasible on this GPU\n"
        );
    }
    return infeasible;
#endif
    return false;
}
Example #13
0
int COPROCS::read_coproc_info_file(vector<string> &warnings) {
    MIOFILE mf;
    int retval;
    FILE* f;
    string s;

    COPROC_ATI my_ati_gpu;
    COPROC_NVIDIA my_nvidia_gpu;
    COPROC_INTEL my_intel_gpu;
    OPENCL_DEVICE_PROP ati_opencl;
    OPENCL_DEVICE_PROP nvidia_opencl;
    OPENCL_DEVICE_PROP intel_gpu_opencl;
    OPENCL_DEVICE_PROP other_opencl;
    OPENCL_CPU_PROP cpu_opencl;

    ati_gpus.clear();
    nvidia_gpus.clear();
    intel_gpus.clear();
    ati_opencls.clear();
    nvidia_opencls.clear();
    intel_gpu_opencls.clear();
    other_opencls.clear();
    cpu_opencls.clear();

    f = boinc_fopen(COPROC_INFO_FILENAME, "r");
    if (!f) return ERR_FOPEN;
    XML_PARSER xp(&mf);
    mf.init_file(f);
    if (!xp.parse_start("coprocs")) {
        fclose(f);
        return ERR_XML_PARSE;
    }
    
    while (!xp.get_tag()) {
        if (xp.match_tag("/coprocs")) {
            fclose(f);
            return 0;
        }

        if (xp.parse_bool("have_cuda", nvidia.have_cuda)) continue;
        if (xp.parse_int("cuda_version", nvidia.cuda_version)) {
             continue;
        }

        if (xp.match_tag("coproc_ati")) {
            retval = my_ati_gpu.parse(xp);
            if (retval) {
                my_ati_gpu.clear();
            } else {
                my_ati_gpu.device_num = (int)ati_gpus.size();
                ati_gpus.push_back(my_ati_gpu);
            }
            continue;
        }
        if (xp.match_tag("coproc_cuda")) {
            retval = my_nvidia_gpu.parse(xp);
            if (retval) {
                my_nvidia_gpu.clear();
            } else {
                my_nvidia_gpu.device_num = (int)nvidia_gpus.size();
                my_nvidia_gpu.pci_info = my_nvidia_gpu.pci_infos[0];
                memset(&my_nvidia_gpu.pci_infos[0], 0, sizeof(struct PCI_INFO));
                nvidia_gpus.push_back(my_nvidia_gpu);
            }
            continue;
        }
        if (xp.match_tag("coproc_intel_gpu")) {
            retval = my_intel_gpu.parse(xp);
            if (retval) {
                my_intel_gpu.clear();
            } else {
                my_intel_gpu.device_num = (int)intel_gpus.size();
                intel_gpus.push_back(my_intel_gpu);
            }
            continue;
        }
        
        if (xp.match_tag("ati_opencl")) {
            memset(&ati_opencl, 0, sizeof(ati_opencl));
            retval = ati_opencl.parse(xp, "/ati_opencl");
            if (retval) {
                memset(&ati_opencl, 0, sizeof(ati_opencl));
            } else {
                ati_opencl.is_used = COPROC_IGNORED;
                ati_opencls.push_back(ati_opencl);
            }
            continue;
        }

        if (xp.match_tag("nvidia_opencl")) {
            memset(&nvidia_opencl, 0, sizeof(nvidia_opencl));
            retval = nvidia_opencl.parse(xp, "/nvidia_opencl");
            if (retval) {
                memset(&nvidia_opencl, 0, sizeof(nvidia_opencl));
            } else {
                nvidia_opencl.is_used = COPROC_IGNORED;
                nvidia_opencls.push_back(nvidia_opencl);
            }
            continue;
        }

        if (xp.match_tag("intel_gpu_opencl")) {
            memset(&intel_gpu_opencl, 0, sizeof(intel_gpu_opencl));
            retval = intel_gpu_opencl.parse(xp, "/intel_gpu_opencl");
            if (retval) {
                memset(&intel_gpu_opencl, 0, sizeof(intel_gpu_opencl));
            } else {
                intel_gpu_opencl.is_used = COPROC_IGNORED;
                intel_gpu_opencls.push_back(intel_gpu_opencl);
            }
            continue;
        }

        if (xp.match_tag("other_opencl")) {
            memset(&other_opencl, 0, sizeof(other_opencl));
            retval = other_opencl.parse(xp, "/other_opencl");
            if (retval) {
                memset(&other_opencl, 0, sizeof(other_opencl));
            } else {
                other_opencl.is_used = COPROC_USED;
                other_opencls.push_back(other_opencl);
            }
            continue;
        }

        if (xp.match_tag("opencl_cpu_prop")) {
            memset(&cpu_opencl, 0, sizeof(cpu_opencl));
            retval = cpu_opencl.parse(xp);
            if (retval) {
                memset(&cpu_opencl, 0, sizeof(cpu_opencl));
            } else {
                cpu_opencl.opencl_prop.is_used = COPROC_IGNORED;
                cpu_opencls.push_back(cpu_opencl);
            }
            continue;
        }
        
        if (xp.parse_string("warning", s)) {
            warnings.push_back(s);
            continue;
        }

        // TODO: parse OpenCL info for CPU when implemented:
        //  gstate.host_info.have_cpu_opencl
        //  gstate.host_info.cpu_opencl_prop
    }
    
    fclose(f);
    return ERR_XML_PARSE;
}
Example #14
0
// traverse the profiles and determine which profile to use.
// this should be compatible with firefox2, firefox3, firefox4, seamonkey, and netscape.
//
bool get_firefox_profile_root( std::string& profile_root ) {
    bool retval = false;
    FILE* pf = NULL;
   	MIOFILE pmf;
    MOZILLA_PROFILES mps;
    MOZILLA_PROFILE* mp = NULL;
    std::string cookies_root;
    std::string tmp;
    unsigned int i = 0;
    unsigned int default_index = 0;

    get_home_dir_path( profile_root );
#ifdef _WIN32
    profile_root += std::string("Mozilla\\Firefox\\");
#elif defined(__APPLE__)
    profile_root += std::string("Library/Application Support/Firefox/");
#else
    profile_root += std::string(".mozilla/firefox/");
#endif

    // lets see if we can open the profiles configuration file
    tmp = profile_root + "profiles.ini";
    pf = fopen(tmp.c_str(), "r");

    // if profiles configuration file exists, parse it.
    if (pf) {
        pmf.init_file(pf);
        mps.parse(pmf);
    }

    // we need to know which cookie file to look at, so if only
    // one profile exists, use it.
    //
    // if more than one profile exists, look through all the
    // profiles until we find the default profile. even when the
    // user selects a different profile at startup the default
    // profile flag is changed at startup to the new profile.
    if (mps.profiles.size() == 0) {
        if (pf) fclose(pf);
        return retval;          // something is very wrong, don't
                                // risk a crash
    }

    if (mps.profiles.size() == 1) {
        default_index = 0;
    } else {
        for (i=0; i < mps.profiles.size(); i++) {
            if (mps.profiles[i]->is_default) {
                default_index = i;
                break;
            }
        }
    }

    // should the path be treated as an absolute path or a relative
    // path?
    mp = mps.profiles[default_index];
    if (mp->is_relative) {
        cookies_root = profile_root + mp->path + "/";
    } else {
        cookies_root = mp->path + "/";
    }

    profile_root = cookies_root;
    retval = true;

    // cleanup
    if (pf) fclose(pf);

    return retval;
}
Example #15
0
int ACCT_MGR_INFO::parse_login_file(FILE* p) {
    MIOFILE mf;
    int retval;

    mf.init_file(p);
    XML_PARSER xp(&mf);
    if (!xp.parse_start("acct_mgr_login")) {
        msg_printf(NULL, MSG_INTERNAL_ERROR,
            "missing start tag in account manager login file"
        );
    }
    while (!xp.get_tag()) {
        if (!xp.is_tag) {
            printf("unexpected text: %s\n", xp.parsed_tag);
            continue;
        }
        if (xp.match_tag("/acct_mgr_login")) break;
        if (xp.parse_str("login", login_name, 256)) continue;
        if (xp.parse_str("password_hash", password_hash, 256)) continue;
        if (xp.parse_str("authenticator", authenticator, 256)) continue;
        if (xp.parse_str("previous_host_cpid", previous_host_cpid, sizeof(previous_host_cpid))) continue;
        if (xp.parse_double("next_rpc_time", next_rpc_time)) continue;
        if (xp.match_tag("opaque")) {
            retval = xp.element_contents("</opaque>", opaque, sizeof(opaque));
            if (retval) {
                msg_printf(NULL, MSG_INFO,
                    "error parsing <opaque> in acct_mgr_login.xml"
                );
            }
            continue;
        }
        if (xp.parse_str("user_name", user_name, sizeof(user_name))) {
            xml_unescape(user_name);
            continue;
        }
        if (xp.parse_str("team_name", team_name, sizeof(team_name))) {
            xml_unescape(team_name);
            continue;
        }
        if (xp.parse_bool("no_project_notices", no_project_notices)) continue;
        if (xp.parse_bool("dynamic", dynamic)) continue;
        if (xp.match_tag("user_keywords")) {
            retval = user_keywords.parse(xp);
            if (retval) {
                msg_printf(NULL, MSG_INFO,
                    "error parsing user keywords in acct_mgr_login.xml"
                );
            }
            continue;
        }
        if (log_flags.unparsed_xml) {
            msg_printf(NULL, MSG_INFO,
                "[unparsed_xml] unrecognized %s in acct_mgr_login.xml",
                xp.parsed_tag
            );
        }
        xp.skip_unexpected(
            log_flags.unparsed_xml, "ACCT_MGR_INFO::parse_login_file"
        );
    }
    return 0;
}
Example #16
0
int write_init_data_file(FILE* f, APP_INIT_DATA& ai) {
    char buf[2048];
    fprintf(f,
        "<app_init_data>\n"
        "<major_version>%d</major_version>\n"
        "<minor_version>%d</minor_version>\n"
        "<release>%d</release>\n"
        "<app_version>%d</app_version>\n"
        "<userid>%d</userid>\n"
        "<teamid>%d</teamid>\n"
        "<hostid>%d</hostid>\n",
        ai.major_version,
        ai.minor_version,
        ai.release,
        ai.app_version,
        ai.userid,
        ai.teamid,
        ai.hostid
    );
    if (strlen(ai.app_name)) {
        fprintf(f, "<app_name>%s</app_name>\n", ai.app_name);
    }
    if (strlen(ai.symstore)) {
        fprintf(f, "<symstore>%s</symstore>\n", ai.symstore);
    }
    if (strlen(ai.acct_mgr_url)) {
        fprintf(f, "<acct_mgr_url>%s</acct_mgr_url>\n", ai.acct_mgr_url);
    }
    if (ai.project_preferences && strlen(ai.project_preferences)) {
        fprintf(f, "<project_preferences>\n%s</project_preferences>\n", ai.project_preferences);
    }
    if (strlen(ai.team_name)) {
        xml_escape(ai.team_name, buf, sizeof(buf));
        fprintf(f, "<team_name>%s</team_name>\n", buf);
    }
    if (strlen(ai.user_name)) {
        xml_escape(ai.user_name, buf, sizeof(buf));
        fprintf(f, "<user_name>%s</user_name>\n", buf);
    }
    if (strlen(ai.project_dir)) {
        fprintf(f, "<project_dir>%s</project_dir>\n", ai.project_dir);
    }
    if (strlen(ai.boinc_dir)) {
        fprintf(f, "<boinc_dir>%s</boinc_dir>\n", ai.boinc_dir);
    }
    if (strlen(ai.authenticator)) {
        fprintf(f, "<authenticator>%s</authenticator>\n", ai.authenticator);
    }
    if (strlen(ai.wu_name)) {
        fprintf(f, "<wu_name>%s</wu_name>\n", ai.wu_name);
    }
    if (strlen(ai.result_name)) {
        fprintf(f, "<result_name>%s</result_name>\n", ai.result_name);
    }
#ifdef _WIN32
    if (strlen(ai.shmem_seg_name)) {
        fprintf(f, "<comm_obj_name>%s</comm_obj_name>\n", ai.shmem_seg_name);
    }
#else
    fprintf(f, "<shm_key>%d</shm_key>\n", ai.shmem_seg_name);
#endif
    fprintf(f,
        "<slot>%d</slot>\n"
        "<client_pid>%d</client_pid>\n"
        "<wu_cpu_time>%f</wu_cpu_time>\n"
        "<starting_elapsed_time>%f</starting_elapsed_time>\n"
        "<using_sandbox>%d</using_sandbox>\n"
        "<vm_extensions_disabled>%d</vm_extensions_disabled>\n"
        "<user_total_credit>%f</user_total_credit>\n"
        "<user_expavg_credit>%f</user_expavg_credit>\n"
        "<host_total_credit>%f</host_total_credit>\n"
        "<host_expavg_credit>%f</host_expavg_credit>\n"
        "<resource_share_fraction>%f</resource_share_fraction>\n"
        "<checkpoint_period>%f</checkpoint_period>\n"
        "<fraction_done_start>%f</fraction_done_start>\n"
        "<fraction_done_end>%f</fraction_done_end>\n"
        "<gpu_type>%s</gpu_type>\n"
        "<gpu_device_num>%d</gpu_device_num>\n"
        "<gpu_opencl_dev_index>%d</gpu_opencl_dev_index>\n"
        "<gpu_usage>%f</gpu_usage>\n"
        "<ncpus>%f</ncpus>\n"
        "<rsc_fpops_est>%f</rsc_fpops_est>\n"
        "<rsc_fpops_bound>%f</rsc_fpops_bound>\n"
        "<rsc_memory_bound>%f</rsc_memory_bound>\n"
        "<rsc_disk_bound>%f</rsc_disk_bound>\n"
        "<computation_deadline>%f</computation_deadline>\n"
        "<vbox_window>%d</vbox_window>\n",
        ai.slot,
        ai.client_pid,
        ai.wu_cpu_time,
        ai.starting_elapsed_time,
        ai.using_sandbox?1:0,
        ai.vm_extensions_disabled?1:0,
        ai.user_total_credit,
        ai.user_expavg_credit,
        ai.host_total_credit,
        ai.host_expavg_credit,
        ai.resource_share_fraction,
        ai.checkpoint_period,
        ai.fraction_done_start,
        ai.fraction_done_end,
        ai.gpu_type,
        ai.gpu_device_num,
        ai.gpu_opencl_dev_index,
        ai.gpu_usage,
        ai.ncpus,
        ai.rsc_fpops_est,
        ai.rsc_fpops_bound,
        ai.rsc_memory_bound,
        ai.rsc_disk_bound,
        ai.computation_deadline,
        ai.vbox_window
    );
    MIOFILE mf;
    mf.init_file(f);
    ai.host_info.write(mf, true, true);
    ai.proxy_info.write(mf);
    ai.global_prefs.write(mf);
    for (unsigned int i=0; i<ai.app_files.size(); i++) {
        fprintf(f, "<app_file>%s</app_file>\n", ai.app_files[i].c_str());
    }
    fprintf(f, "</app_init_data>\n");
    return 0;
}
Example #17
0
// scan an account_*.xml file, looking for a <venue> element
// that matches this host's venue,
// and parsing that for resource share and prefs.
// Call this only after client_state.xml has been read
// (so that we know the host venue)
//
int PROJECT::parse_account_file_venue() {
    char attr_buf[256], venue[256], path[MAXPATHLEN], buf2[256];
    int retval;
    bool in_right_venue = false, btemp;
    double dtemp;

    get_account_filename(master_url, path);
    FILE* in = boinc_fopen(path, "r");
    if (!in) return ERR_FOPEN;

    //msg_printf(this, MSG_INFO, "parsing project prefs, looking for venue %s", host_venue);
    MIOFILE mf;
    XML_PARSER xp(&mf);
    mf.init_file(in);
    while (!xp.get_tag(attr_buf, sizeof(attr_buf))) {
        if (xp.match_tag("/account")) {
            fclose(in);
            return 0;
        } else if (xp.match_tag("venue")) {
            parse_attr(attr_buf, "name", venue, sizeof(venue));
            if (!strcmp(venue, host_venue)) {
                //msg_printf(this, MSG_INFO, "found venue %s", host_venue);
                using_venue_specific_prefs = true;
                in_right_venue = true;

                // reset these
                //
                for (int i=0; i<coprocs.n_rsc; i++) {
                    no_rsc_pref[i] = false;
                }
            } else {
                std::string devnull;
                retval = copy_element_contents(in, "</venue>", devnull);
                if (retval) return retval;
            }
            continue;
        }
        if (!in_right_venue) continue;
        if (xp.match_tag("/venue")) {
            in_right_venue = false;
            continue;
        } else if (xp.match_tag("project_specific")) {
            retval = copy_element_contents(
                xp.f->f,
                "</project_specific>",
                project_specific_prefs
            );
            if (retval) return retval;
            continue;
        } else if (xp.parse_double("resource_share", dtemp)) {
            // if account manager has specified resource share, don't override
            //
            if (ams_resource_share < 0) {
                resource_share = dtemp;
            }
            continue;
        }
        else if (xp.parse_bool("no_cpu", btemp)) {
            if (btemp) handle_no_rsc_pref(this, "CPU");
            continue;
        }

        // deprecated syntax
        else if (xp.parse_bool("no_cuda", btemp)) {
            if (btemp) handle_no_rsc_pref(this, GPU_TYPE_NVIDIA);
            continue;
        }
        else if (xp.parse_bool("no_ati", btemp)) {
            if (btemp) handle_no_rsc_pref(this, GPU_TYPE_ATI);
            continue;
        }
        else if (xp.parse_bool("no_intel_gpu", btemp)) {
            if (btemp) handle_no_rsc_pref(this, GPU_TYPE_INTEL);
            continue;
        }

        else if (xp.parse_str("no_rsc", buf2, sizeof(buf2))) {
            handle_no_rsc_pref(this, buf2);
            continue;
        }
        else {
            // skip project preferences the client doesn't know about
            //
            xp.skip_unexpected();
        }
    }
    fclose(in);
    return ERR_XML_PARSE;
}
Example #18
0
// Read global preferences into the global_prefs structure.
// 1) read the override file to get venue in case it's there
// 2) read global_prefs.xml
// 3) read the override file again
//
// This is called:
// - on startup
// - on completion of a scheduler or AMS RPC, if they sent prefs
// - in response to read_global_prefs_override GUI RPC
//
void CLIENT_STATE::read_global_prefs(
    const char* fname, const char* override_fname
) {
    bool found_venue;
    bool venue_specified_in_override = false;
    int retval;
    FILE* f;
    string foo;

    if (override_fname) {
        retval = read_file_string(override_fname, foo);
        if (!retval) {
            parse_str(foo.c_str(), "<host_venue>", main_host_venue, sizeof(main_host_venue));
            if (strlen(main_host_venue)) {
                venue_specified_in_override = true;
            }
        }
    }

    retval = global_prefs.parse_file(
        fname, main_host_venue, found_venue
    );
    if (retval) {
        if (retval == ERR_FOPEN) {
            msg_printf(NULL, MSG_INFO,
                "No general preferences found - using defaults"
            );
        } else {
            msg_printf(NULL, MSG_INFO,
                "Couldn't parse preferences file - using defaults"
            );
            boinc_delete_file(fname);
        }
        global_prefs.init();
    } else {
        if (!venue_specified_in_override) {
            // check that the source project's venue matches main_host_venue.
            // If not, read file again.
            // This is a fix for cases where main_host_venue is out of synch
            //
            PROJECT* p = global_prefs_source_project();
            if (p && strcmp(main_host_venue, p->host_venue)) {
                strcpy(main_host_venue, p->host_venue);
                global_prefs.parse_file(fname, main_host_venue, found_venue);
            }
        }
        show_global_prefs_source(found_venue);
    }

    // read the override file
    //
    global_prefs.override_file_present = false;
    if (override_fname) {
        f = fopen(override_fname, "r");
        if (f) {
            MIOFILE mf;
            GLOBAL_PREFS_MASK mask;
            mf.init_file(f);
            XML_PARSER xp(&mf);
            global_prefs.parse_override(xp, "", found_venue, mask);
            msg_printf(NULL, MSG_INFO, "Reading preferences override file");
            fclose(f);
            global_prefs.override_file_present = true;
        }
    }

    msg_printf(NULL, MSG_INFO, "Preferences:");
    msg_printf(NULL, MSG_INFO,
        "   max memory usage when active: %.2fMB",
        (host_info.m_nbytes*global_prefs.ram_max_used_busy_frac)/MEGA
    );
    msg_printf(NULL, MSG_INFO,
        "   max memory usage when idle: %.2fMB",
        (host_info.m_nbytes*global_prefs.ram_max_used_idle_frac)/MEGA
    );
#ifndef SIM
    get_disk_usages();
    msg_printf(NULL, MSG_INFO,
        "   max disk usage: %.2fGB",
        allowed_disk_usage(total_disk_usage)/GIGA
    );
#endif
    // max_cpus, bandwidth limits may have changed
    //
    set_ncpus();
    if (ncpus != host_info.p_ncpus) {
        msg_printf(NULL, MSG_INFO,
            "   max CPUs used: %d", ncpus
        );
    }
    if (!global_prefs.run_if_user_active) {
        msg_printf(NULL, MSG_INFO, "   don't compute while active");
    }
    if (!global_prefs.run_gpu_if_user_active) {
        msg_printf(NULL, MSG_INFO, "   don't use GPU while active");
    }
    if (global_prefs.suspend_cpu_usage) {
        msg_printf(NULL, MSG_INFO,
            "   suspend work if non-BOINC CPU load exceeds %.0f %%",
            global_prefs.suspend_cpu_usage
        );
    }
    if (global_prefs.max_bytes_sec_down) {
        msg_printf(NULL, MSG_INFO,
            "   max download rate: %.0f bytes/sec",
            global_prefs.max_bytes_sec_down
        );
    }
    if (global_prefs.max_bytes_sec_up) {
        msg_printf(NULL, MSG_INFO,
            "   max upload rate: %.0f bytes/sec",
            global_prefs.max_bytes_sec_up
        );
    }
#ifndef SIM
    file_xfers->set_bandwidth_limits(true);
    file_xfers->set_bandwidth_limits(false);
#endif
    msg_printf(NULL, MSG_INFO,
        "   (to change preferences, visit a project web site or select Preferences in the Manager)"
    );
    request_schedule_cpus("Prefs update");
    request_work_fetch("Prefs update");
#ifndef SIM
    active_tasks.request_reread_app_info();
#endif
}
int ACCT_MGR_OP::parse(FILE* f) {
    char tag[1024];
	bool is_tag;
    string message;
    int retval;
	MIOFILE mf;
	mf.init_file(f);
	XML_PARSER xp(&mf);

    accounts.clear();
    error_str = "";
    error_num = 0;
    repeat_sec = 0;
    strcpy(host_venue, "");
	strcpy(ami.opaque, "");
	if (!xp.parse_start("acct_mgr_reply")) return ERR_XML_PARSE;
    while (!xp.get(tag, sizeof(tag), is_tag)) {
		if (!is_tag) {
			if (log_flags.unparsed_xml) {
				msg_printf(0, MSG_INFO,
                    "[unparsed_xml] ACCT_MGR_OP::parse: unexpected text %s",
                    tag
                );
			}
			continue;
		}
        if (!strcmp(tag, "/acct_mgr_reply")) return 0;
        if (xp.parse_str(tag, "name", ami.acct_mgr_name, 256)) continue;
        if (xp.parse_int(tag, "error_num", error_num)) continue;
        if (xp.parse_string(tag, "error", error_str)) continue;
        if (xp.parse_double(tag, "repeat_sec", repeat_sec)) continue;
        if (xp.parse_string(tag, "message", message)) {
            msg_printf(NULL, MSG_INFO, "Account manager: %s", message.c_str());
            continue;
        }
		if (!strcmp(tag, "opaque")) {
			retval = xp.element_contents("</opaque>", ami.opaque, sizeof(ami.opaque));
			if (retval) return retval;
			continue;
		}
        if (!strcmp(tag, "signing_key")) {
            retval = xp.element_contents("</signing_key>", ami.signing_key, sizeof(ami.signing_key));
            if (retval) return retval;
            continue;
        }
        if (!strcmp(tag, "account")) {
            AM_ACCOUNT account;
            retval = account.parse(xp);
            if (retval) {
                msg_printf(NULL, MSG_INTERNAL_ERROR,
                    "Can't parse account in account manager reply: %s",
                    boincerror(retval)
                );
            } else {
                accounts.push_back(account);
            }
            continue;
        }
        if (!strcmp(tag, "global_preferences")) {
            retval = dup_element_contents(
                f,
                "</global_preferences>",
                &global_prefs_xml
            );
            if (retval) {
                msg_printf(NULL, MSG_INTERNAL_ERROR,
                    "Can't parse global prefs in account manager reply: %s",
                    boincerror(retval)
                );
                return retval;
            }
            continue;
        }
        if (xp.parse_str(tag, "host_venue", host_venue, sizeof(host_venue))) continue;
        if (log_flags.unparsed_xml) {
            msg_printf(NULL, MSG_INFO,
                "[unparsed_xml] ACCT_MGR_OP::parse: unrecognized %s", tag
            );
        }
        xp.skip_unexpected(tag, log_flags.unparsed_xml, "ACCT_MGR_OP::parse");
    }
    return ERR_XML_PARSE;
}