From 441990d176ff6df7032ef812efb2ac35f4d76388 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Fri, 13 May 2016 17:00:44 -0400 Subject: The libhal RPC channel works better when one remembers to initialize it. --- p11util.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'p11util.c') diff --git a/p11util.c b/p11util.c index 606e40c..db36888 100644 --- a/p11util.c +++ b/p11util.c @@ -265,23 +265,24 @@ static int set_pin(const hal_user_t user, const int read_from_stdin) int main(int argc, char *argv[]) { int do_set_so_pin = 0, do_set_user_pin = 0, do_set_wheel_pin = 0, read_from_stdin = 0; + hal_error_t err; parse_args(argc, argv, &do_set_so_pin, &do_set_user_pin, &do_set_wheel_pin, &read_from_stdin); - if (do_set_wheel_pin && !set_pin(HAL_USER_WHEEL, read_from_stdin)) { - fprintf(stderr, "Couldn't set wheel PIN\n"); - return 1; - } + if ((err = hal_rpc_client_init()) != HAL_OK) + return fprintf(stderr, "Couldn't initialize RPC: %s\n", hal_error_string(err)), 1; - if (do_set_so_pin && !set_pin(HAL_USER_SO, read_from_stdin)) { - fprintf(stderr, "Couldn't set SO PIN\n"); - return 2; - } + if (do_set_wheel_pin && !set_pin(HAL_USER_WHEEL, read_from_stdin)) + return fprintf(stderr, "Couldn't set wheel PIN\n"), 2; - if (do_set_user_pin && !set_pin(HAL_USER_NORMAL, read_from_stdin)) { - fprintf(stderr, "Couldn't set user PIN\n"); - return 3; - } + if (do_set_so_pin && !set_pin(HAL_USER_SO, read_from_stdin)) + return fprintf(stderr, "Couldn't set SO PIN\n"), 3; + + if (do_set_user_pin && !set_pin(HAL_USER_NORMAL, read_from_stdin)) + return fprintf(stderr, "Couldn't set user PIN\n"), 4; + + if ((err = hal_rpc_client_close()) != HAL_OK) + return fprintf(stderr, "Couldn't shut down RPC: %s\n", hal_error_string(err)), 5; return 0; } -- cgit v1.2.3