diff options
author | Stef Walter <stefw@redhat.com> | 2014-10-03 09:42:27 +0200 |
---|---|---|
committer | Stef Walter <stefw@redhat.com> | 2014-10-03 20:56:16 +0200 |
commit | 16e25b2890927108ec15297aabb1d86a49792741 (patch) | |
tree | 495215b96e664348fa6651696d517b22215d8467 /p11-kit/test-rpc.c | |
parent | a3b1e1c2f2c8c1f14293d8158b6dfeb2a6560908 (diff) | |
download | p11-kit-16e25b2890927108ec15297aabb1d86a49792741.tar.gz |
p11-kit: Use pthread_atfork() in a safe manner
Instead of trying to perform actions in pthread_atfork() which
are not async-signal-safe, just increment a counter so we can
later tell if the process has forked.
Note this does not make it safe to mix threads and forking without
immediately execing. This is a far broader problem that p11-kit,
however we now do the right thing when fork+exec is used from a
thread.
https://bugs.freedesktop.org/show_bug.cgi?id=84567
Diffstat (limited to 'p11-kit/test-rpc.c')
-rw-r--r-- | p11-kit/test-rpc.c | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/p11-kit/test-rpc.c b/p11-kit/test-rpc.c index 8c20a40..c9f8333 100644 --- a/p11-kit/test-rpc.c +++ b/p11-kit/test-rpc.c @@ -353,17 +353,15 @@ test_byte_array_static (void) } static p11_virtual base; -static pid_t rpc_initialized = 0; +static unsigned int rpc_initialized = 0; static CK_RV rpc_initialize (p11_rpc_client_vtable *vtable, void *init_reserved) { - pid_t pid = getpid (); - assert_str_eq (vtable->data, "vtable-data"); - assert_num_cmp (pid, !=, rpc_initialized); - rpc_initialized = pid; + assert_num_cmp (p11_forkid, !=, rpc_initialized); + rpc_initialized = p11_forkid; return CKR_OK; } @@ -372,10 +370,8 @@ static CK_RV rpc_initialize_fails (p11_rpc_client_vtable *vtable, void *init_reserved) { - pid_t pid = getpid (); - assert_str_eq (vtable->data, "vtable-data"); - assert_num_cmp (pid, !=, rpc_initialized); + assert_num_cmp (p11_forkid, !=, rpc_initialized); return CKR_FUNCTION_FAILED; } @@ -383,10 +379,8 @@ static CK_RV rpc_initialize_device_removed (p11_rpc_client_vtable *vtable, void *init_reserved) { - pid_t pid = getpid (); - assert_str_eq (vtable->data, "vtable-data"); - assert_num_cmp (pid, !=, rpc_initialized); + assert_num_cmp (p11_forkid, !=, rpc_initialized); return CKR_DEVICE_REMOVED; } @@ -410,10 +404,8 @@ static void rpc_finalize (p11_rpc_client_vtable *vtable, void *fini_reserved) { - pid_t pid = getpid (); - assert_str_eq (vtable->data, "vtable-data"); - assert_num_cmp (pid, ==, rpc_initialized); + assert_num_cmp (p11_forkid, ==, rpc_initialized); rpc_initialized = 0; } @@ -421,7 +413,6 @@ static void test_initialize (void) { p11_rpc_client_vtable vtable = { "vtable-data", rpc_initialize, rpc_transport, rpc_finalize }; - pid_t pid = getpid (); p11_virtual mixin; bool ret; CK_RV rv; @@ -435,11 +426,11 @@ test_initialize (void) rv = mixin.funcs.C_Initialize (&mixin.funcs, NULL); assert (rv == CKR_OK); - assert_num_eq (pid, rpc_initialized); + assert_num_eq (p11_forkid, rpc_initialized); rv = mixin.funcs.C_Finalize (&mixin.funcs, NULL); assert (rv == CKR_OK); - assert_num_cmp (pid, !=, rpc_initialized); + assert_num_cmp (p11_forkid, !=, rpc_initialized); p11_virtual_uninit (&mixin); } |