Browse code

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 authored on 14/03/2014 23:29:43
Showing 1 changed files
... ...
@@ -1224,6 +1224,7 @@ int fix_cfg_file(void)
1224 1224
 	
1225 1225
 	if (cfg_file == NULL) cfg_file = CFG_FILE;
1226 1226
 	if (cfg_file[0] == '/') return 0;
1227
+	if (cfg_file[0] == '-' && strlen(cfg_file)==1) return 0;
1227 1228
 	
1228 1229
 	/* cfg_file contains a relative pathname, get the current
1229 1230
 	 * working directory and add it at the beginning
... ...
@@ -2044,7 +2045,11 @@ int main(int argc, char** argv)
2044 2044
 	if (fix_cfg_file() < 0) goto error;
2045 2045
 
2046 2046
 	/* load config file or die */
2047
-	cfg_stream=fopen (cfg_file, "r");
2047
+	if (cfg_file[0] == '-' && strlen(cfg_file)==1) {
2048
+		cfg_stream=stdin;
2049
+	} else {
2050
+		cfg_stream=fopen (cfg_file, "r");
2051
+	}
2048 2052
 	if (cfg_stream==0){
2049 2053
 		fprintf(stderr, "ERROR: loading config file(%s): %s\n", cfg_file,
2050 2054
 				strerror(errno));