diff options
Diffstat (limited to 'p11util.c')
-rw-r--r-- | p11util.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -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; } |