- string stream_id = *stream_it;
- fprintf(stderr, "WARNING: stream '%s' disappeared from the configuration file.\n",
- stream_id.c_str());
- fprintf(stderr, " It will not be deleted, but clients will not get any new inputs.\n");
- if (deserialized_inputs->count(stream_id) != 0) {
- delete (*deserialized_inputs)[stream_id];
- deserialized_inputs->erase(stream_id);
+ string url = *stream_it;
+ log(WARNING, "stream '%s' disappeared from the configuration file. "
+ "It will not be deleted, but clients will not get any new inputs. "
+ "If you really meant to delete it, set src=delete and reload.",
+ url.c_str());
+ }
+
+ // UDP streams.
+ for (unsigned i = 0; i < config.udpstreams.size(); ++i) {
+ const UDPStreamConfig &udpstream_config = config.udpstreams[i];
+ MarkPool *mark_pool = NULL;
+ if (udpstream_config.mark_pool != -1) {
+ mark_pool = mark_pools[udpstream_config.mark_pool];
+ }
+ int stream_index = servers->add_udpstream(udpstream_config.dst, mark_pool);
+
+ string src = udpstream_config.src;
+ if (!src.empty()) {
+ multimap<string, InputWithRefcount>::iterator input_it = inputs->find(src);
+ assert(input_it != inputs->end());
+ input_it->second.input->add_destination(stream_index);
+ ++input_it->second.refcount;
+ }
+ }
+}
+
+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);
+}
+
+void find_deleted_streams(const Config &config, set<string> *deleted_urls)
+{
+ for (unsigned i = 0; i < config.streams.size(); ++i) {
+ const StreamConfig &stream_config = config.streams[i];
+ if (stream_config.src == "delete") {
+ log(INFO, "Deleting stream '%s'.", stream_config.url.c_str());
+ deleted_urls->insert(stream_config.url);