MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / loadServerConfig

Function loadServerConfig

src/config.cpp:836–868  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

834 * empty. This way loadServerConfig can be used to just load a file or
835 * just load a string. */
836void loadServerConfig(char *filename, char config_from_stdin, char *options) {
837 sds config = sdsempty();
838 char buf[CONFIG_MAX_LINE+1];
839 FILE *fp;
840
841 /* Load the file content */
842 if (filename) {
843 if ((fp = fopen(filename,"r")) == NULL) {
844 serverLog(LL_WARNING,
845 "Fatal error, can't open config file '%s': %s",
846 filename, strerror(errno));
847 exit(1);
848 }
849 while(fgets(buf,CONFIG_MAX_LINE+1,fp) != NULL)
850 config = sdscat(config,buf);
851 fclose(fp);
852 }
853 /* Append content from stdin */
854 if (config_from_stdin) {
855 serverLog(LL_WARNING,"Reading config from stdin");
856 fp = stdin;
857 while(fgets(buf,CONFIG_MAX_LINE+1,fp) != NULL)
858 config = sdscat(config,buf);
859 }
860
861 /* Append the additional options */
862 if (options) {
863 config = sdscat(config,"\n");
864 config = sdscat(config,options);
865 }
866 loadServerConfigFromString(config);
867 sdsfree(config);
868}
869
870/*-----------------------------------------------------------------------------
871 * CONFIG SET implementation

Callers 2

mainFunction · 0.85

Calls 5

sdsemptyFunction · 0.85
serverLogFunction · 0.85
sdscatFunction · 0.85
sdsfreeFunction · 0.85

Tested by

no test coverage detected