From a238a58186ed7f68676d8ef17285a962bd013361 Mon Sep 17 00:00:00 2001 From: Patrick Gaskin Date: Fri, 23 Apr 2021 02:25:58 -0400 Subject: [PATCH] cli-command: Replace config dir with toplevel for .include on win32 This makes the behaviour match pa_{open,find}_config_file by replacing PA_DEFAULT_CONFIG_DIR with the toplevel. This fixes the hardcoded paths for {default,system}.pa.d introduced in 45abd0b43c7901b375afcba6d9b0e1cca2f349a8 (!361). Part-of: --- src/pulsecore/cli-command.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c index 5dc2ac6b9..ae75064f0 100644 --- a/src/pulsecore/cli-command.c +++ b/src/pulsecore/cli-command.c @@ -2084,20 +2084,34 @@ int pa_cli_command_execute_line_stateful(pa_core *c, const char *s, pa_strbuf *b if (l == sizeof(META_INCLUDE)-1 && !strncmp(cs, META_INCLUDE, l)) { struct stat st; - const char *filename = cs+l+strspn(cs+l, whitespace); + const char *fn = cs+l+strspn(cs+l, whitespace); + + char *filename; +#ifdef OS_IS_WIN32 + if (strncmp(fn, PA_DEFAULT_CONFIG_DIR, strlen(PA_DEFAULT_CONFIG_DIR)) == 0) + filename = pa_sprintf_malloc("%s" PA_PATH_SEP "etc" PA_PATH_SEP "pulse" PA_PATH_SEP "%s", + pa_win32_get_toplevel(NULL), + fn + strlen(PA_DEFAULT_CONFIG_DIR)); + else +#endif + filename = pa_xstrdup(fn); if (stat(filename, &st) < 0) { pa_log_warn("stat('%s'): %s", filename, pa_cstrerror(errno)); - if (*fail) + if (*fail) { + pa_xfree(filename); return -1; + } } else { if (S_ISDIR(st.st_mode)) { DIR *d; if (!(d = opendir(filename))) { pa_log_warn("Failed to read '%s': %s", filename, pa_cstrerror(errno)); - if (*fail) + if (*fail) { + pa_xfree(filename); return -1; + } } else { unsigned i, count; char **sorted_files; @@ -2143,14 +2157,18 @@ int pa_cli_command_execute_line_stateful(pa_core *c, const char *s, pa_strbuf *b pa_xfree(sorted_files[i]); } pa_xfree(sorted_files); - if (failed) + if (failed) { + pa_xfree(filename); return -1; + } } } } else if (pa_cli_command_execute_file(c, filename, buf, fail) < 0 && *fail) { + pa_xfree(filename); return -1; } } + pa_xfree(filename); } else if (l == sizeof(META_IFEXISTS)-1 && !strncmp(cs, META_IFEXISTS, l)) { if (!ifstate) { pa_strbuf_printf(buf, "Meta command %s is not valid in this context\n", cs);