From 1ff94b0761a855546c3d8e813e6fc660da4ac5c3 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 31 Jul 2014 10:01:57 +0200 Subject: remote: added --timeout option --- p11-kit/p11-kit.c | 8 +++++++- p11-kit/remote.c | 10 +++++++--- p11-kit/remote.h | 3 ++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/p11-kit/p11-kit.c b/p11-kit/p11-kit.c index 0e5db29..692267d 100644 --- a/p11-kit/p11-kit.c +++ b/p11-kit/p11-kit.c @@ -142,6 +142,7 @@ p11_kit_remote (int argc, const struct passwd* pwd; const struct group* grp; unsigned foreground = 1; + unsigned timeout = 0; enum { opt_verbose = 'v', @@ -152,6 +153,7 @@ p11_kit_remote (int argc, opt_run_as_user = 'a', opt_run_as_group = 'z', opt_foreground = 'f', + opt_timeout = 't', }; struct option options[] = { @@ -163,6 +165,7 @@ p11_kit_remote (int argc, { "group", required_argument, NULL, opt_group }, { "run-as-user", required_argument, NULL, opt_run_as_user }, { "run-as-group", required_argument, NULL, opt_run_as_group }, + { "timeout", required_argument, NULL, opt_timeout }, { 0 }, }; @@ -181,6 +184,9 @@ p11_kit_remote (int argc, case opt_socket: socket_file = strdup(optarg); break; + case opt_timeout: + timeout = atoi(optarg); + break; case opt_group: grp = getgrnam(optarg); if (grp == NULL) { @@ -265,7 +271,7 @@ p11_kit_remote (int argc, if (module == NULL) return 1; - ret = p11_kit_remote_serve_module (module, socket_file, uid, gid, foreground); + ret = p11_kit_remote_serve_module (module, socket_file, uid, gid, foreground, timeout); p11_kit_module_release (module); return ret; diff --git a/p11-kit/remote.c b/p11-kit/remote.c index d8f50ef..da05746 100644 --- a/p11-kit/remote.c +++ b/p11-kit/remote.c @@ -210,7 +210,8 @@ p11_kit_remote_serve_module (CK_FUNCTION_LIST *module, const char *socket_file, uid_t uid, gid_t gid, - unsigned foreground) + unsigned foreground, + unsigned timeout) { p11_virtual virt; p11_buffer options; @@ -224,6 +225,7 @@ p11_kit_remote_serve_module (CK_FUNCTION_LIST *module, sigset_t emptyset, blockset; uid_t tuid; gid_t tgid; + struct timespec ts; sigemptyset(&blockset); sigemptyset(&emptyset); @@ -292,12 +294,14 @@ p11_kit_remote_serve_module (CK_FUNCTION_LIST *module, FD_ZERO(&rd_set); FD_SET(sd, &rd_set); - ret = pselect(sd + 1, &rd_set, NULL, NULL, NULL, &emptyset); + ts.tv_sec = timeout; + ts.tv_nsec = 0; + ret = pselect(sd + 1, &rd_set, NULL, NULL, &ts, &emptyset); if (ret == -1 && errno == EINTR) continue; if (ret == 0 && children_avail == 0) { /* timeout */ - p11_message ("no connections for 30 secs, exiting"); + p11_message ("no connections to %s for %u secs, exiting", socket_file, timeout); exit(0); } diff --git a/p11-kit/remote.h b/p11-kit/remote.h index f3b2d3d..ca4cf2d 100644 --- a/p11-kit/remote.h +++ b/p11-kit/remote.h @@ -46,7 +46,8 @@ extern "C" { int p11_kit_remote_serve_module (CK_FUNCTION_LIST *module, const char *socket, uid_t, gid_t, - unsigned foreground); + unsigned foreground, + unsigned timeout); #endif -- cgit v1.2.1