FILE *pa_daemon_conf_open_default_script_file(pa_daemon_conf *c) { FILE *f; pa_assert(c); if (!c->default_script_file) { if (c->system_instance) f = pa_open_config_file(DEFAULT_SYSTEM_SCRIPT_FILE, NULL, ENV_SCRIPT_FILE, &c->default_script_file); else f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file); } else f = pa_fopen_cloexec(c->default_script_file, "r"); return f; }
static int save_rules(struct userdata *u) { FILE *f; int ret = -1; void *state = NULL; struct rule *rule; if (!u->modified) return 0; pa_log_info("Saving rules..."); f = u->table_file ? fopen(u->table_file, "w") : pa_open_config_file(NULL, DEFAULT_VOLUME_TABLE_FILE, NULL, &u->table_file, "w"); if (!f) { pa_log("Failed to open file '%s': %s", u->table_file, pa_cstrerror(errno)); goto finish; } pa_lock_fd(fileno(f), 1); while ((rule = pa_hashmap_iterate(u->hashmap, &state, NULL))) { unsigned i; fprintf(f, "%s\n", rule->name); if (rule->volume_is_set) { fprintf(f, "%u", rule->volume.channels); for (i = 0; i < rule->volume.channels; i++) fprintf(f, " %u", rule->volume.values[i]); } fprintf(f, "\n%s\n%s\n", rule->sink ? rule->sink : "", rule->source ? rule->source : ""); } ret = 0; u->modified = FALSE; pa_log_debug("Successfully saved rules..."); finish: if (f) { pa_lock_fd(fileno(f), 0); fclose(f); } return ret; }
int pa_client_conf_load(pa_client_conf *c, const char *filename) { FILE *f = NULL; char *fn = NULL; int r = -1; /* Prepare the configuration parse table */ pa_config_item table[] = { { "daemon-binary", pa_config_parse_string, NULL }, { "extra-arguments", pa_config_parse_string, NULL }, { "default-sink", pa_config_parse_string, NULL }, { "default-source", pa_config_parse_string, NULL }, { "default-server", pa_config_parse_string, NULL }, { "autospawn", pa_config_parse_bool, NULL }, { "cookie-file", pa_config_parse_string, NULL }, { "disable-shm", pa_config_parse_bool, NULL }, { NULL, NULL, NULL }, }; table[0].data = &c->daemon_binary; table[1].data = &c->extra_arguments; table[2].data = &c->default_sink; table[3].data = &c->default_source; table[4].data = &c->default_server; table[5].data = &c->autospawn; table[6].data = &c->cookie_file; table[7].data = &c->disable_shm; f = filename ? fopen((fn = pa_xstrdup(filename)), "r") : pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn, "r"); if (!f && errno != EINTR) { pa_log_warn("Failed to open configuration file '%s': %s", fn, pa_cstrerror(errno)); goto finish; } r = f ? pa_config_parse(fn, f, table, NULL) : 0; if (!r) r = pa_client_conf_load_cookie(c); finish: pa_xfree(fn); if (f) fclose(f); return r; }
int pa_client_conf_load(pa_client_conf *c, const char *filename) { FILE *f = NULL; char *fn = NULL; int r = -1; /* Prepare the configuration parse table */ pa_config_item table[] = { { "daemon-binary", pa_config_parse_string, &c->daemon_binary, NULL }, { "extra-arguments", pa_config_parse_string, &c->extra_arguments, NULL }, { "default-sink", pa_config_parse_string, &c->default_sink, NULL }, { "default-source", pa_config_parse_string, &c->default_source, NULL }, { "default-server", pa_config_parse_string, &c->default_server, NULL }, { "autospawn", pa_config_parse_bool, &c->autospawn, NULL }, { "cookie-file", pa_config_parse_string, &c->cookie_file, NULL }, { "disable-shm", pa_config_parse_bool, &c->disable_shm, NULL }, { "enable-shm", pa_config_parse_not_bool, &c->disable_shm, NULL }, { "shm-size-bytes", pa_config_parse_size, &c->shm_size, NULL }, { NULL, NULL, NULL, NULL }, }; if (filename) { if (!(f = fopen(filename, "r"))) { pa_log(_("Failed to open configuration file '%s': %s"), fn, pa_cstrerror(errno)); goto finish; } fn = pa_xstrdup(fn); } else { if (!(f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn))) if (errno != ENOENT) goto finish; } r = f ? pa_config_parse(fn, f, table, NULL) : 0; if (!r) r = pa_client_conf_load_cookie(c); finish: pa_xfree(fn); if (f) fclose(f); return r; }
int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { int r = -1; FILE *f = NULL; struct channel_conf_info ci; pa_config_item table[] = { { "daemonize", pa_config_parse_bool, &c->daemonize, NULL }, { "fail", pa_config_parse_bool, &c->fail, NULL }, { "high-priority", pa_config_parse_bool, &c->high_priority, NULL }, { "realtime-scheduling", pa_config_parse_bool, &c->realtime_scheduling, NULL }, { "disallow-module-loading", pa_config_parse_bool, &c->disallow_module_loading, NULL }, { "allow-module-loading", pa_config_parse_not_bool, &c->disallow_module_loading, NULL }, { "disallow-exit", pa_config_parse_bool, &c->disallow_exit, NULL }, { "allow-exit", pa_config_parse_not_bool, &c->disallow_exit, NULL }, { "use-pid-file", pa_config_parse_bool, &c->use_pid_file, NULL }, { "system-instance", pa_config_parse_bool, &c->system_instance, NULL }, #ifdef HAVE_DBUS { "local-server-type", parse_server_type, c, NULL }, #endif { "no-cpu-limit", pa_config_parse_bool, &c->no_cpu_limit, NULL }, { "cpu-limit", pa_config_parse_not_bool, &c->no_cpu_limit, NULL }, { "disable-shm", pa_config_parse_bool, &c->disable_shm, NULL }, { "enable-shm", pa_config_parse_not_bool, &c->disable_shm, NULL }, { "enable-memfd", pa_config_parse_not_bool, &c->disable_memfd, NULL }, { "flat-volumes", pa_config_parse_bool, &c->flat_volumes, NULL }, { "lock-memory", pa_config_parse_bool, &c->lock_memory, NULL }, { "enable-deferred-volume", pa_config_parse_bool, &c->deferred_volume, NULL }, { "exit-idle-time", pa_config_parse_int, &c->exit_idle_time, NULL }, { "scache-idle-time", pa_config_parse_int, &c->scache_idle_time, NULL }, { "realtime-priority", parse_rtprio, c, NULL }, { "dl-search-path", pa_config_parse_string, &c->dl_search_path, NULL }, { "default-script-file", pa_config_parse_string, &c->default_script_file, NULL }, { "log-target", parse_log_target, c, NULL }, { "log-level", parse_log_level, c, NULL }, { "verbose", parse_log_level, c, NULL }, { "resample-method", parse_resample_method, c, NULL }, { "default-sample-format", parse_sample_format, c, NULL }, { "default-sample-rate", parse_sample_rate, c, NULL }, { "alternate-sample-rate", parse_alternate_sample_rate, c, NULL }, { "default-sample-channels", parse_sample_channels, &ci, NULL }, { "default-channel-map", parse_channel_map, &ci, NULL }, { "default-fragments", parse_fragments, c, NULL }, { "default-fragment-size-msec", parse_fragment_size_msec, c, NULL }, { "deferred-volume-safety-margin-usec", pa_config_parse_unsigned, &c->deferred_volume_safety_margin_usec, NULL }, { "deferred-volume-extra-delay-usec", pa_config_parse_int, &c->deferred_volume_extra_delay_usec, NULL }, { "nice-level", parse_nice_level, c, NULL }, { "avoid-resampling", pa_config_parse_bool, &c->avoid_resampling, NULL }, { "disable-remixing", pa_config_parse_bool, &c->disable_remixing, NULL }, { "enable-remixing", pa_config_parse_not_bool, &c->disable_remixing, NULL }, { "remixing-use-all-sink-channels", pa_config_parse_bool, &c->remixing_use_all_sink_channels, NULL }, { "disable-lfe-remixing", pa_config_parse_bool, &c->disable_lfe_remixing, NULL }, { "enable-lfe-remixing", pa_config_parse_not_bool, &c->disable_lfe_remixing, NULL }, { "lfe-crossover-freq", pa_config_parse_unsigned, &c->lfe_crossover_freq, NULL }, { "load-default-script-file", pa_config_parse_bool, &c->load_default_script_file, NULL }, { "shm-size-bytes", pa_config_parse_size, &c->shm_size, NULL }, { "log-meta", pa_config_parse_bool, &c->log_meta, NULL }, { "log-time", pa_config_parse_bool, &c->log_time, NULL }, { "log-backtrace", pa_config_parse_unsigned, &c->log_backtrace, NULL }, #ifdef HAVE_SYS_RESOURCE_H { "rlimit-fsize", parse_rlimit, &c->rlimit_fsize, NULL }, { "rlimit-data", parse_rlimit, &c->rlimit_data, NULL }, { "rlimit-stack", parse_rlimit, &c->rlimit_stack, NULL }, { "rlimit-core", parse_rlimit, &c->rlimit_core, NULL }, #ifdef RLIMIT_RSS { "rlimit-rss", parse_rlimit, &c->rlimit_rss, NULL }, #endif #ifdef RLIMIT_NOFILE { "rlimit-nofile", parse_rlimit, &c->rlimit_nofile, NULL }, #endif #ifdef RLIMIT_AS { "rlimit-as", parse_rlimit, &c->rlimit_as, NULL }, #endif #ifdef RLIMIT_NPROC { "rlimit-nproc", parse_rlimit, &c->rlimit_nproc, NULL }, #endif #ifdef RLIMIT_MEMLOCK { "rlimit-memlock", parse_rlimit, &c->rlimit_memlock, NULL }, #endif #ifdef RLIMIT_LOCKS { "rlimit-locks", parse_rlimit, &c->rlimit_locks, NULL }, #endif #ifdef RLIMIT_SIGPENDING { "rlimit-sigpending", parse_rlimit, &c->rlimit_sigpending, NULL }, #endif #ifdef RLIMIT_MSGQUEUE { "rlimit-msgqueue", parse_rlimit, &c->rlimit_msgqueue, NULL }, #endif #ifdef RLIMIT_NICE { "rlimit-nice", parse_rlimit, &c->rlimit_nice, NULL }, #endif #ifdef RLIMIT_RTPRIO { "rlimit-rtprio", parse_rlimit, &c->rlimit_rtprio, NULL }, #endif #ifdef RLIMIT_RTTIME { "rlimit-rttime", parse_rlimit, &c->rlimit_rttime, NULL }, #endif #endif { NULL, NULL, NULL, NULL }, }; pa_xfree(c->config_file); c->config_file = NULL; f = filename ? pa_fopen_cloexec(c->config_file = pa_xstrdup(filename), "r") : pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file); if (!f && errno != ENOENT) { pa_log_warn(_("Failed to open configuration file: %s"), pa_cstrerror(errno)); goto finish; } ci.default_channel_map_set = ci.default_sample_spec_set = false; ci.conf = c; r = f ? pa_config_parse(c->config_file, f, table, NULL, true, NULL) : 0; if (r >= 0) { /* Make sure that channel map and sample spec fit together */ if (ci.default_sample_spec_set && ci.default_channel_map_set && c->default_channel_map.channels != c->default_sample_spec.channels) { pa_log_error(_("The specified default channel map has a different number of channels than the specified default number of channels.")); r = -1; goto finish; } else if (ci.default_sample_spec_set) pa_channel_map_init_extend(&c->default_channel_map, c->default_sample_spec.channels, PA_CHANNEL_MAP_DEFAULT); else if (ci.default_channel_map_set) c->default_sample_spec.channels = c->default_channel_map.channels; } finish: if (f) fclose(f); return r; }
static int load_rules(struct userdata *u) { FILE *f; int n = 0; int ret = -1; char buf_name[256], buf_volume[256], buf_sink[256], buf_source[256]; char *ln = buf_name; f = u->table_file ? fopen(u->table_file, "r") : pa_open_config_file(NULL, DEFAULT_VOLUME_TABLE_FILE, NULL, &u->table_file, "r"); if (!f) { if (errno == ENOENT) { pa_log_info("starting with empty ruleset."); ret = 0; } else pa_log("failed to open file '%s': %s", u->table_file, pa_cstrerror(errno)); goto finish; } pa_lock_fd(fileno(f), 1); while (!feof(f)) { struct rule *rule; pa_cvolume v; pa_bool_t v_is_set; if (!fgets(ln, sizeof(buf_name), f)) break; n++; pa_strip_nl(ln); if (ln[0] == '#') continue; if (ln == buf_name) { ln = buf_volume; continue; } if (ln == buf_volume) { ln = buf_sink; continue; } if (ln == buf_sink) { ln = buf_source; continue; } pa_assert(ln == buf_source); if (buf_volume[0]) { if (!parse_volume(buf_volume, &v)) { pa_log("parse failure in %s:%u, stopping parsing", u->table_file, n); goto finish; } v_is_set = TRUE; } else v_is_set = FALSE; ln = buf_name; if (pa_hashmap_get(u->hashmap, buf_name)) { pa_log("double entry in %s:%u, ignoring", u->table_file, n); continue; } rule = pa_xnew(struct rule, 1); rule->name = pa_xstrdup(buf_name); if ((rule->volume_is_set = v_is_set)) rule->volume = v; rule->sink = buf_sink[0] ? pa_xstrdup(buf_sink) : NULL; rule->source = buf_source[0] ? pa_xstrdup(buf_source) : NULL; pa_hashmap_put(u->hashmap, rule->name, rule); } if (ln != buf_name) { pa_log("invalid number of lines in %s.", u->table_file); goto finish; } ret = 0; finish: if (f) { pa_lock_fd(fileno(f), 0); fclose(f); } return ret; }