You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by gs...@apache.org on 2012/03/31 23:01:05 UTC
svn commit: r1307903 - in /subversion/trunk/subversion: libsvn_subr/crypto.c
libsvn_subr/crypto.h svn/main.c
Author: gstein
Date: Sat Mar 31 21:01:05 2012
New Revision: 1307903
URL: http://svn.apache.org/viewvc?rev=1307903&view=rev
Log:
Switch to automatic initialization via atomics, as suggested by Bert.
This revert's r1307538, r1307559, r1307564, and r1307747 to main.c.
Some includes were added to crypt.[ch] to enable building.
* subverison/libsvn_subr/crypto.h:
(...): include svn_types.h and svn_string.h
* subversion/libsvn_subr/crypto.c:
(...): include svn_types and svn_private_conig to fix the build.
include the atomics.
(crypto_init_state): our atomic to determine if we have initialized
APR's crypto subsystem.
(CRYPTO_INIT): handy macro to init the subsystem
(crypto_init): svn_atomic handler to init APR
(svn_crypt__context_create): call CRYPTO_INIT()
* subverison/svn/main.c:
(...): remove various includes
(crypto_init): removed
(main): remove call to crypto_init()
Modified:
subversion/trunk/subversion/libsvn_subr/crypto.c
subversion/trunk/subversion/libsvn_subr/crypto.h
subversion/trunk/subversion/svn/main.c
Modified: subversion/trunk/subversion/libsvn_subr/crypto.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/crypto.c?rev=1307903&r1=1307902&r2=1307903&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/crypto.c (original)
+++ subversion/trunk/subversion/libsvn_subr/crypto.c Sat Mar 31 21:01:05 2012
@@ -25,6 +25,40 @@
#if APU_HAVE_CRYPTO
#include <apr_random.h>
+#include "svn_types.h"
+
+#include "svn_private_config.h"
+#include "private/svn_atomic.h"
+
+
+static volatile svn_atomic_t crypto_init_state = 0;
+
+#define CRYPTO_INIT(scratch_pool) \
+ SVN_ERR(svn_atomic__init_once(&crypto_init_state, \
+ crypto_init, NULL, (scratch_pool)))
+
+/* Initialize the APR cryptography subsystem (if available), using
+ ANY_POOL's ancestor root pool for the registration of cleanups,
+ shutdowns, etc. */
+/* Don't call this function directly! Use svn_atomic__init_once(). */
+static svn_error_t *
+crypto_init(void *baton, apr_pool_t *any_pool)
+{
+#if APU_HAVE_CRYPTO
+ /* NOTE: this function will locate the topmost ancestor of ANY_POOL
+ for its cleanup handlers. We don't have to worry about ANY_POOL
+ being cleared. */
+ apr_status_t apr_err = apr_crypto_init(any_pool);
+
+ if (apr_err)
+ return svn_error_wrap_apr(
+ apr_err,
+ _("Failed to initialize cryptography subsystem"));
+#endif /* APU_HAVE_CRYPTO */
+
+ return SVN_NO_ERROR;
+}
+
/* If APU_ERR is non-NULL, create and return a Subversion error using
APR_ERR and APU_ERR. */
@@ -66,6 +100,8 @@ svn_crypto__context_create(apr_crypto_t
const apu_err_t *apu_err = NULL;
const apr_crypto_driver_t *driver;
+ CRYPTO_INIT(pool);
+
/* ### TODO: So much for abstraction. APR's wrappings around NSS
and OpenSSL aren't quite as opaque as I'd hoped, requiring us
to specify a driver type and then params to the driver. We
Modified: subversion/trunk/subversion/libsvn_subr/crypto.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/crypto.h?rev=1307903&r1=1307902&r2=1307903&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/crypto.h (original)
+++ subversion/trunk/subversion/libsvn_subr/crypto.h Sat Mar 31 21:01:05 2012
@@ -30,6 +30,9 @@
#include <apr_crypto.h>
+#include "svn_types.h"
+#include "svn_string.h"
+
/* Set *CRYPTO_CTX to an APR-managed OpenSSL cryptography context
object allocated from POOL. */
/* ### TODO: Should this be something done once at apr_crypto_init()
Modified: subversion/trunk/subversion/svn/main.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/main.c?rev=1307903&r1=1307902&r2=1307903&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/main.c (original)
+++ subversion/trunk/subversion/svn/main.c Sat Mar 31 21:01:05 2012
@@ -34,11 +34,6 @@
#include <apr_tables.h>
#include <apr_general.h>
#include <apr_signal.h>
-#include <apu.h> /* for APU_HAVE_CRYPTO */
-
-#if APU_HAVE_CRYPTO
-#include <apr_crypto.h>
-#endif
#include "svn_cmdline.h"
#include "svn_pools.h"
@@ -1540,29 +1535,6 @@ svn_cl__check_cancel(void *baton)
return SVN_NO_ERROR;
}
-/* Initialize the APR cryptography subsystem (if available), using
- POOL for the registration of cleanups, shutdowns, etc.
-
- ### Maybe this should move to one of our library initialization routines
- ### or an atomic initializer from the new api, in order not to break
- ### backwards compatibility with older api users.
-
- ### If not this should be duplicated in svnsync, svnmucc, javahl, the swig
- ### bindings, etc. etc. when we switch to the master password.
- */
-static svn_error_t *
-crypto_init(apr_pool_t *pool)
-{
-#if APU_HAVE_CRYPTO
- apr_status_t apr_err = apr_crypto_init(pool);
- if (apr_err)
- return svn_error_wrap_apr(apr_err,
- _("Failed to initialize cryptography subsystem"));
-#endif /* APU_HAVE_CRYPTO */
- return SVN_NO_ERROR;
-}
-
-
/*** Main. ***/
@@ -1620,11 +1592,6 @@ main(int argc, const char *argv[])
}
#endif
- /* Initialize the cryptography subsystem. */
- err = crypto_init(pool);
- if (err)
- return svn_cmdline_handle_exit_error(err, pool, "svn: ");
-
/* Initialize the RA library. */
err = svn_ra_initialize(pool);
if (err)