summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjirka-h <hladky.jiri@gmail.com>2020-05-11 16:01:13 +0200
committerGitHub <noreply@github.com>2020-05-11 16:01:13 +0200
commit663f375f558a80c97a2e3737e741311a9bfd3e5f (patch)
tree48c1a9d8f8ecc9af902e16a0918d94771ee864d9
parentMerge pull request #32 from suominen/posix (diff)
parenthaveged: fix crash on shutdown in threaded mode (diff)
downloadhaveged-663f375f558a80c97a2e3737e741311a9bfd3e5f.tar.xz
haveged-663f375f558a80c97a2e3737e741311a9bfd3e5f.zip
Merge pull request #30 from trofi/master
haveged: fix crash on shutdown in threaded mode
-rw-r--r--src/havege.c13
-rw-r--r--src/havege.h8
-rw-r--r--src/haveged.c4
3 files changed, 24 insertions, 1 deletions
diff --git a/src/havege.c b/src/havege.c
index 3aeaf20..6710458 100644
--- a/src/havege.c
+++ b/src/havege.c
@@ -178,6 +178,19 @@ H_PTR havege_create( /* RETURN: app state */
havege_ndsetup(h);
return h;
}
+
+void havege_reparent(
+ H_PTR hptr)
+{
+#if NUMBER_CORES>1
+ H_THREAD *t = (H_THREAD *)hptr->threads;
+ if (0 == t)
+ return; /* single-threaded */
+
+ t->main = getpid();
+#endif
+}
+
/**
* Destructor. In a multi-collector build, this method should be called from a signal handler
* to avoid creating processes.
diff --git a/src/havege.h b/src/havege.h
index 2e1ade6..35bda94 100644
--- a/src/havege.h
+++ b/src/havege.h
@@ -238,6 +238,14 @@ typedef enum {
* H_NOINIT
*/
H_PTR havege_create(H_PARAMS *params);
+
+/**
+ * haveger_create() remembers parent pid and uses it to identify deallocating thread.
+ * daemonize() forks parent and effectively loses parent thread.
+ * havege_reparent(void) allows recovering new parent pid before havege_run() is started.
+ */
+void havege_reparent(H_PTR hptr);
+
/**
* Frees all allocated anchor resources. If the multi-core option is used, this
* method should be called from a signal handler to prevent zombie processes.
diff --git a/src/haveged.c b/src/haveged.c
index e061079..4d05fdb 100644
--- a/src/haveged.c
+++ b/src/haveged.c
@@ -538,8 +538,10 @@ static void run_daemon( /* RETURN: nothing */
anchor_info(h);
return;
}
- if (params->foreground==0)
+ if (params->foreground==0) {
daemonize();
+ havege_reparent(handle);
+ }
else printf ("%s starting up\n", params->daemon);
if (0 != havege_run(h))
error_exit("Couldn't initialize HAVEGE rng %d", h->error);