+void create_streams(const Config &config,
+ const set<string> &deserialized_stream_ids,
+ map<string, Input *> *deserialized_inputs)
+{
+ vector<MarkPool *> mark_pools; // FIXME: leak
+ for (unsigned i = 0; i < config.mark_pools.size(); ++i) {
+ const MarkPoolConfig &mp_config = config.mark_pools[i];
+ mark_pools.push_back(new MarkPool(mp_config.from, mp_config.to));
+ }
+
+ set<string> expecting_stream_ids = deserialized_stream_ids;
+ for (unsigned i = 0; i < config.streams.size(); ++i) {
+ const StreamConfig &stream_config = config.streams[i];
+ if (deserialized_stream_ids.count(stream_config.stream_id) == 0) {
+ servers->add_stream(stream_config.stream_id, stream_config.backlog_size);
+ } else {
+ servers->set_backlog_size(stream_config.stream_id, stream_config.backlog_size);
+ }
+ expecting_stream_ids.erase(stream_config.stream_id);
+
+ if (stream_config.mark_pool != -1) {
+ servers->set_mark_pool(stream_config.stream_id,
+ mark_pools[stream_config.mark_pool]);
+ }
+ }
+
+ // Warn about any servers we've lost.
+ // TODO: Make an option (delete=yes?) to actually shut down streams.
+ for (set<string>::const_iterator stream_it = expecting_stream_ids.begin();
+ stream_it != expecting_stream_ids.end();
+ ++stream_it) {
+ string stream_id = *stream_it;
+ log(WARNING, "stream '%s' disappeared from the configuration file. "
+ "It will not be deleted, but clients will not get any new inputs.",
+ stream_id.c_str());
+ if (deserialized_inputs->count(stream_id) != 0) {
+ delete (*deserialized_inputs)[stream_id];
+ deserialized_inputs->erase(stream_id);
+ }
+ }
+}
+
+void open_logs(const vector<LogConfig> &log_destinations)
+{
+ for (size_t i = 0; i < log_destinations.size(); ++i) {
+ if (log_destinations[i].type == LogConfig::LOG_TYPE_FILE) {
+ add_log_destination_file(log_destinations[i].filename);
+ } else if (log_destinations[i].type == LogConfig::LOG_TYPE_CONSOLE) {
+ add_log_destination_console();
+ } else if (log_destinations[i].type == LogConfig::LOG_TYPE_SYSLOG) {
+ add_log_destination_syslog();
+ } else {
+ assert(false);
+ }
+ }
+ start_logging();
+}
+
+bool dry_run_config(const std::string &argv0, const std::string &config_filename)
+{
+ char *argv0_copy = strdup(argv0.c_str());
+ char *config_filename_copy = strdup(config_filename.c_str());
+
+ pid_t pid = fork();
+ switch (pid) {
+ case -1:
+ log_perror("fork()");
+ free(argv0_copy);
+ free(config_filename_copy);
+ return false;
+ case 0:
+ // Child.
+ execlp(argv0_copy, argv0_copy, "--test-config", config_filename_copy, NULL);
+ log_perror(argv0_copy);
+ _exit(1);
+ default:
+ // Parent.
+ break;
+ }
+
+ free(argv0_copy);
+ free(config_filename_copy);
+
+ int status;
+ pid_t err;
+ do {
+ err = waitpid(pid, &status, 0);
+ } while (err == -1 && errno == EINTR);
+
+ if (err == -1) {
+ log_perror("waitpid()");
+ return false;
+ }
+
+ return (WIFEXITED(status) && WEXITSTATUS(status) == 0);
+}
+