Re: [PATCH] support --version command line for common binaries
"Nikos Balkanas" <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <004e01c98edb$24afc1d0$02b2a8c0@tardis> |
Looks fine. Even the userguide patch. +1 How about giving also the shorthand version (-v)? Distinguishing between version and verbose could be done by whether the switch is followed by a number or not. BR, Nikos ----- Original Message ----- From: "Stipe Tolj" <[email protected]> To: "kannel_dev_mailinglist" <[email protected]> Sent: Saturday, February 14, 2009 5:13 PM Subject: [PATCH] support --version command line for common binaries > Hi list, > > please find attached a simple patch, that allows to use > > $ <kannel binary> --version > > to dump the full Kannel version string to stdout. > > I moved the version dumping related functions from gw/shared.[ch] to > gwlib/utils.[ch] and embedded the '--version' in get_and_set_debugs(), so > there > is need of change in the binary main functions itself. > > Please have a review and vote. As this is just a simple "feature add", > I'll > commit if there is no objection, which I don't expect ;) > > Stipe > > -- > ------------------------------------------------------------------- > KΟ†lner Landstrasse 419 > 40589 DΟsseldorf, NRW, Germany > > tolj.org system architecture Kannel Software Foundation (KSF) > http://www.tolj.org/ http://www.kannel.org/ > > mailto:st_{at}_tolj.org mailto:stolj_{at}_kannel.org > ------------------------------------------------------------------- > -------------------------------------------------------------------------------- > ### Eclipse Workspace Patch 1.0 > #P gateway-cvs-head > Index: gw/shared.h > =================================================================== > RCS file: /home/cvs/gateway/gw/shared.h,v > retrieving revision 1.22 > diff -u -r1.22 shared.h > --- gw/shared.h 12 Jan 2009 16:46:55 -0000 1.22 > +++ gw/shared.h 14 Feb 2009 15:00:56 -0000 > @@ -84,21 +84,6 @@ > > > /* > - * Return an octet string with information about Kannel version, > - * operating system, and libxml version. The caller must take care to > - * destroy the string when done. > - */ > -Octstr *version_report_string(const char *boxname); > - > - > -/* > - * Output the information returned by version_report_string to the log > - * files. > - */ > -void report_versions(const char *boxname); > - > - > -/* > * Open a connection to the bearerbox. > */ > Connection *connect_to_bearerbox_real(Octstr *host, int port, int ssl, > Octstr *our_host); > Index: gw/shared.c > =================================================================== > RCS file: /home/cvs/gateway/gw/shared.c,v > retrieving revision 1.44 > diff -u -r1.44 shared.c > --- gw/shared.c 12 Jan 2009 16:46:56 -0000 1.44 > +++ gw/shared.c 14 Feb 2009 15:00:56 -0000 > @@ -60,108 +60,15 @@ > * Lars Wirzenius > */ > > -#include <sys/utsname.h> > #include <libxml/xmlversion.h> > > #include "gwlib/gwlib.h" > #include "shared.h" > > -#if defined(HAVE_LIBSSL) || defined(HAVE_WTLS_OPENSSL) > -#include <openssl/opensslv.h> > -#endif > -#ifdef HAVE_MYSQL > -#include <mysql_version.h> > -#include <mysql.h> > -#endif > -#ifdef HAVE_SQLITE > -#include <sqlite.h> > -#endif > -#ifdef HAVE_SQLITE3 > -#include <sqlite3.h> > -#endif > -#ifdef HAVE_ORACLE > -#include <oci.h> > -#endif > - > > volatile enum program_status program_status = starting_up; > > > -void report_versions(const char *boxname) > -{ > - Octstr *os; > - > - os = version_report_string(boxname); > - debug("gwlib.gwlib", 0, "%s", octstr_get_cstr(os)); > - octstr_destroy(os); > -} > - > - > -Octstr *version_report_string(const char *boxname) > -{ > - struct utsname u; > - > - uname(&u); > - return octstr_format(GW_NAME " %s version `%s'.\nBuild `%s', compiler > `%s'.\n" > - "System %s, release %s, version %s, machine %s.\n" > - "Hostname %s, IP %s.\n" > - "Libxml version %s.\n" > -#ifdef HAVE_LIBSSL > - "Using " > -#ifdef HAVE_WTLS_OPENSSL > - "WTLS library " > -#endif > - "%s.\n" > -#endif > -#ifdef HAVE_MYSQL > - "Compiled with MySQL %s, using MySQL %s.\n" > -#endif > -#ifdef HAVE_SDB > - "Using LibSDB %s.\n" > -#endif > -#if defined(HAVE_SQLITE) || defined(HAVE_SQLITE3) > - "Using SQLite %s.\n" > -#endif > -#ifdef HAVE_ORACLE > -#if defined(OCI_MAJOR_VERSION) && defined(OCI_MINOR_VERSION) > - "Using Oracle OCI %d.%d.\n" > -#else > - "Using Oracle OCI.\n" > -#endif > -#endif > - "Using %s malloc.\n", > - boxname, GW_VERSION, > -#ifdef __GNUC__ > - (__DATE__ " " __TIME__) , > - __VERSION__, > -#else > - "unknown" , "unknown", > -#endif > - u.sysname, u.release, u.version, u.machine, > - octstr_get_cstr(get_official_name()), > - octstr_get_cstr(get_official_ip()), > - LIBXML_DOTTED_VERSION, > -#ifdef HAVE_LIBSSL > - OPENSSL_VERSION_TEXT, > -#endif > -#ifdef HAVE_MYSQL > - MYSQL_SERVER_VERSION, mysql_get_client_info(), > -#endif > -#ifdef HAVE_SDB > - LIBSDB_VERSION, > -#endif > -#if defined(HAVE_SQLITE) || defined(HAVE_SQLITE3) > - SQLITE_VERSION, > -#endif > -#ifdef HAVE_ORACLE > -#if defined(OCI_MAJOR_VERSION) && defined(OCI_MINOR_VERSION) > - OCI_MAJOR_VERSION, OCI_MINOR_VERSION, > -#endif > -#endif > - octstr_get_cstr(gwmem_type())); > -} > - > - > /*********************************************************************** > * Communication with the bearerbox. > */ > Index: gwlib/utils.h > =================================================================== > RCS file: /home/cvs/gateway/gwlib/utils.h,v > retrieving revision 1.31 > diff -u -r1.31 utils.h > --- gwlib/utils.h 12 Jan 2009 16:46:54 -0000 1.31 > +++ gwlib/utils.h 14 Feb 2009 15:00:56 -0000 > @@ -199,4 +199,19 @@ > unsigned long long gw_generate_id(void); > > > +/* > + * Return an octet string with information about Kannel version, > + * operating system, and libxml version. The caller must take care to > + * destroy the string when done. > + */ > +Octstr *version_report_string(const char *boxname); > + > + > +/* > + * Output the information returned by version_report_string to the log > + * files. > + */ > +void report_versions(const char *boxname); > + > + > #endif > Index: gwlib/utils.c > =================================================================== > RCS file: /home/cvs/gateway/gwlib/utils.c,v > retrieving revision 1.55 > diff -u -r1.55 utils.c > --- gwlib/utils.c 12 Jan 2009 16:46:52 -0000 1.55 > +++ gwlib/utils.c 14 Feb 2009 15:00:56 -0000 > @@ -74,12 +74,33 @@ > #include <sys/types.h> > #include <sys/wait.h> > #include <sys/stat.h> > +#include <sys/utsname.h> > #include <fcntl.h> > #include <pwd.h> > #include <grp.h> > +#include <libgen.h> > > #include "gwlib.h" > > +/* Headers required for the version dump. */ > +#if defined(HAVE_LIBSSL) || defined(HAVE_WTLS_OPENSSL) > +#include <openssl/opensslv.h> > +#endif > +#ifdef HAVE_MYSQL > +#include <mysql_version.h> > +#include <mysql.h> > +#endif > +#ifdef HAVE_SQLITE > +#include <sqlite.h> > +#endif > +#ifdef HAVE_SQLITE3 > +#include <sqlite3.h> > +#endif > +#ifdef HAVE_ORACLE > +#include <oci.h> > +#endif > + > + > /* pid of child process when parachute is used */ > static pid_t child_pid = -1; > /* saved child signal handlers */ > @@ -346,6 +367,7 @@ > error(errno, "Could not unlink pid-file `%s'", pid_file); > } > > + > static int change_user(const char *user) > { > struct passwd *pass; > @@ -381,7 +403,6 @@ > */ > > > - > MultibyteInt get_variable_value(Octet *source, int *len) > { > MultibyteInt retval = 0; > @@ -415,6 +436,7 @@ > return loc; > } > > + > Octet reverse_octet(Octet source) > { > Octet dest; > @@ -431,6 +453,81 @@ > } > > > +void report_versions(const char *boxname) > +{ > + Octstr *os; > + > + os = version_report_string(boxname); > + debug("gwlib.gwlib", 0, "%s", octstr_get_cstr(os)); > + octstr_destroy(os); > +} > + > + > +Octstr *version_report_string(const char *boxname) > +{ > + struct utsname u; > + > + uname(&u); > + return octstr_format(GW_NAME " %s version `%s'.\nBuild `%s', compiler > `%s'.\n" > + "System %s, release %s, version %s, machine > %s.\n" > + "Hostname %s, IP %s.\n" > + "Libxml version %s.\n" > +#ifdef HAVE_LIBSSL > + "Using " > +#ifdef HAVE_WTLS_OPENSSL > + "WTLS library " > +#endif > + "%s.\n" > +#endif > +#ifdef HAVE_MYSQL > + "Compiled with MySQL %s, using MySQL %s.\n" > +#endif > +#ifdef HAVE_SDB > + "Using LibSDB %s.\n" > +#endif > +#if defined(HAVE_SQLITE) || defined(HAVE_SQLITE3) > + "Using SQLite %s.\n" > +#endif > +#ifdef HAVE_ORACLE > +#if defined(OCI_MAJOR_VERSION) && defined(OCI_MINOR_VERSION) > + "Using Oracle OCI %d.%d.\n" > +#else > + "Using Oracle OCI.\n" > +#endif > +#endif > + "Using %s malloc.\n", > + boxname, GW_VERSION, > +#ifdef __GNUC__ > + (__DATE__ " " __TIME__) , > + __VERSION__, > +#else > + "unknown" , "unknown", > +#endif > + u.sysname, u.release, u.version, u.machine, > + octstr_get_cstr(get_official_name()), > + octstr_get_cstr(get_official_ip()), > + LIBXML_DOTTED_VERSION, > +#ifdef HAVE_LIBSSL > + OPENSSL_VERSION_TEXT, > +#endif > +#ifdef HAVE_MYSQL > + MYSQL_SERVER_VERSION, mysql_get_client_info(), > +#endif > +#ifdef HAVE_SDB > + LIBSDB_VERSION, > +#endif > +#if defined(HAVE_SQLITE) || defined(HAVE_SQLITE3) > + SQLITE_VERSION, > +#endif > +#ifdef HAVE_ORACLE > +#if defined(OCI_MAJOR_VERSION) && defined(OCI_MINOR_VERSION) > + OCI_MAJOR_VERSION, OCI_MINOR_VERSION, > +#endif > +#endif > + octstr_get_cstr(gwmem_type())); > +} > + > + > int get_and_set_debugs(int argc, char **argv, > int (*find_own) (int index, int argc, char **argv)) > { > @@ -492,6 +589,11 @@ > } else if (strcmp(argv[i], "-g")==0 || strcmp(argv[i], > "--generate")==0) { > cfg_dump_all(); > exit(0); > + } else if (strcmp(argv[i], "--version")==0) { > + Octstr *version = version_report_string(basename(argv[0])); > + printf("%s", octstr_get_cstr(version)); > + octstr_destroy(version); > + exit(0); > } else if (strcmp(argv[i],"--")==0) { > i++; > break; > Index: doc/userguide/userguide.xml > =================================================================== > RCS file: /home/cvs/gateway/doc/userguide/userguide.xml,v > retrieving revision 1.344 > diff -u -r1.344 userguide.xml > --- doc/userguide/userguide.xml 14 Jan 2009 11:11:46 -0000 1.344 > +++ doc/userguide/userguide.xml 14 Feb 2009 15:00:56 -0000 > @@ -1654,6 +1654,12 @@ > <title>Kannel Command Line Options</title> > <tgroup cols="2"> > <tbody> > + <row><entry><literal></literal></entry> > + <entry morerows="1" valign="bottom"> > + Print the version of the Kannel binary. > + </entry></row> > + <row><entry><literal>--version</literal></entry></row> > + > <row><entry><literal>-v <level></literal></entry> > <entry morerows="1" valign="bottom"> > Set verbosity level for stdout (screen) logging. Default is > 0, >