conf: ignore the prefix if the config file name is an absolute path

Fixes:
$ export PIPEWIRE_CONFIG_PREFIX=/usr/share/pipewire
$ pipewire -c /etc/pipewire/bar.conf
[W][11925.530591][          conf.c:  253 conf_load()] config 0x560039ac6510: error loading config '/usr/share/pipewire//etc/pipewire/pipewire.conf': No such file or directory
[W][11925.530721][       context.c:  178 try_load_conf()] context 0x560039ac6190: can't load config /usr/share/pipewire//etc/pipewire/pipewire.conf: No such file or directory
This commit is contained in:
Peter Hutterer 2021-07-06 11:04:44 +10:00 committed by Wim Taymans
parent b1ac776ff0
commit fb2d35895e
4 changed files with 102 additions and 8 deletions

View file

@ -69,13 +69,27 @@ static int get_read_path(char *path, size_t size, const char *prefix, const char
const char *dir;
char buffer[4096];
if (prefix[0] == '/') {
if (name[0] == '/') {
const char *paths[] = { name, NULL };
if (make_path(path, size, paths) == 0 &&
access(path, R_OK) == 0)
return 1;
return -ENOENT;
}
if (prefix && prefix[0] == '/') {
const char *paths[] = { prefix, name, NULL };
if (make_path(path, size, paths) == 0 &&
access(path, R_OK) == 0)
return 1;
return -ENOENT;
}
if (prefix == NULL) {
prefix = name;
name = NULL;
}
if (pw_check_option("no-config", "true"))
goto no_config;
@ -240,11 +254,6 @@ static int conf_load(const char *prefix, const char *name, struct pw_properties
struct stat sbuf;
int fd;
if (prefix == NULL) {
prefix = name;
name = NULL;
}
if (get_read_path(path, sizeof(path), prefix, name) == 0) {
pw_log_debug(NAME" %p: can't load config '%s': %m", conf, path);
return -ENOENT;

View file

@ -175,10 +175,11 @@ static int try_load_conf(struct pw_context *this, const char *conf_prefix,
if (spa_streq(conf_name, "null"))
return 0;
if ((res = pw_conf_load_conf(conf_prefix, conf_name, conf)) < 0) {
bool skip_prefix = conf_prefix == NULL || conf_name[0] == '/';
pw_log_warn(NAME" %p: can't load config %s%s%s: %s",
this,
conf_prefix ? conf_prefix : "",
conf_prefix ? "/" : "",
skip_prefix ? "" : conf_prefix,
skip_prefix ? "" : "/",
conf_name, spa_strerror(res));
}
return res;