blob: 35c316270189b8ffbdee0da1ff8ecf4c2456a12c [file] [log] [blame]
Brad Bishop15ae2502019-06-18 21:44:24 -04001From 5834216fb3aa4e5e59ee13e871c70db1b4e13f02 Mon Sep 17 00:00:00 2001
2From: Patrick Ohly <patrick.ohly@intel.com>
3Date: Fri, 30 Sep 2016 10:22:16 +0200
4Subject: [PATCH] command line: apply operation to all paths
5
6Previously, invocations like "evmctl ima_hash foo bar" silently
7ignored all parameters after the first path name ("foo" in this
8example).
9
10Now evmctl iterates over all specified paths. It aborts with an
11error as soon as the selected operation fails for a path.
12
13Supporting more than one parameter is useful in combination with
14"find" and "xargs" because it is noticably faster than invoking
15evmutil separately for each file, in particular when run under pseudo
16(a fakeroot environment used by the OpenEmbedded build system).
17
18This complements the recursive mode and can be used when more control
19over file selection is needed.
20
21Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
22---
23 src/evmctl.c | 21 ++++++++++++---------
24 1 file changed, 12 insertions(+), 9 deletions(-)
25
26diff --git a/src/evmctl.c b/src/evmctl.c
27index 23cf54c..2072034 100644
28--- a/src/evmctl.c
29+++ b/src/evmctl.c
30@@ -626,7 +626,7 @@ static int get_file_type(const char *path, const char *search_type)
31 static int do_cmd(struct command *cmd, find_cb_t func)
32 {
33 char *path = g_argv[optind++];
34- int err, dts = REG_MASK; /* only regular files by default */
35+ int err = 0, dts = REG_MASK; /* only regular files by default */
36
37 if (!path) {
38 log_err("Parameters missing\n");
39@@ -634,15 +634,18 @@ static int do_cmd(struct command *cmd, find_cb_t func)
40 return -1;
41 }
42
43- if (recursive) {
44- if (search_type) {
45- dts = get_file_type(path, search_type);
46- if (dts < 0)
47- return dts;
48+ while (path && !err) {
49+ if (recursive) {
50+ if (search_type) {
51+ dts = get_file_type(path, search_type);
52+ if (dts < 0)
53+ return dts;
54+ }
55+ err = find(path, dts, func);
56+ } else {
57+ err = func(path);
58 }
59- err = find(path, dts, func);
60- } else {
61- err = func(path);
62+ path = g_argv[optind++];
63 }
64
65 return err;
66--
672.1.4
68