Module: sip-router Branch: master Commit: 1ef55a0915c675ada0cecf7c7b6e0bb0d72f4da7 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1ef55a09...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Tue Jul 13 19:59:26 2010 +0200
core: move version strings to a separate file
- moved version strings to variables (instead of macros) and in a separate file (ver.c). This will require re-compiling only one small file and re-linking on version or repository changes (e.g. new commit or local uncommitted changes), instead of recompiling main.c and core_cmd.c. - more detailed info about the repository state is now available via repo_hash (hash of the top commit) and repo_state (dirty or ""). - the core.version rpc reports now directly the version number (complete with repository hash and state), without prefixing it with "Server:", e.g.: ser 3.0.99-dev1 (i386/linux) dd9681-dirty instead of Server: ser (3.0.99-dev1 (i386/freebsd)) d89437-dirty
---
Makefile | 11 ++++++++--- core_cmd.c | 12 +++++------- main.c | 40 ++++++++++++++++------------------------ modules_k/kex/mi_core.c | 10 +++------- sr_module.h | 2 +- ver.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ ver.h | 43 +++++++++++++++++++++++++++++++++++++++++++ version.h => ver_defs.h | 9 +++------ 8 files changed, 125 insertions(+), 48 deletions(-)
diff --git a/Makefile b/Makefile index b3fa651..516b294 100644 --- a/Makefile +++ b/Makefile @@ -491,12 +491,11 @@ modules_search_path=$(subst $(space),:,$(strip\ # $(addprefix $(modules_target),$(modules_dirs))))
# special depends for main.o -main.d main.o: autover.h main.o: DEFS+=-DMODS_DIR='"$(modules_search_path)"'
-#special depends for core_cmd.o -core_cmd.d core_cmd.o: autover.h +#special depends for ver.c +ver.d ver.o: autover.h
include Makefile.shared
@@ -564,10 +563,14 @@ repo_ver=$(shell RV=`git rev-parse --verify --short=6 HEAD 2>/dev/null`;\ ; git diff-index --name-only HEAD 2>/dev/null | \ grep -v Makefile`" &&\ RV="$$RV"-dirty; echo "$$RV") +repo_hash=$(subst -dirty,,$(repo_ver)) +repo_state=$(patsubst %-dirty,dirty,$(repo_ver)) autover_h_dep=.git $(filter-out $(auto_gen), $(sources)) cfg.y cfg.lex else # else if .git/ does not exist repo_ver= +repo_hash="unknown" +repo_state= autover_h_dep= endif
@@ -579,6 +582,8 @@ autover.h: $(autover_h_dep) @echo " */" >>$@ @echo "" >>$@ @echo "#define REPO_VER "$(repo_ver)"" >>$@ + @echo "#define REPO_HASH "$(repo_hash)"" >>$@ + @echo "#define REPO_STATE "$(repo_state)"" >>$@
.PHONY: all all: $(NAME) every-module diff --git a/core_cmd.c b/core_cmd.c index b049af9..589908d 100644 --- a/core_cmd.c +++ b/core_cmd.c @@ -20,18 +20,16 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-/*! - * \file - * \brief SIP-router core :: - * \ingroup core - * Module: \ref core +/** core rpcs. + * @file core_cmd.c + * @ingroup core */
#include <time.h> #include <sys/types.h> #include <signal.h> -#include "autover.h" +#include "ver.h" #include "mem/mem.h" #include "mem/shm_mem.h" #include "sr_module.h" @@ -336,7 +334,7 @@ static const char* core_version_doc[] = {
static void core_version(rpc_t* rpc, void* c) { - rpc->add(c, "s", SERVER_HDR " " REPO_VER ); + rpc->add(c, "s", full_version); }
diff --git a/main.c b/main.c index 7d28bcd..8f71731 100644 --- a/main.c +++ b/main.c @@ -73,23 +73,20 @@ * 2008-08-08 sctp support (andrei) * 2008-08-19 -l support for mmultihomed addresses/addresses lists * (e.g. -l (eth0, 1.2.3.4, foo.bar) ) (andrei) - * 2010-04-19 added daemon_status_fd pipe to communicate the parent process with - the main process in daemonize mode, so the parent process can return - the proper exit status code (ibc) + * 2010-04-19 added daemon_status_fd pipe to communicate the parent process + * with the main process in daemonize mode, so the parent process + * can return the proper exit status code (ibc) */
-/*! - * \file - * \brief SIP-router core :: - * \ingroup core - * Module: \ref core +/** main file (init, daemonize, startup) + * @file main.c + * @ingroup core + * Module: core */
-/*! \defgroup core SIP-router core - * - * This modules implements a SIP server with a module interface - * for extendability. +/*! @defgroup core SIP-router core * + * sip router core part. */
#include <stdio.h> @@ -190,8 +187,7 @@ #ifdef DEBUG_DMALLOC #include <dmalloc.h> #endif -#include "autover.h" -#include "version.h" +#include "ver.h"
/* define SIG_DEBUG by default */ #ifdef NO_SIG_DEBUG @@ -200,10 +196,6 @@ #define SIG_DEBUG #endif
-static char id[]="@(#) $Id$"; -static char* version=SER_FULL_VERSION " " REPO_VER; -static char* flags=SER_COMPILE_FLAGS; -char compiled[]= __TIME__ " " __DATE__ ;
static char help_msg[]= "\ @@ -1688,7 +1680,7 @@ int main(int argc, char** argv) opterr = 0; while((c=getopt(argc,argv,options))!=-1) { if (c == 'h' || (optarg && strcmp(optarg, "-h") == 0)) { - printf("version: %s\n", version); + printf("version: %s\n", full_version); printf("%s",help_msg); exit(0); break; @@ -1724,8 +1716,8 @@ int main(int argc, char** argv) default_core_cfg.debug++; break; case 'V': - printf("version: %s\n", version); - printf("flags: %s\n", flags ); + printf("version: %s\n", full_version); + printf("flags: %s\n", ver_flags ); print_ct_constants(); #ifdef USE_SCTP tmp=malloc(256); @@ -1733,9 +1725,9 @@ int main(int argc, char** argv) printf("sctp unsupported socket options: %s\n", tmp); if (tmp) free(tmp); #endif - printf("%s\n",id); - printf("%s compiled on %s with %s\n", __FILE__, - compiled, COMPILER ); + printf("id: %s\n", ver_id); + printf("compiled on %s with %s\n", + ver_compiled_time, ver_compiler );
exit(0); break; diff --git a/modules_k/kex/mi_core.c b/modules_k/kex/mi_core.c index 157d9f4..241b0b6 100644 --- a/modules_k/kex/mi_core.c +++ b/modules_k/kex/mi_core.c @@ -47,7 +47,7 @@ #include "../../pt.h" #include "../../mem/mem.h" #include "../../lib/kmi/mi.h" -#include "../../version.h" +#include "../../ver.h" #include "../../cfg/cfg.h" #include "../../cfg/cfg_ctx.h"
@@ -139,12 +139,8 @@ static struct mi_root *mi_version(struct mi_root *cmd, void *param) if (node==0) goto error;
-#ifndef KAMAILIO_COMPILE_FLAGS -#define KAMAILIO_COMPILE_FLAGS SER_COMPILE_FLAGS -#endif - - node = add_mi_node_child( rpl, 0, MI_SSTR("Flags"), KAMAILIO_COMPILE_FLAGS, - sizeof(KAMAILIO_COMPILE_FLAGS)-1); + node = add_mi_node_child( rpl, 0, MI_SSTR("Flags"), (char*)ver_flags, + strlen(ver_flags)); if (node==0) goto error; diff --git a/sr_module.h b/sr_module.h index b055c88..d098f78 100644 --- a/sr_module.h +++ b/sr_module.h @@ -61,7 +61,7 @@ #include <dlfcn.h>
#include "parser/msg_parser.h" /* for sip_msg */ -#include "version.h" +#include "ver_defs.h" #include "rpc.h" #include "route_struct.h" #include "route.h" diff --git a/ver.c b/ver.c new file mode 100644 index 0000000..80f1b26 --- /dev/null +++ b/ver.c @@ -0,0 +1,46 @@ +/* + * $Id$ + * + * Copyright (C) 2010 iptelorg GmbH + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +/** version strings. + * @file ver.c + * @ingroup: core + */ +/* + * History: + * -------- + * 2010-07-13 initial version (andrei) +*/ + +#include "ver_defs.h" +#include "autover.h" /* REPO_VER, REPO_STATE */ + + +const char full_version[] = SER_FULL_VERSION " " REPO_VER; +const char ver_id[] = REPO_HASH " " REPO_STATE; +const char ver_compiled_time[] = __TIME__ " " __DATE__ ; +const char ver_compiler[] = COMPILER; + +const char ver_flags[] = SER_COMPILE_FLAGS; + +/** hash-state. */ +const char repo_ver[] = REPO_VER; +/** git hash. */ +const char repo_hash[] = REPO_HASH; +/** state of the repository: dirty (uncommited changes) or "" */ +const char repo_state[] = REPO_STATE; + +/* vi: set ts=4 sw=4 tw=79:ai:cindent: */ diff --git a/ver.h b/ver.h new file mode 100644 index 0000000..ba036f3 --- /dev/null +++ b/ver.h @@ -0,0 +1,43 @@ +/* + * $Id$ + * + * Copyright (C) 2010 iptelorg GmbH + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +/** version strings. + * @file ver.h + * @ingroup: core + */ +/* + * History: + * -------- + * 2010-07-13 initial version (andrei) +*/ + +#ifndef __ver_h +#define __ver_h + +extern const char full_version[]; +extern const char ver_id[]; +extern const char ver_compiled_time[]; +extern const char ver_compiler[]; +extern const char ver_flags[]; +extern const char repo_ver[]; +extern const char repo_hash[]; +extern const char repo_state[]; + + +#endif /*__ver_h*/ + +/* vi: set ts=4 sw=4 tw=79:ai:cindent: */ diff --git a/version.h b/ver_defs.h similarity index 98% rename from version.h rename to ver_defs.h index 1c60539..e6eb391 100644 --- a/version.h +++ b/ver_defs.h @@ -23,12 +23,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-/*! - * \file - * \brief SIP-router core :: version and compile flag macros - * \ingroup core - * - * Module: \ref core +/** compile flags and other version related defines. + * @file ver_defs.h + * @ingroup core */
#ifndef version_h