From cc284ffd815095765332ff35e8ae1e5f8320c583 Mon Sep 17 00:00:00 2001 From: Eric Heien Date: Fri, 27 Jun 2003 23:13:15 +0000 Subject: [PATCH] app stderr fix svn path=/trunk/boinc/; revision=1609 --- client/app.C | 9 +++++++-- client/client_state.C | 19 ++++++------------- client/client_types.C | 17 ++++++----------- client/client_types.h | 2 +- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/client/app.C b/client/app.C index fb7f7beaba..5e855ce95b 100644 --- a/client/app.C +++ b/client/app.C @@ -684,15 +684,20 @@ int ACTIVE_TASK::abort() { // check for the stderr file, copy to result record // bool ACTIVE_TASK::read_stderr_file() { + char stderr_file[MAX_BLOB_LEN]; char path[256]; int n; sprintf(path, "%s%s%s", slot_dir, PATH_SEPARATOR, STDERR_FILE); FILE* f = fopen(path, "r"); if (f) { - n = fread(result->stderr_out, 1, sizeof(result->stderr_out), f); - result->stderr_out[n] = 0; + n = fread(stderr_file, 1, sizeof(stderr_file), f); fclose(f); + stderr_file[n-1] = '\0'; + result->stderr_out += "\n"; + result->stderr_out += stderr_file; + result->stderr_out += "\n\n"; + result->stderr_out = result->stderr_out.substr(0,MAX_BLOB_LEN-1); return true; } return false; diff --git a/client/client_state.C b/client/client_state.C index 8e1fc3ae25..e9b630cfb9 100644 --- a/client/client_state.C +++ b/client/client_state.C @@ -1550,16 +1550,11 @@ int CLIENT_STATE::report_result_error( res.exit_status, res.signal ); - - if (strlen(res.stderr_out) + strlen(buf) < MAX_BLOB_LEN) { - strcat(res.stderr_out, buf ); - } + res.stderr_out.append(buf); if ((res.state == RESULT_FILES_DOWNLOADED) && err_num) { sprintf(buf,"%d\n", err_num); - if (strlen(res.stderr_out) + strlen(buf) < MAX_BLOB_LEN) { - strcat(res.stderr_out, buf ); - } + res.stderr_out.append(buf); } if (res.state == RESULT_NEW) { @@ -1572,9 +1567,7 @@ int CLIENT_STATE::report_result_error( "\n", res.wup->input_files[i].file_info->name, failnum ); - if (strlen(res.stderr_out) + strlen(buf) < MAX_BLOB_LEN ) { - strcat( res.stderr_out, buf ); - } + res.stderr_out.append(buf); } } } @@ -1589,12 +1582,12 @@ int CLIENT_STATE::report_result_error( "\n", res.output_files[i].file_info->name, failnum ); - if (strlen(res.stderr_out) + strlen(buf) < MAX_BLOB_LEN ) { - strcat( res.stderr_out, buf ); - } + res.stderr_out.append(buf); } } } + + res.stderr_out = res.stderr_out.substr(0,MAX_BLOB_LEN-1); return 0; } diff --git a/client/client_types.C b/client/client_types.C index 23bd9726b8..721e90b106 100644 --- a/client/client_types.C +++ b/client/client_types.C @@ -737,7 +737,7 @@ void RESULT::clear() { exit_status = 0; active_task_state = 0; signal = 0; - strcpy(stderr_out, ""); + stderr_out = ""; app = NULL; wup = NULL; project = NULL; @@ -790,7 +790,7 @@ int RESULT::parse_state(FILE* in) { else if (match_tag(buf, "")) { while (fgets(buf, 256, in)) { if (match_tag(buf, "")) break; - strcat(stderr_out, buf); + stderr_out.append(buf); } continue; } @@ -813,17 +813,12 @@ int RESULT::write(FILE* out, bool to_server) { final_cpu_time, state ); - n = strlen(stderr_out); + n = stderr_out.length(); if (n) { - fprintf(out, - "\n" - "%s", - stderr_out - ); + fprintf(out, "\n"); + fprintf(out, stderr_out.c_str()); if (stderr_out[n-1] != '\n') fprintf(out, "\n"); - fprintf(out, - "\n" - ); + fprintf(out, "\n"); } if (!to_server) { if (server_ack) fprintf(out, " \n"); diff --git a/client/client_types.h b/client/client_types.h index 4dae970528..c1f28142cf 100644 --- a/client/client_types.h +++ b/client/client_types.h @@ -221,7 +221,7 @@ struct RESULT { int signal; // the signal caught by the active_task, // defined only if active_task_state is PROCESS_SIGNALED int active_task_state; // the state of the active task corresponding to this result - char stderr_out[MAX_BLOB_LEN]; + string stderr_out; APP* app; WORKUNIT* wup;