You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Michael Felt <ma...@gmail.com> on 2012/03/31 13:36:25 UTC

apr_generate_random_bytes() is not generated for AIX4 (with no /dev/random) - httpd 2.X.X cannot build without it

A very quick hack - for something that has been around for a long time, but
I have "fixed" in the past by "hacking" my local copy of httpd (last time
was for 2.2.16, htpasswd.c).

Will working on a test of the proposed httpd-2.4.2 I came across this again
when I tried to build for AIX 4.3.3 - which lacks a /dev/random device.

Result of configure is APR_HAS_RANDOM = 0, so the routine
apr_generate_random_bytes() is not built and so httpd 2.X which use this
routine - cannot be built.

There is nothing officially "random" in my hack, but it gets the routine
built. I expect there is a much better way to do this (and hopefully be
backported into 1.4.x) - than putting it into an #else block.

Anyway, here is a starting point.

Index: apr-1.5.x/misc/unix/rand.c
===================================================================
--- apr-1.5.x/misc/unix/rand.c  (revision 1307078)
+++ apr-1.5.x/misc/unix/rand.c  (working copy)
@@ -247,4 +247,28 @@
 #include "randbyte_os2.inc"
 #endif

+#else
+/*
+ * APR_HAS_RANDOM == 0
+ *      quick hack for AIX4 which lacks /dev/random
+ *      apr is not creating a substitute routine
+ */
+#ifdef _AIX
+
+APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char *buf,
+                                                    apr_size_t length)
+{
+#include <time.h>
+        struct timespec tp;
+       int seed = 0;
+#ifdef CLOCK_MONOTONIC
+        clock_gettime(CLOCK_MONOTONIC,&tp);
+#else
+        clock_gettime(CLOCK_REALTIME,&tp);
+#endif
+        seed = tp.tv_nsec % 10000;
+        memcpy(buf, &seed, length);
+    return APR_SUCCESS;
+}
+#endif
 #endif /* APR_HAS_RANDOM */