Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 1 | From 5834216fb3aa4e5e59ee13e871c70db1b4e13f02 Mon Sep 17 00:00:00 2001 |
| 2 | From: Patrick Ohly <patrick.ohly@intel.com> |
| 3 | Date: Fri, 30 Sep 2016 10:22:16 +0200 |
| 4 | Subject: [PATCH] command line: apply operation to all paths |
| 5 | |
| 6 | Previously, invocations like "evmctl ima_hash foo bar" silently |
| 7 | ignored all parameters after the first path name ("foo" in this |
| 8 | example). |
| 9 | |
| 10 | Now evmctl iterates over all specified paths. It aborts with an |
| 11 | error as soon as the selected operation fails for a path. |
| 12 | |
| 13 | Supporting more than one parameter is useful in combination with |
| 14 | "find" and "xargs" because it is noticably faster than invoking |
| 15 | evmutil separately for each file, in particular when run under pseudo |
| 16 | (a fakeroot environment used by the OpenEmbedded build system). |
| 17 | |
| 18 | This complements the recursive mode and can be used when more control |
| 19 | over file selection is needed. |
| 20 | |
| 21 | Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> |
| 22 | --- |
| 23 | src/evmctl.c | 21 ++++++++++++--------- |
| 24 | 1 file changed, 12 insertions(+), 9 deletions(-) |
| 25 | |
| 26 | diff --git a/src/evmctl.c b/src/evmctl.c |
| 27 | index 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 | -- |
| 67 | 2.1.4 |
| 68 | |