From da3921e7c78ec2f9a7861cfb5d06df96bb1e477f Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Wed, 23 Mar 2011 16:31:42 +0000 Subject: [PATCH] ptserver: Add cmdline options for config and log Make it possible to set the location of the ptserver's configuration directory, and the file that it logs to, from the command line. This makes it possible to bring up a ptserver without requiring an installation on the system for testing purposes. Change-Id: I914eb842256eb74506490fcf5532b4138e6f3875 Reviewed-on: http://gerrit.openafs.org/4447 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- doc/man-pages/pod8/ptserver.pod | 37 +++++++++++++++++++++++++-------- src/ptserver/ptserver.c | 24 ++++++++++++++++++--- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/doc/man-pages/pod8/ptserver.pod b/doc/man-pages/pod8/ptserver.pod index ff152c2be..6c2d20f2b 100644 --- a/doc/man-pages/pod8/ptserver.pod +++ b/doc/man-pages/pod8/ptserver.pod @@ -7,15 +7,19 @@ ptserver - Initializes the Protection Server =for html
-B S<<< [B<-database> | B<-db> >] >>> S<<< [B<-p> >] >>> S<<< [B<-d> >] >>> - S<<< [B<-groupdepth> >] >>> - S<<< [B<-default_access> > >] >>> - [B<-restricted>] [B<-enable_peer_stats>] - [B<-enable_process_stats>] [B<-allow-dotted-principals>] - [B<-rxbind>] S<<< [B<-auditlog> >] >>> - S<<< [B<-audit-interface> (file | sysvmq)] >>> - S<<< [B<-syslog>[=>]] >>> S<<< [B<-rxmaxmtu> >] >>> - [B<-help>] +ptserver S<<< [B<-database> | B<-db> >] >>> +S<<< [B<-p> >] >>> S<<< [B<-d> >] >>> +S<<< [B<-groupdepth> >] >>> +S<<< [B<-default_access> > >] >>> +[B<-restricted>] [B<-enable_peer_stats>] +[B<-enable_process_stats>] [B<-allow-dotted-principals>] +[B<-rxbind>] S<<< [B<-auditlog> >] >>> +S<<< [B<-audit-interface> (file | sysvmq)] >>> +S<<< [B<-syslog>[=>]] >>> +S<<< [B<-logfile >] >>> +S<<< [B<-config >] >>> +S<<< [B<-rxmaxmtu> >] >>> +[B<-help>] =for html
@@ -145,6 +149,21 @@ log file. B<-syslog>=I can be used to specify to which facility the log message should be sent. Logging message sent to syslog are tagged with the string "ptserver". +=item B<-logfile> > + +Sets the file to use for server logging. If logfile is not specified, and +no other logging options are supplied, this will be F. +Note that this option is intended for debugging and testing purposes. +Changing the location of the log file from the command line may result +in undesirable interactions with tools such as B. + +=item B<-config> > + +Set the location of the configuration directory used to configure this +service. In a typical configuration this will be F - this +option allows the use of alternative configuration locations for testing +purposes. + =item B<-auditlog> > Turns on audit logging, and sets the path for the audit log. The audit diff --git a/src/ptserver/ptserver.c b/src/ptserver/ptserver.c index d1c789ce8..d1c4d40b0 100644 --- a/src/ptserver/ptserver.c +++ b/src/ptserver/ptserver.c @@ -206,6 +206,8 @@ main(int argc, char **argv) afs_uint32 host = htonl(INADDR_ANY); const char *pr_dbaseName; + const char *configDir; + const char *logFile; char *whoami = "ptserver"; int a; @@ -242,6 +244,8 @@ main(int argc, char **argv) } pr_dbaseName = AFSDIR_SERVER_PRDB_FILEPATH; + configDir = AFSDIR_SERVER_ETC_DIRPATH; + logFile = AFSDIR_SERVER_PTLOG_FILEPATH; #if defined(SUPERGROUPS) /* make sure the structures for database records are the same size */ @@ -337,12 +341,26 @@ main(int argc, char **argv) RX_MAX_PACKET_DATA_SIZE); PT_EXIT(1); } + } else if (!strncmp(arg, "-config", alen)) { + if ((a + 1) > argc) { + fprintf(stderr, "missing argument for -config\n"); + PT_EXIT(1); + } + configDir = argv[++a]; + } else if (!strncmp(arg, "-logfile", alen)) { + if ((a + 1) > argc) { + fprintf(stderr, "missing argument for -logfile\n"); + PT_EXIT(1); + } + logFile = argv[++a]; } else if (*arg == '-') { /* hack in help flag support */ printf("Usage: ptserver [-database ] " "[-auditlog ] " - "[-audit-interface (default is file)] "); + "[-audit-interface (default is file)] " + "[-config ] " + "[-logfile ] "); #ifndef AFS_NT40_ENV printf("[-syslog[=FACILITY]] "); #endif @@ -376,10 +394,10 @@ main(int argc, char **argv) #ifndef AFS_NT40_ENV serverLogSyslogTag = "ptserver"; #endif - OpenLog(AFSDIR_SERVER_PTLOG_FILEPATH); /* set up logging */ + OpenLog(logFile); /* set up logging */ SetupLogSignals(); - prdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH); + prdir = afsconf_Open(configDir); if (!prdir) { fprintf(stderr, "ptserver: can't open configuration directory.\n"); PT_EXIT(1); -- 2.39.5