int create_listen_sockets(void) { listen_backlog = (int) config_get_number("global", "http port listen backlog", LISTEN_BACKLOG); if(config_exists("global", "bind socket to IP") && !config_exists("global", "bind to")) config_rename("global", "bind socket to IP", "bind to"); if(config_exists("global", "port") && !config_exists("global", "default port")) config_rename("global", "port", "default port"); listen_port = (int) config_get_number("global", "default port", LISTEN_PORT); if(listen_port < 1 || listen_port > 65535) { error("Invalid listen port %d given. Defaulting to %d.", listen_port, LISTEN_PORT); listen_port = (int) config_set_number("global", "default port", LISTEN_PORT); } debug(D_OPTIONS, "Default listen port set to %d.", listen_port); char *s = config_get("global", "bind to", "*"); while(*s) { char *e = s; // skip separators, moving both s(tart) and e(nd) while(isspace(*e) || *e == ',') s = ++e; // move e(nd) to the first separator while(*e && !isspace(*e) && *e != ',') e++; // is there anything? if(!*s || s == e) break; char buf[e - s + 1]; strncpyz(buf, s, e - s); bind_to_one(buf, listen_port, listen_backlog); s = e; } if(!listen_fds_count) fatal("Cannot listen on any socket. Exiting..."); return listen_fds_count; }
/* * config_update -- * Reconcile and update the command line configuration against the * config we found. */ int config_update(WT_SESSION *session, char **list) { int found; const char *cfg[] = { NULL, NULL, NULL }; char **configp, **listp; const char **rm; static const char *rmnames[] = { "filename", "id", "checkpoint", "checkpoint_lsn", "version", "source", NULL }; /* * If the object has been renamed, replace all of the column group, * index, file and table names with the new name. */ if (cmdname != NULL) { for (listp = list; *listp != NULL; listp += 2) if (WT_PREFIX_MATCH(*listp, "colgroup:") || WT_PREFIX_MATCH(*listp, "file:") || WT_PREFIX_MATCH(*listp, "index:") || WT_PREFIX_MATCH(*listp, "table:")) if (config_rename(listp, cmdname)) return (1); /* * If the object was renamed, and there are configuration pairs, * rename the configuration pairs as well, because we don't know * if the user used the old or new names for the pair's URI. */ for (configp = cmdconfig; cmdconfig != NULL && *configp != NULL; configp += 2) if (config_rename(configp, cmdname)) return (1); } /* * Remove all "filename=", "source=" and other configurations * that foil loading from the values. New filenames are chosen * as part of table load. */ for (listp = list; *listp != NULL; listp += 2) for (rm = rmnames; *rm != NULL; rm++) if (strstr(listp[1], *rm) != NULL) config_remove(listp[1], *rm); /* * It's possible to update everything except the key/value formats. * If there were command-line configuration pairs, walk the list of * command-line configuration strings, and check. */ for (configp = cmdconfig; cmdconfig != NULL && *configp != NULL; configp += 2) if (strstr(configp[1], "key_format=") || strstr(configp[1], "value_format=")) return (util_err(0, "the command line configuration string may not " "modify the object's key or value format")); /* * If there were command-line configuration pairs, walk the list of * command-line URIs and find a matching dump URI. For each match, * rewrite the dump configuration as described by the command-line * configuration. It is an error if a command-line URI doesn't find * a single, exact match, that's likely a mistake. */ for (configp = cmdconfig; cmdconfig != NULL && *configp != NULL; configp += 2) { found = 0; for (listp = list; *listp != NULL; listp += 2) { if (strncmp(*configp, listp[0], strlen(*configp)) != 0) continue; /* * !!! * We support JSON configuration strings, which leads to * configuration strings with brackets. Unfortunately, * that implies we can't simply append new configuration * strings to existing ones. We call an unpublished * WiredTiger API to do the concatenation: if anyone * else ever needs it we can make it public, but I think * that's unlikely. We're also playing fast and loose * with types, but it should work. */ cfg[0] = listp[1]; cfg[1] = configp[1]; if (__wt_config_concat( (WT_SESSION_IMPL *)session, cfg, &listp[1]) != 0) return (1); ++found; } switch (found) { case 0: return (util_err(0, "the command line object name %s was not matched " "by any loaded object name", *configp)); case 1: break; default: return (util_err(0, "the command line object name %s was not unique, " "matching more than a single loaded object name", *configp)); } } /* Leak the memory, I don't care. */ return (0); }
/* * config_update -- * Reconcile and update the command line configuration against the * config we found. */ int config_update(WT_SESSION *session, char **list) { WT_DECL_RET; size_t cnt; int found; const char *p, **cfg; char **configp, **listp; /* * If the object has been renamed, replace all of the column group, * index, file and table names with the new name. */ if (cmdname != NULL) { for (listp = list; *listp != NULL; listp += 2) if (WT_PREFIX_MATCH(*listp, "colgroup:") || WT_PREFIX_MATCH(*listp, "file:") || WT_PREFIX_MATCH(*listp, "index:") || WT_PREFIX_MATCH(*listp, "table:")) if (config_rename(session, listp, cmdname)) return (1); /* * If the object was renamed, and there are configuration pairs, * rename the configuration pairs as well, because we don't know * if the user used the old or new names for the pair's URI. */ for (configp = cmdconfig; cmdconfig != NULL && *configp != NULL; configp += 2) if (config_rename(session, configp, cmdname)) return (1); } /* * Updating the key/value formats seems like an easy mistake to make. * If there were command-line configuration pairs, walk the list of * command-line configuration strings and check. */ for (configp = cmdconfig; configp != NULL && *configp != NULL; configp += 2) if (strstr(configp[1], "key_format=") || strstr(configp[1], "value_format=")) return (util_err(session, 0, "an object's key or value format may not be " "modified")); /* * If there were command-line configuration pairs, walk the list of * command-line URIs and find a matching dump URI. It is an error * if a command-line URI doesn't find a single, exact match, that's * likely a mistake. */ for (configp = cmdconfig; configp != NULL && *configp != NULL; configp += 2) { for (found = 0, listp = list; *listp != NULL; listp += 2) if (strncmp(*configp, listp[0], strlen(*configp)) == 0) ++found; switch (found) { case 0: return (util_err(session, 0, "the command line object name %s was not matched " "by any loaded object name", *configp)); case 1: break; default: return (util_err(session, 0, "the command line object name %s was not unique, " "matching more than a single loaded object name", *configp)); } } /* * Allocate a big enough configuration stack to hold all of the command * line arguments, a list of configuration values to remove, and the * base configuration values, plus some slop. */ for (cnt = 0, configp = cmdconfig; cmdconfig != NULL && *configp != NULL; configp += 2) ++cnt; if ((cfg = calloc(cnt + 10, sizeof(cfg[0]))) == NULL) return (util_err(session, errno, NULL)); /* * For each match, rewrite the dump configuration as described by any * command-line configuration arguments. * * New filenames will be chosen as part of the table load, remove all * "filename=", "source=" and other configurations that foil loading * from the values; we call an unpublished API to do the work. */ for (listp = list; *listp != NULL; listp += 2) { cnt = 0; cfg[cnt++] = listp[1]; for (configp = cmdconfig; cmdconfig != NULL && *configp != NULL; configp += 2) if (strncmp(*configp, listp[0], strlen(*configp)) == 0) cfg[cnt++] = configp[1]; cfg[cnt++] = NULL; if ((ret = __wt_config_merge((WT_SESSION_IMPL *)session, cfg, "filename=,id=," "checkpoint=,checkpoint_lsn=,version=,source=,", &p)) != 0) break; free(listp[1]); listp[1] = (char *)p; } free(cfg); return (ret); }