summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Czapiga <jacz@semihalf.com>2022-09-07 13:51:30 +0200
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-10 05:47:07 +0000
commit62cc7885eab5d5ab0a7d773fb5284b4ca9ee097c (patch)
tree19c6336af2e10bf164194f989ba9cf4040c0f31a
parent3bd35108579db497b006b81e77794739b5118592 (diff)
downloadvboot-stabilize-15117.48.B.tar.gz
Utility programs in vboot sometimes use subprocess_run to execute another program like flashrom or cbfstool. This change makes it easier to debug these utilities by logging executed subprocess and its arguments. This change also fixes futility vb2ex_printf() implementation. Previously use of VB2_DEBUG_RAW() calling vb2ex_printf(NULL, ...) was unnecessarily trying to print NULL as function name, which was not intended behavior. TEST=sign image and look for "Run: cbfstool ..." BUG=none BRANCH=none Signed-off-by: Jakub Czapiga <czapiga@google.com> Change-Id: I613d4af4af4370425cbbedc2d7de29a488533c6a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3878593 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
-rw-r--r--futility/misc.c3
-rw-r--r--host/lib/cbfstool.c2
-rw-r--r--host/lib/subprocess.c25
3 files changed, 27 insertions, 3 deletions
diff --git a/futility/misc.c b/futility/misc.c
index 874039f0..7d261c2c 100644
--- a/futility/misc.c
+++ b/futility/misc.c
@@ -39,7 +39,8 @@ void vb2ex_printf(const char *func, const char *format, ...)
va_list ap;
va_start(ap, format);
- fprintf(stderr, "DEBUG: %s: ", func);
+ if (func)
+ fprintf(stderr, "DEBUG: %s: ", func);
vfprintf(stderr, format, ap);
va_end(ap);
}
diff --git a/host/lib/cbfstool.c b/host/lib/cbfstool.c
index 8f547066..9f09d136 100644
--- a/host/lib/cbfstool.c
+++ b/host/lib/cbfstool.c
@@ -43,8 +43,6 @@ vb2_error_t cbfstool_truncate(const char *file, const char *region,
cbfstool, file, "truncate", "-r", region, NULL,
};
- VB2_DEBUG("Calling: %s '%s' truncate -r '%s'\n", cbfstool, file,
- region);
status = subprocess_run(argv, &subprocess_null, &output,
&subprocess_null);
diff --git a/host/lib/subprocess.c b/host/lib/subprocess.c
index 242b1897..8905d1c2 100644
--- a/host/lib/subprocess.c
+++ b/host/lib/subprocess.c
@@ -5,6 +5,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
@@ -248,6 +249,28 @@ static int process_target_output(struct subprocess_target *target)
return rv;
}
+static bool contains_spaces(const char *s)
+{
+ for (size_t i = 0; s[i]; i++) {
+ if (isspace(s[i]))
+ return true;
+ }
+ return false;
+}
+
+static void subprocess_log_call(const char *const argv[])
+{
+ VB2_DEBUG("Run:");
+
+ for (size_t i = 0; argv[i]; i++) {
+ if (contains_spaces(argv[i]))
+ VB2_DEBUG_RAW(" '%s'", argv[i]);
+ else
+ VB2_DEBUG_RAW(" %s", argv[i]);
+ }
+ VB2_DEBUG_RAW("\n");
+}
+
struct subprocess_target subprocess_null = {
.type = TARGET_NULL,
};
@@ -275,6 +298,8 @@ int subprocess_run(const char *const argv[],
int status;
pid_t pid = -1;
+ subprocess_log_call(argv);
+
if (!input)
input = &subprocess_stdin;
if (!output)