Load the server configuration from the specified filename. * The function appends the additional configuration directives stored * in the 'options' string to the config file before loading. * * Both filename and options can be NULL, in such a case are considered * empty. This way loadServerConfig can be used to just load a file or * just load a string. */
| 645 | * empty. This way loadServerConfig can be used to just load a file or |
| 646 | * just load a string. */ |
| 647 | void loadServerConfig(char *filename, char config_from_stdin, char *options) { |
| 648 | sds config = sdsempty(); |
| 649 | char buf[CONFIG_MAX_LINE+1]; |
| 650 | FILE *fp; |
| 651 | |
| 652 | /* Load the file content */ |
| 653 | if (filename) { |
| 654 | if ((fp = fopen(filename,"r")) == NULL) { |
| 655 | serverLog(LL_WARNING, |
| 656 | "Fatal error, can't open config file '%s': %s", |
| 657 | filename, strerror(errno)); |
| 658 | exit(1); |
| 659 | } |
| 660 | while(fgets(buf,CONFIG_MAX_LINE+1,fp) != NULL) |
| 661 | config = sdscat(config,buf); |
| 662 | fclose(fp); |
| 663 | } |
| 664 | /* Append content from stdin */ |
| 665 | if (config_from_stdin) { |
| 666 | serverLog(LL_WARNING,"Reading config from stdin"); |
| 667 | fp = stdin; |
| 668 | while(fgets(buf,CONFIG_MAX_LINE+1,fp) != NULL) |
| 669 | config = sdscat(config,buf); |
| 670 | } |
| 671 | |
| 672 | /* Append the additional options */ |
| 673 | if (options) { |
| 674 | config = sdscat(config,"\n"); |
| 675 | config = sdscat(config,options); |
| 676 | } |
| 677 | loadServerConfigFromString(config); |
| 678 | sdsfree(config); |
| 679 | } |
| 680 | |
| 681 | /*----------------------------------------------------------------------------- |
| 682 | * CONFIG SET implementation |
no test coverage detected