From 733b1f7952894fc007c695206bdc47d5efb4c805 Mon Sep 17 00:00:00 2001 From: davidpanderson Date: Sat, 2 Nov 2024 12:32:16 -0700 Subject: [PATCH] debug docker_wrapper on Linux Make 'verbose' an attribute of DOCKER_CONN. --- lib/util.cpp | 18 ++++++++++++------ lib/util.h | 10 +++++----- samples/docker_wrapper/docker_wrapper.cpp | 4 ++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/util.cpp b/lib/util.cpp index fcfc3953b2..c1d230e946 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -701,7 +701,7 @@ string parse_ldd_libc(const char* input) { } #ifdef _WIN32 -int DOCKER_CONN::init(DOCKER_TYPE docker_type, string distro_name) { +int DOCKER_CONN::init(DOCKER_TYPE docker_type, string distro_name, bool _verbose) { cli_prog = docker_cli_prog(docker_type); if (docker_type == DOCKER) { int retval = ctl_wc.setup(); @@ -714,16 +714,18 @@ int DOCKER_CONN::init(DOCKER_TYPE docker_type, string distro_name) { } else { return -1; } + verbose = _verbose; return 0; } #else -int DOCKER_CONN::init(DOCKER_TYPE docker_type) { +int DOCKER_CONN::init(DOCKER_TYPE docker_type, bool _verbose) { cli_prog = docker_cli_prog(docker_type); + verbose = _verbose; return 0; } #endif -int DOCKER_CONN::command(const char* cmd, vector out, bool verbose) { +int DOCKER_CONN::command(const char* cmd, vector &out) { char buf[1024]; int retval; if (verbose) { @@ -745,10 +747,15 @@ int DOCKER_CONN::command(const char* cmd, vector out, bool verbose) { #else sprintf(buf, "%s %s\n", cli_prog, cmd); retval = run_command(buf, out); - if (retval) return retval; + if (retval) { + if (verbose) { + fprintf(stderr, "command failed: %s\n", boincerror(retval)); + } + return retval; + } #endif if (verbose) { - fprintf(stderr, "output:\n"); + fprintf(stderr, "command output:\n"); for (string line: out) { fprintf(stderr, "%s\n", line.c_str()); } @@ -756,7 +763,6 @@ int DOCKER_CONN::command(const char* cmd, vector out, bool verbose) { return 0; } - // REPOSITORY TAG IMAGE ID CREATED SIZE // localhost/boinc__app_test__test_wu latest cbc1498dfc49 43 hours ago 121 MB diff --git a/lib/util.h b/lib/util.h index c789364b5e..bbd56fa58e 100644 --- a/lib/util.h +++ b/lib/util.h @@ -151,15 +151,15 @@ extern double simtime; struct DOCKER_CONN { DOCKER_TYPE type; const char* cli_prog; + bool verbose; #ifdef _WIN32 WSL_CMD ctl_wc; - int init(DOCKER_TYPE type, std::string distro_name); + int init(DOCKER_TYPE type, std::string distro_name, bool verbose); #else - int init(DOCKER_TYPE); + int init(DOCKER_TYPE, bool verbose); #endif - int command( - const char* cmd, std::vector out, bool verbose=false - ); + int command(const char* cmd, std::vector &out); + static const int TIMEOUT = 10; // timeout for docker commands // parse a line from "docker images" output; return name diff --git a/samples/docker_wrapper/docker_wrapper.cpp b/samples/docker_wrapper/docker_wrapper.cpp index 4c5fb5edfe..df7a4a0d1a 100644 --- a/samples/docker_wrapper/docker_wrapper.cpp +++ b/samples/docker_wrapper/docker_wrapper.cpp @@ -483,7 +483,7 @@ int wsl_init() { distro_name = distro->distro_name; docker_type = distro->docker_type; } - return docker_conn.init (docker_type, distro_name); + return docker_conn.init(docker_type, distro_name, verbose); } #endif @@ -555,7 +555,7 @@ int main(int argc, char** argv) { } #else docker_conn.init( - boinc_is_standalone()?DOCKER:aid.host_info.docker_type + boinc_is_standalone()?DOCKER:aid.host_info.docker_type, verbose ); #endif