Browse Source

core: -f parameter can take the value '-' to read config from stdin

- allos piping the config from various sources (e.g., downloading from
  web)
- example: cat /etc/kamailio/kamailio.cfg | /usr/sbin/kamailio -f -
Daniel-Constantin Mierla 11 years ago
parent
commit
6f96f4fbc7
1 changed files with 6 additions and 1 deletions
  1. 6 1
      main.c

+ 6 - 1
main.c

@@ -1224,6 +1224,7 @@ int fix_cfg_file(void)
 	
 	
 	if (cfg_file == NULL) cfg_file = CFG_FILE;
 	if (cfg_file == NULL) cfg_file = CFG_FILE;
 	if (cfg_file[0] == '/') return 0;
 	if (cfg_file[0] == '/') return 0;
+	if (cfg_file[0] == '-' && strlen(cfg_file)==1) return 0;
 	
 	
 	/* cfg_file contains a relative pathname, get the current
 	/* cfg_file contains a relative pathname, get the current
 	 * working directory and add it at the beginning
 	 * working directory and add it at the beginning
@@ -2044,7 +2045,11 @@ int main(int argc, char** argv)
 	if (fix_cfg_file() < 0) goto error;
 	if (fix_cfg_file() < 0) goto error;
 
 
 	/* load config file or die */
 	/* load config file or die */
-	cfg_stream=fopen (cfg_file, "r");
+	if (cfg_file[0] == '-' && strlen(cfg_file)==1) {
+		cfg_stream=stdin;
+	} else {
+		cfg_stream=fopen (cfg_file, "r");
+	}
 	if (cfg_stream==0){
 	if (cfg_stream==0){
 		fprintf(stderr, "ERROR: loading config file(%s): %s\n", cfg_file,
 		fprintf(stderr, "ERROR: loading config file(%s): %s\n", cfg_file,
 				strerror(errno));
 				strerror(errno));