aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2017-04-12 16:58:50 -0400
committerRob Austein <sra@hactrn.net>2017-04-12 16:58:50 -0400
commit108b532b9ae4c9138ad1a25e9ef437183711a05b (patch)
treefa7a5d851b1be348090a98bd12fd58e5f187967b
parent4837c5d366e965e196828a2898e2471c592b85e1 (diff)
Handle race condition while fetching key metadata for display.
Fetching a list of keys and all of their metadata isn't an atomic process, nor, probably, should it be, so we need to cope with things like a key being deleted via the RPC interface while we're fetching its metadata for display on the console interface.
-rw-r--r--projects/hsm/mgmt-keystore.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/projects/hsm/mgmt-keystore.c b/projects/hsm/mgmt-keystore.c
index 230bded..f24f49b 100644
--- a/projects/hsm/mgmt-keystore.c
+++ b/projects/hsm/mgmt-keystore.c
@@ -208,21 +208,21 @@ static int show_keys(struct cli_def *cli, const char *title)
for (int i = 0; i < n; i++) {
if ((status = hal_uuid_format(&uuids[i], key_name, sizeof(key_name))) != LIBHAL_OK) {
- cli_print(cli, "Could not convert key name: %s",
+ cli_print(cli, "Could not convert key name, skipping: %s",
hal_error_string(status));
- return CLI_ERROR;
+ continue;
}
if ((status = hal_rpc_pkey_open(client, session, &pkey, &uuids[i])) != LIBHAL_OK) {
- cli_print(cli, "Could not open key %s: %s",
+ cli_print(cli, "Could not open key %s, skipping: %s",
key_name, hal_error_string(status));
- return CLI_ERROR;
+ continue;
}
if ((status = hal_rpc_pkey_get_key_type(pkey, &type)) != LIBHAL_OK ||
(status = hal_rpc_pkey_get_key_curve(pkey, &curve)) != LIBHAL_OK ||
(status = hal_rpc_pkey_get_key_flags(pkey, &flags)) != LIBHAL_OK)
- cli_print(cli, "Could not fetch metadata for key %s: %s",
+ cli_print(cli, "Could not fetch metadata for key %s, skipping: %s",
key_name, hal_error_string(status));
if (status == LIBHAL_OK)
@@ -231,7 +231,7 @@ static int show_keys(struct cli_def *cli, const char *title)
(void) hal_rpc_pkey_close(pkey);
if (status != LIBHAL_OK)
- return CLI_ERROR;
+ continue;
const char *type_name = "unknown";
switch (type) {