[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [obfsproxy/master] Implement --version and put git revision on top of log.



commit 4f3d208352cada4bd3f31696e1d19f5061ed2692
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Mon Mar 19 12:55:34 2012 -0700

    Implement --version and put git revision on top of log.
    
    Also, implement --help.
---
 .gitignore  |    1 +
 ChangeLog   |    7 +++++++
 Makefile.am |   27 ++++++++++++++++++++++++++-
 src/main.c  |   51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 83 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore
index 848c2b5..590ceed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,6 +25,7 @@ Makefile.in
 /obfsproxy
 /unittests
 /tester.py
+/micro-revision.i
 
 # /doc/
 /doc/doxygen
diff --git a/ChangeLog b/ChangeLog
index 1bdab1a..fc055b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Changes in version 0.1.2 - <not yet released>
+ - Display git revision when we start logging. Fixes part of bug
+   #5157.
+ - Implement obfsproxy --version. Fixes the rest of bug #5157.
+ - Implement obfsproxy --help.
+
+
 Changes in version 0.1.1 - 2012-03-09
  - Add trailing slash to the torproject URL in the man page. Fixes
    bug #5311. Patch by Peter Palfrader.
diff --git a/Makefile.am b/Makefile.am
index f7c9c11..6b2731f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -54,7 +54,8 @@ noinst_HEADERS = \
 	src/protocols/dummy.h \
 	src/protocols/obfs2.h \
 	src/test/tinytest.h \
-	src/test/tinytest_macros.h
+	src/test/tinytest_macros.h \
+	micro-revision.i
 
 EXTRA_DIST = \
 	ChangeLog \
@@ -99,3 +100,27 @@ version:
 	   echo -n "git: " ;\
 	   (cd "$(top_srcdir)" && git rev-parse --short=16 HEAD); \
 	fi
+
+all: micro-revision.i
+
+micro-revision.i: FORCE
+	@rm -f micro-revision.tmp;					\
+	if test -d "$(top_srcdir)/.git" &&				\
+	  test -x "`which git 2>&1;true`"; then				\
+	  HASH="`cd "$(top_srcdir)" && git rev-parse --short=16 HEAD`"; 	\
+	  echo \"$$HASH\" > micro-revision.tmp; 			\
+        fi;								\
+	if test ! -f micro-revision.tmp ; then				\
+	  if test ! -f micro-revision.i ; then				\
+	    echo '""' > micro-revision.i;				\
+	  fi;								\
+	elif test ! -f micro-revision.i ||				\
+	  test x"`cat micro-revision.tmp`" != x"`cat micro-revision.i`"; then \
+	  mv micro-revision.tmp micro-revision.i;			\
+	fi; true
+	@rm -f micro-revision.tmp;
+
+CLEANFILES = micro-revision.i
+
+#Dummy target to ensure that micro-revision.i _always_ gets built.
+FORCE:
diff --git a/src/main.c b/src/main.c
index 0d690b7..30210f1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -31,6 +31,16 @@
 #include <event2/event.h>
 #include <event2/dns.h>
 
+/** String describing which obfsproxy git repository version the
+ * source was built from.  This string is generated by a bit of shell
+ * kludging in Makefile.am, and is usually right.
+ */
+const char obfs_git_revision[] =
+#ifndef _MSC_VER
+#include "micro-revision.i"
+#endif
+  "";
+
 static struct event_base *the_event_base;
 static struct event *sig_int;
 static struct event *sig_term;
@@ -41,6 +51,22 @@ static int is_external_proxy=1;
 /* Whether to scrub connection addresses -- on by default */
 int safe_logging=1;
 
+static char *the_obfsproxy_version = NULL;
+
+/** Return the current obfsproxy version. */
+static const char *
+get_version(void)
+{
+  if (!the_obfsproxy_version) {
+    if (strlen(obfs_git_revision))
+      obfs_asprintf(&the_obfsproxy_version, "git-%s", obfs_git_revision);
+    else
+      obfs_asprintf(&the_obfsproxy_version, "git");
+  }
+
+  return the_obfsproxy_version;
+}
+
 /**
    Prints the obfsproxy usage instructions then exits.
 */
@@ -61,6 +87,21 @@ usage(void)
           "--no-log ~ disable logging\n"
           "--no-safe-logging ~ disable safe (scrubbed address) logging\n");
 
+  if (the_obfsproxy_version)
+    free(the_obfsproxy_version);
+
+  exit(1);
+}
+
+/** Prints the obfsproxy version then exits. */
+static void ATTR_NORETURN
+version(void)
+{
+  printf("obfsproxy %s\n", get_version());
+
+  if (the_obfsproxy_version)
+    free(the_obfsproxy_version);
+
   exit(1);
 }
 
@@ -175,6 +216,10 @@ handle_obfsproxy_args(const char *const *argv)
       safe_logging=0;
     } else if (!strncmp(argv[i], "--managed", 10)) {
       is_external_proxy=0;
+    } else if (!strncmp(argv[i], "--version", 10)) {
+      version();
+    } else if (!strncmp(argv[i], "--help", 7)) {
+      usage();
     } else {
       log_error("Unrecognizable obfsproxy argument '%s'", argv[i]);
     }
@@ -279,8 +324,10 @@ obfsproxy_cleanup()
   cleanup_crypto();
   status_connections_cleanup();
   close_obfsproxy_logfile();
-}
 
+  if (the_obfsproxy_version)
+    free(the_obfsproxy_version);
+}
 
 /** Entry point */
 int
@@ -290,7 +337,7 @@ obfs_main(int argc, const char *const *argv)
 
   /* Handle optional obfsproxy arguments. */
   begin = argv + handle_obfsproxy_args(argv);
-  log_notice("Starting.");
+  log_notice("Starting (%s).", get_version());
 
   if (is_external_proxy) {
     if (launch_external_proxy(begin) < 0)

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits