mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
Revert "conf: Load and stack all config files."
This reverts commit db44fe47ee.
We should not be merging config files at this point. Generating config
files should be done offline and only the result is loaded here.
This commit is contained in:
parent
61007dd412
commit
342ae0b643
1 changed files with 78 additions and 98 deletions
|
|
@ -64,78 +64,63 @@ static int make_path(char *path, int size, const char *paths[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_read_path(char *path, size_t size, const char *prefix, const char *name,
|
static int get_read_path(char *path, size_t size, const char *prefix, const char *name)
|
||||||
bool useronly, uint32_t *state)
|
|
||||||
{
|
{
|
||||||
const char *dir;
|
const char *dir;
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
|
|
||||||
while (true) {
|
if (prefix[0] == '/') {
|
||||||
switch ((*state)++) {
|
const char *paths[] = { prefix, name, NULL };
|
||||||
case 0:
|
if (make_path(path, size, paths) == 0 &&
|
||||||
if (prefix[0] == '/') {
|
access(path, R_OK) == 0)
|
||||||
const char *paths[] = { prefix, name, NULL };
|
return 1;
|
||||||
if (make_path(path, size, paths) == 0 &&
|
return -ENOENT;
|
||||||
access(path, R_OK) == 0)
|
}
|
||||||
return 1;
|
if (pw_check_option("no-config", "true"))
|
||||||
return -ENOENT;
|
goto no_config;
|
||||||
}
|
|
||||||
break;
|
dir = getenv("PIPEWIRE_CONFIG_DIR");
|
||||||
case 1:
|
if (dir != NULL) {
|
||||||
if (useronly)
|
const char *paths[] = { dir, prefix, name, NULL };
|
||||||
break;
|
if (make_path(path, size, paths) == 0 &&
|
||||||
dir = getenv("PIPEWIRE_CONFIG_DIR");
|
access(path, R_OK) == 0)
|
||||||
if (dir != NULL) {
|
return 1;
|
||||||
const char *paths[] = { dir, prefix, name, NULL };
|
}
|
||||||
if (make_path(path, size, paths) == 0 &&
|
|
||||||
access(path, R_OK) == 0)
|
dir = getenv("XDG_CONFIG_HOME");
|
||||||
return 1;
|
if (dir != NULL) {
|
||||||
}
|
const char *paths[] = { dir, "pipewire", prefix, name, NULL };
|
||||||
dir = PIPEWIRE_CONFDATADIR;
|
if (make_path(path, size, paths) == 0 &&
|
||||||
if (dir != NULL) {
|
access(path, R_OK) == 0)
|
||||||
const char *paths[] = { dir, prefix, name, NULL };
|
return 1;
|
||||||
if (make_path(path, size, paths) == 0 &&
|
}
|
||||||
access(path, R_OK) == 0)
|
dir = getenv("HOME");
|
||||||
return 1;
|
if (dir == NULL) {
|
||||||
}
|
struct passwd pwd, *result = NULL;
|
||||||
break;
|
if (getpwuid_r(getuid(), &pwd, buffer, sizeof(buffer), &result) == 0)
|
||||||
case 2:
|
dir = result ? result->pw_dir : NULL;
|
||||||
if (pw_check_option("no-config", "true"))
|
}
|
||||||
return 0;
|
if (dir != NULL) {
|
||||||
if (useronly)
|
const char *paths[] = { dir, ".config", "pipewire", prefix, name, NULL };
|
||||||
break;
|
if (make_path(path, size, paths) == 0 &&
|
||||||
dir = PIPEWIRE_CONFIG_DIR;
|
access(path, R_OK) == 0)
|
||||||
if (dir != NULL) {
|
return 1;
|
||||||
const char *paths[] = { dir, prefix, name, NULL };
|
}
|
||||||
if (make_path(path, size, paths) == 0 &&
|
|
||||||
access(path, R_OK) == 0)
|
dir = PIPEWIRE_CONFIG_DIR;
|
||||||
return 1;
|
if (dir != NULL) {
|
||||||
}
|
const char *paths[] = { dir, prefix, name, NULL };
|
||||||
break;
|
if (make_path(path, size, paths) == 0 &&
|
||||||
case 3:
|
access(path, R_OK) == 0)
|
||||||
dir = getenv("XDG_CONFIG_HOME");
|
return 1;
|
||||||
if (dir != NULL) {
|
}
|
||||||
const char *paths[] = { dir, "pipewire", prefix, name, NULL };
|
no_config:
|
||||||
if (make_path(path, size, paths) == 0 &&
|
dir = PIPEWIRE_CONFDATADIR;
|
||||||
access(path, R_OK) == 0)
|
if (dir != NULL) {
|
||||||
return 1;
|
const char *paths[] = { dir, prefix, name, NULL };
|
||||||
}
|
if (make_path(path, size, paths) == 0 &&
|
||||||
dir = getenv("HOME");
|
access(path, R_OK) == 0)
|
||||||
if (dir == NULL) {
|
return 1;
|
||||||
struct passwd pwd, *result = NULL;
|
|
||||||
if (getpwuid_r(getuid(), &pwd, buffer, sizeof(buffer), &result) == 0)
|
|
||||||
dir = result ? result->pw_dir : NULL;
|
|
||||||
}
|
|
||||||
if (dir != NULL) {
|
|
||||||
const char *paths[] = { dir, ".config", "pipewire", prefix, name, NULL };
|
|
||||||
if (make_path(path, size, paths) == 0 &&
|
|
||||||
access(path, R_OK) == 0)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -249,58 +234,53 @@ error:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int conf_load(const char *prefix, const char *name, bool useronly, struct pw_properties *conf)
|
static int conf_load(const char *prefix, const char *name, struct pw_properties *conf)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX], *data;
|
char path[PATH_MAX], *data;
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
int fd, count = 0;
|
int fd;
|
||||||
uint32_t state = 0;
|
|
||||||
|
|
||||||
if (prefix == NULL) {
|
if (prefix == NULL) {
|
||||||
prefix = name;
|
prefix = name;
|
||||||
name = NULL;
|
name = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
if (get_read_path(path, sizeof(path), prefix, name) == 0) {
|
||||||
if (get_read_path(path, sizeof(path), prefix, name, useronly, &state) <= 0)
|
pw_log_debug(NAME" %p: can't load config '%s': %m", conf, path);
|
||||||
break;
|
|
||||||
|
|
||||||
pw_log_info(NAME" %p: loading config '%s'", conf, path);
|
|
||||||
if ((fd = open(path, O_CLOEXEC | O_RDONLY)) < 0) {
|
|
||||||
pw_log_warn(NAME" %p: error opening '%s': %m", conf, path);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = NULL;
|
|
||||||
if (fstat(fd, &sbuf) < 0) {
|
|
||||||
pw_log_warn(NAME" %p: error stat '%s': %m", conf, path);
|
|
||||||
} else if ((data = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) {
|
|
||||||
pw_log_warn(NAME" %p: error mmap '%s': %m", conf, path);
|
|
||||||
data = NULL;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (data != NULL) {
|
|
||||||
count += pw_properties_update_string(conf, data, sbuf.st_size);
|
|
||||||
munmap(data, sbuf.st_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (count == 0)
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
if ((fd = open(path, O_CLOEXEC | O_RDONLY)) < 0) {
|
||||||
|
pw_log_warn(NAME" %p: error loading config '%s': %m", conf, path);
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
pw_log_info(NAME" %p: loading config '%s'", conf, path);
|
||||||
|
if (fstat(fd, &sbuf) < 0)
|
||||||
|
goto error_close;
|
||||||
|
if ((data = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
|
||||||
|
goto error_close;
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
pw_properties_update_string(conf, data, sbuf.st_size);
|
||||||
|
munmap(data, sbuf.st_size);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
error_close:
|
||||||
|
close(fd);
|
||||||
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int pw_conf_load_conf(const char *prefix, const char *name, struct pw_properties *conf)
|
int pw_conf_load_conf(const char *prefix, const char *name, struct pw_properties *conf)
|
||||||
{
|
{
|
||||||
return conf_load(prefix, name, false, conf);
|
return conf_load(prefix, name, conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int pw_conf_load_state(const char *prefix, const char *name, struct pw_properties *conf)
|
int pw_conf_load_state(const char *prefix, const char *name, struct pw_properties *conf)
|
||||||
{
|
{
|
||||||
return conf_load(prefix, name, true, conf);
|
return conf_load(prefix, name, conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* context.spa-libs = {
|
/* context.spa-libs = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue