From: Kurt Zeilenga Date: Tue, 2 Dec 2003 16:57:34 +0000 (+0000) Subject: ITS#2807: version option support (-V[V]) based on patch submitted X-Git-Tag: OPENLDAP_REL_ENG_2_1_MP~298 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4898913fb6865c8fd1e9df6e7a9b1243741198dd;p=openldap ITS#2807: version option support (-V[V]) based on patch submitted by . --- diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 2304208e90..ce0d07dce7 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -103,6 +103,7 @@ static int cnvt_str2int( char *, STRDISP_P, int ); #endif /* LOG_LOCAL4 */ static int check_config = 0; +static int version = 0; static void usage( char *name ) @@ -130,6 +131,7 @@ usage( char *name ) "\t-t\t\tCheck configuration file and exit\n" #if defined(HAVE_SETUID) && defined(HAVE_SETGID) "\t-u user\t\tUser (id or name) to run as\n" + "\t-V\t\tprint version info (-VV only)\n" #endif ); } @@ -239,7 +241,7 @@ int main( int argc, char **argv ) #endif while ( (i = getopt( argc, argv, - "c:d:f:h:s:n:t" + "c:d:f:h:s:n:t:V" #if LDAP_PF_INET6 "46" #endif @@ -346,6 +348,9 @@ int main( int argc, char **argv ) case 't': check_config++; break; + case 'V': + version++; + break; default: usage( argv[0] ); @@ -364,11 +369,10 @@ int main( int argc, char **argv ) ldif_debug = slap_debug; #endif -#ifdef NEW_LOGGING - LDAP_LOG( SLAPD, INFO, "%s", Versionstr, 0, 0 ); -#else - Debug( LDAP_DEBUG_TRACE, "%s", Versionstr, 0, 0 ); -#endif + if ( version ) { + fprintf( stderr, "%s\n", Versionstr ); + if ( version > 1 ) goto stop; + } if( serverName == NULL ) { if ( (serverName = strrchr( argv[0], *LDAP_DIRSEP )) == NULL ) { @@ -384,6 +388,12 @@ int main( int argc, char **argv ) openlog( serverName, OPENLOG_OPTIONS ); #endif +#ifdef NEW_LOGGING + LDAP_LOG( SLAPD, INFO, "%s", Versionstr, 0, 0 ); +#else + Debug( LDAP_DEBUG_ANY, "%s", Versionstr, 0, 0 ); +#endif + if( !check_config && slapd_daemon_init( urls ) != 0 ) { rc = 1; SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 ); diff --git a/servers/slurpd/Makefile.in b/servers/slurpd/Makefile.in index d505a43684..18e1087dcd 100644 --- a/servers/slurpd/Makefile.in +++ b/servers/slurpd/Makefile.in @@ -51,7 +51,7 @@ sslurpd: version.o version.c: Makefile @-$(RM) $@ - $(MKVERSION) slurpd > $@ + $(MKVERSION) -s -n Versionstr slurpd > $@ version.o: version.c $(OBJS) $(SLURPD_L) diff --git a/servers/slurpd/args.c b/servers/slurpd/args.c index b764001012..380deeab19 100644 --- a/servers/slurpd/args.c +++ b/servers/slurpd/args.c @@ -80,7 +80,7 @@ doargs( g->myname = strdup( g->myname + 1 ); } - while ( (i = getopt( argc, argv, "d:f:n:or:t:" )) != EOF ) { + while ( (i = getopt( argc, argv, "d:f:n:or:t:V" )) != EOF ) { switch ( i ) { case 'd': /* set debug level and 'do not detach' flag */ g->no_detach = 1; @@ -140,6 +140,9 @@ doargs( snprintf(g->slurpd_rdir, sz, "%s" LDAP_DIRSEP "replica", optarg); } break; + case 'V': + (g->version)++; + break; default: usage( g->myname ); return( -1 ); diff --git a/servers/slurpd/globals.c b/servers/slurpd/globals.c index f6a7b97afe..1f7cba7088 100644 --- a/servers/slurpd/globals.c +++ b/servers/slurpd/globals.c @@ -84,6 +84,7 @@ init_globals( void ) g->myname = NULL; g->serverName = NULL; g->srpos = 0L; + g->version = 0; if ( St_init( &(g->st)) < 0 ) { fprintf( stderr, "Cannot initialize status data\n" ); exit( EXIT_FAILURE ); diff --git a/servers/slurpd/globals.h b/servers/slurpd/globals.h index 8f6e4feb60..1f9595f70b 100644 --- a/servers/slurpd/globals.h +++ b/servers/slurpd/globals.h @@ -81,6 +81,8 @@ typedef struct globals { /* Default name of kerberos srvtab file */ char *default_srvtab; #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */ + /* Non-zero if we shall print the version */ + int version; } Globals; diff --git a/servers/slurpd/main.c b/servers/slurpd/main.c index 5418ef79d1..1e4a53ffcb 100644 --- a/servers/slurpd/main.c +++ b/servers/slurpd/main.c @@ -60,6 +60,11 @@ #define MAIN_RETURN(x) return(x) #endif +#ifndef HAVE_MKVERSION +const char Versionstr[] = + OPENLDAP_PACKAGE " " OPENLDAP_VERSION " Standalone LDAP Replicator (slurpd)"; +#endif + #ifdef HAVE_NT_SERVICE_MANAGER void WINAPI ServiceMain( DWORD argc, LPTSTR *argv ) #else @@ -139,6 +144,20 @@ int main( int argc, char **argv ) goto stop; } + if ( sglob->version ) { + fprintf(stderr, "%s\n", Versionstr); + if (sglob->version > 1 ) { + rc = 1; + goto stop; + } + } + +#ifdef NEW_LOGGING + LDAP_LOG( SLURPD, INFO, "%s\n", Versionstr, 0, 0 ); +#else + Debug ( LDAP_DEBUG_ANY, "%s\n", Versionstr, 0, 0 ); +#endif + /* * Read slapd config file and initialize Re (per-replica) structs. */ diff --git a/servers/slurpd/proto-slurp.h b/servers/slurpd/proto-slurp.h index 70261951e4..fa01c987c1 100644 --- a/servers/slurpd/proto-slurp.h +++ b/servers/slurpd/proto-slurp.h @@ -107,4 +107,7 @@ int tsleep LDAP_P((time_t interval)); void start_lwp_scheduler LDAP_P(( void )); #endif +/*main.c */ +extern const char Versionstr[]; + #endif /* _PROTO_SLURP */