[Pkg-privacy-commits] [libotr] 115/225: Don't have otrl_init call exit(1)

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:45:07 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository libotr.

commit ec38ddb5b72077a2bc625a5bcade133dc489e108
Author: Ian Goldberg <iang at cs.uwaterloo.ca>
Date:   Tue Aug 28 11:23:45 2012 -0400

    Don't have otrl_init call exit(1)
    
    Don't have otrl_init call exit(1) if the application's requested version
    number differs from libotr's.  Rather, return a non-zero error code, and
    have the application clean up gracefully.  The OTRL_INIT macro now
    checks the error code and does an exit(1) as the default behaviour, but
    the application can do what it likes.
---
 ChangeLog   | 11 +++++++++++
 UPGRADING   | 12 ++++++++++++
 src/proto.c |  6 ++++--
 src/proto.h |  7 +++++--
 4 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 82984bf..42de6ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-08-28
+
+	* UPGRADING:
+	* src/proto.h:
+	* src/proto.c: Don't have otrl_init call exit(1) if the
+	application's requested version number differs from libotr's.
+	Rather, return a non-zero error code, and have the application
+	clean up gracefully.  The OTRL_INIT macro now checks the error
+	code and does an exit(1) as the default behaviour, but the
+	application can do what it likes.
+
 2012-08-27
 
 	* src/auth.h:
diff --git a/UPGRADING b/UPGRADING
index 58cfc78..f7445c3 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -15,6 +15,7 @@ Table of Contents
 3.2. Instance Tags
 3.3. Fragmentation Changes
 3.4. Asynchronous Private Key Generation
+3.5. Library Initialization
 
 1. Introduction
 
@@ -499,5 +500,16 @@ If the privkey generation was cancelled, the application should call:
 void otrl_privkey_generate_cancelled(OtrlUserState us, void *newkey)
 
 
+3.5. Library Initialization
 
+If you currently initialize libotr with the recommended OTRL_INIT;
+macro, you do not need to change anything.
+
+If you call otrl_init(ver_major, ver_minor, ver_sub) directly, then know
+that this function no longer returns void.  Previously, if the
+application requested version numbers incompatible with those of the
+library, the library would exit(1).  Now, the otrl_init call will return
+a non-zero error code.  You must check the return value of otrl_init (a
+gcry_error_t), and if it is non-zero, your application's expected
+API/ABI does not match the installed libotr, and libotr cannot be used.
 
diff --git a/src/proto.c b/src/proto.c
index 3522249..b6c773a 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -48,7 +48,7 @@ unsigned int otrl_api_version = 0;
 
 /* Initialize the OTR library.  Pass the version of the API you are
  * using. */
-void otrl_init(unsigned int ver_major, unsigned int ver_minor,
+gcry_error_t otrl_init(unsigned int ver_major, unsigned int ver_minor,
 	unsigned int ver_sub)
 {
     unsigned int api_version;
@@ -60,7 +60,7 @@ void otrl_init(unsigned int ver_major, unsigned int ver_minor,
 		"with actual version %u.%u.%u.  Aborting.\n",
 		ver_major, ver_minor, ver_sub,
 		OTRL_VERSION_MAJOR, OTRL_VERSION_MINOR, OTRL_VERSION_SUB);
-	exit(1);
+	return gcry_error(GPG_ERR_INV_VALUE);
     }
 
     /* Set the API version.  If we get called multiple times for some
@@ -84,6 +84,8 @@ void otrl_init(unsigned int ver_major, unsigned int ver_minor,
     fprintf(stderr, "\nlibotr debugging is available.  Type %s in a message\n"
 	    "  to see debug info.\n\n", OTRL_DEBUGGING_DEBUGSTR);
 #endif
+
+    return gcry_error(GPG_ERR_NO_ERROR);
 }
 
 /* Return a pointer to a static string containing the version number of
diff --git a/src/proto.h b/src/proto.h
index 3419e9b..28be83f 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -102,12 +102,15 @@ typedef enum {
 
 /* Initialize the OTR library.  Pass the version of the API you are
  * using. */
-void otrl_init(unsigned int ver_major, unsigned int ver_minor,
+gcry_error_t otrl_init(unsigned int ver_major, unsigned int ver_minor,
 	unsigned int ver_sub);
 
 /* Shortcut */
 #define OTRL_INIT do { \
-	otrl_init(OTRL_VERSION_MAJOR, OTRL_VERSION_MINOR, OTRL_VERSION_SUB); \
+	if (otrl_init(OTRL_VERSION_MAJOR, OTRL_VERSION_MINOR, \
+		OTRL_VERSION_SUB)) { \
+	    exit(1); \
+	} \
     } while(0)
 
 /* Return a pointer to a static string containing the version number of

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/libotr.git



More information about the Pkg-privacy-commits mailing list