aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_ksk.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-07-09 20:41:23 +0000
committerChristian Grothoff <christian@grothoff.org>2009-07-09 20:41:23 +0000
commitd558104570635bb71b65074e0bfd3c56575cb2cb (patch)
tree23de6ae6b943783ec5199dd074f27500dcf1b3c3 /src/util/crypto_ksk.c
parent4dbc3a811a4468764f17c3db76a00ce30f23471a (diff)
downloadgnunet-d558104570635bb71b65074e0bfd3c56575cb2cb.tar.gz
gnunet-d558104570635bb71b65074e0bfd3c56575cb2cb.zip
fixing find forking
Diffstat (limited to 'src/util/crypto_ksk.c')
-rw-r--r--src/util/crypto_ksk.c65
1 files changed, 49 insertions, 16 deletions
diff --git a/src/util/crypto_ksk.c b/src/util/crypto_ksk.c
index 7dcdccd23..17591692f 100644
--- a/src/util/crypto_ksk.c
+++ b/src/util/crypto_ksk.c
@@ -763,7 +763,12 @@ GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc)
763} 763}
764 764
765 765
766#ifdef gcry_register_random_progress 766/**
767 * Process ID of the "find" process that we use for
768 * entropy gathering.
769 */
770static pid_t genproc;
771
767/** 772/**
768 * Function called by libgcrypt whenever we are 773 * Function called by libgcrypt whenever we are
769 * blocked gathering entropy. 774 * blocked gathering entropy.
@@ -775,28 +780,58 @@ entropy_generator (void *cls,
775 int current, 780 int current,
776 int total) 781 int total)
777{ 782{
778 static pid_t genproc; 783 unsigned long code;
784 enum GNUNET_OS_ProcessStatusType type;
785 int ret;
786
779 if (0 != strcmp (what, "need_entropy")) 787 if (0 != strcmp (what, "need_entropy"))
780 return; 788 return;
781 if (current == total) 789 if (current == total)
782 { 790 {
783 if (genproc != 0) 791 if (genproc != 0)
784 { 792 {
785 PLIBC_KILL(genproc, SIGKILL); 793 PLIBC_KILL(genproc, SIGTERM);
786 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); 794 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
787 genproc = 0; 795 genproc = 0;
788 } 796 }
789 return; 797 return;
790 } 798 }
791 genproc = GNUNET_OS_start_process ("find", 799 if (genproc != 0)
792 "find", 800 {
793 "-type", 801 ret = GNUNET_OS_process_status (genproc,
794 "s", 802 &type,
795 "-fprint", 803 &code);
796 "/dev/null", 804 if (ret == GNUNET_NO)
805 return; /* still running */
806 if (ret == GNUNET_SYSERR)
807 {
808 GNUNET_break (0);
809 return;
810 }
811 PLIBC_KILL(genproc, SIGTERM);
812 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
813 genproc = 0;
814 }
815 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
816 _("Starting `%s' process to generate entropy\n"),
817 "find");
818 genproc = GNUNET_OS_start_process ("sh",
819 "sh",
820 "-c",
821 "exec find / -type f -exec cp {} /dev/null \\; 2>/dev/null",
797 NULL); 822 NULL);
798} 823}
799#endif 824
825
826static void
827killfind ()
828{
829 if (genproc != 0)
830 {
831 PLIBC_KILL(genproc, SIGKILL);
832 genproc = 0;
833 }
834}
800 835
801 836
802void __attribute__ ((constructor)) GNUNET_CRYPTO_ksk_init () 837void __attribute__ ((constructor)) GNUNET_CRYPTO_ksk_init ()
@@ -813,11 +848,11 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_ksk_init ()
813#ifdef gcry_fast_random_poll 848#ifdef gcry_fast_random_poll
814 gcry_fast_random_poll (); 849 gcry_fast_random_poll ();
815#endif 850#endif
816#ifdef gcry_register_random_progress 851 gcry_set_progress_handler (&entropy_generator, NULL);
817 gcry_register_random_progress (&entropy_generator, NULL); 852 atexit (&killfind);
818#endif
819} 853}
820 854
855
821void __attribute__ ((destructor)) GNUNET_CRYPTO_ksk_fini () 856void __attribute__ ((destructor)) GNUNET_CRYPTO_ksk_fini ()
822{ 857{
823 int i; 858 int i;
@@ -828,9 +863,7 @@ void __attribute__ ((destructor)) GNUNET_CRYPTO_ksk_fini ()
828 GNUNET_free (cache[i]); 863 GNUNET_free (cache[i]);
829 } 864 }
830 GNUNET_array_grow (cache, cacheSize, 0); 865 GNUNET_array_grow (cache, cacheSize, 0);
831#ifdef gcry_register_random_progress 866 gcry_set_progress_handler (NULL, NULL);
832 gcry_register_random_progress (NULL, NULL);
833#endif
834} 867}
835 868
836/* end of kblockkey.c */ 869/* end of kblockkey.c */