ptserver: Add cmdline options for config and log
authorSimon Wilkinson <sxw@your-file-system.com>
Wed, 23 Mar 2011 16:31:42 +0000 (16:31 +0000)
committerDerrick Brashear <shadow@dementia.org>
Sun, 10 Apr 2011 13:14:23 +0000 (06:14 -0700)
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 <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

doc/man-pages/pod8/ptserver.pod
src/ptserver/ptserver.c

index ff152c2..6c2d20f 100644 (file)
@@ -7,15 +7,19 @@ ptserver - Initializes the Protection Server
 =for html
 <div class="synopsis">
 
-B<ptserver> S<<< [B<-database> | B<-db> <I<db path>>] >>> S<<< [B<-p> <I<number of threads>>] >>> S<<< [B<-d> <I<debug level>>] >>>
-    S<<< [B<-groupdepth> <I<# of nested groups>>] >>>
-    S<<< [B<-default_access> <I<user access mask>> <I<group access mask>>] >>>
-    [B<-restricted>] [B<-enable_peer_stats>]
-    [B<-enable_process_stats>] [B<-allow-dotted-principals>]
-    [B<-rxbind>] S<<< [B<-auditlog> <I<file path>>] >>>
-    S<<< [B<-audit-interface> (file | sysvmq)] >>>
-    S<<< [B<-syslog>[=<I<FACILITY>>]] >>> S<<< [B<-rxmaxmtu> <I<bytes>>] >>>
-    [B<-help>]
+ptserver S<<< [B<-database> | B<-db> <I<db path>>] >>>
+S<<< [B<-p> <I<number of threads>>] >>> S<<< [B<-d> <I<debug level>>] >>>
+S<<< [B<-groupdepth> <I<# of nested groups>>] >>>
+S<<< [B<-default_access> <I<user access mask>> <I<group access mask>>] >>>
+[B<-restricted>] [B<-enable_peer_stats>]
+[B<-enable_process_stats>] [B<-allow-dotted-principals>]
+[B<-rxbind>] S<<< [B<-auditlog> <I<file path>>] >>>
+S<<< [B<-audit-interface> (file | sysvmq)] >>>
+S<<< [B<-syslog>[=<I<FACILITY>>]] >>>
+S<<< [B<-logfile <I<log file>>] >>>
+S<<< [B<-config <I<configuration path>>] >>>
+S<<< [B<-rxmaxmtu> <I<bytes>>] >>>
+[B<-help>]
 
 =for html
 </div>
@@ -145,6 +149,21 @@ log file.  B<-syslog>=I<FACILITY> 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> <I<log file>>
+
+Sets the file to use for server logging. If logfile is not specified, and
+no other logging options are supplied, this will be F</usr/afs/logs/PTLog>.
+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<bos>.
+
+=item B<-config> <I<configuration directory>>
+
+Set the location of the configuration directory used to configure this
+service. In a typical configuration this will be F</usr/afs/etc> - this
+option allows the use of alternative configuration locations for testing
+purposes.
+
 =item B<-auditlog> <I<log path>>
 
 Turns on audit logging, and sets the path for the audit log.  The audit
index d1c789c..d1c4d40 100644 (file)
@@ -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 <db path>] "
                   "[-auditlog <log path>] "
-                  "[-audit-interface <file|sysvmq> (default is file)] ");
+                  "[-audit-interface <file|sysvmq> (default is file)] "
+                  "[-config <config directory path>] "
+                  "[-logfile <log file path>] ");
 #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);