diff src/sm-archive.cpp @ 27:9298f8b00db2 stable-1-0-10

patches from Takao Abe add switches for config and pid files
author Carl Byington <carl@five-ten-sg.com>
date Thu, 24 May 2018 10:35:45 -0700
parents 09564d4acd9e
children
line wrap: on
line diff
--- a/src/sm-archive.cpp	Mon Feb 06 12:08:35 2017 -0800
+++ b/src/sm-archive.cpp	Thu May 24 10:35:45 2018 -0700
@@ -56,7 +56,11 @@
 	void sig_chld(int signo);
 }
 
+// command line options
+const char  *optionConfigFile = "sm-archive.conf" ;
+const char  *optionPidFile    = "/var/run/sm-archive.pid" ;
 int  debug_syslog  = 0;
+//
 bool syslog_opened = false;
 bool use_syslog    = true;	// false to printf
 bool loader_run    = true;	// used to stop the config loader thread
@@ -293,7 +297,7 @@
 		snprintf(buf, sizeof(buf), "loading configuration generation %d", newc->generation);
 		my_syslog(buf);
 	}
-	if (load_conf(*newc, "sm-archive.conf")) {
+    if (load_conf(*newc, optionConfigFile)) {
 		newc->load_time = time(NULL);
 		return newc;
 	}
@@ -349,13 +353,15 @@
 void usage(const char *prog);
 void usage(const char *prog)
 {
-	fprintf(stderr, "Usage: %s  [-d [level]] [-c] -p sm-sock-addr [-t timeout]\n", prog);
+    fprintf(stderr, "Usage: %s  [-d [level]] [-c] -p sm-sock-addr [-t timeout] [-C config-file] [-P pid-file]\n", prog);
 	fprintf(stderr, "where sm-sock-addr is for the connection to sendmail\n");
 	fprintf(stderr, "    and should be one of\n");
 	fprintf(stderr, "        inet:port@ip-address\n");
 	fprintf(stderr, "        local:local-domain-socket-file-name\n");
 	fprintf(stderr, "-c will load and dump the config to stdout\n");
 	fprintf(stderr, "-d will set the syslog message level, currently 0 to 3\n");
+    fprintf(stderr, "-C specifies the config file, defaults to sm-archive.conf\n");
+    fprintf(stderr, "-P specifies the pid file, defaults to /var/run/sm-archive.pid\n");
 }
 
 
@@ -393,7 +399,7 @@
 	bool check	 = false;
 	bool setconn = false;
 	int c;
-	const char *args = "p:t:d:ch";
+    const char *args = "p:t:d:chC:P:";
 	extern char *optarg;
 
 	// Process command line options
@@ -433,6 +439,22 @@
 				else								   debug_syslog = atoi(optarg);
 				break;
 
+            case 'C':
+                if (optarg == NULL || *optarg == '\0') {
+                    fprintf( stderr, "Must specify the config file path: %s\n", optarg );
+                    exit(EX_USAGE);
+                }
+                optionConfigFile = optarg ;
+                break ;
+
+            case 'P':
+                if (optarg == NULL || *optarg == '\0') {
+                    fprintf( stderr, "Must specify the pid file path: %s\n", optarg );
+                    exit(EX_USAGE);
+                }
+                optionPidFile = optarg ;
+                break ;
+
 			case 'h':
 			default:
 				usage(argv[0]);
@@ -473,7 +495,7 @@
 	}
 
 	// write the pid
-	const char *pidpath = "/var/run/sm-archive.pid";
+    const char *pidpath = optionPidFile;
 	unlink(pidpath);
 	FILE *f = fopen(pidpath, "w");
 	if (f) {