1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-11 13:51:02 -05:00

Merge pull request #1157 from absolutelynothelix/fix-segfaults-when-homeless

This commit is contained in:
Yuxuan Shui 2023-12-22 10:59:55 +00:00 committed by GitHub
commit 496452cfce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View file

@ -596,15 +596,17 @@ char *locate_auxiliary_file(const char *scope, const char *path, const char *inc
// Fall back to searching in user config directory // Fall back to searching in user config directory
scoped_charp picom_scope = mstrjoin("/picom/", scope); scoped_charp picom_scope = mstrjoin("/picom/", scope);
scoped_charp config_home = (char *)xdg_config_home(); scoped_charp config_home = (char *)xdg_config_home();
if (config_home) {
char *ret = locate_auxiliary_file_at(config_home, picom_scope, path); char *ret = locate_auxiliary_file_at(config_home, picom_scope, path);
if (ret) { if (ret) {
return ret; return ret;
} }
}
// Fall back to searching in system config directory // Fall back to searching in system config directory
auto config_dirs = xdg_config_dirs(); auto config_dirs = xdg_config_dirs();
for (int i = 0; config_dirs[i]; i++) { for (int i = 0; config_dirs[i]; i++) {
ret = locate_auxiliary_file_at(config_dirs[i], picom_scope, path); char *ret = locate_auxiliary_file_at(config_dirs[i], picom_scope, path);
if (ret) { if (ret) {
free(config_dirs); free(config_dirs);
return ret; return ret;
@ -612,7 +614,7 @@ char *locate_auxiliary_file(const char *scope, const char *path, const char *inc
} }
free(config_dirs); free(config_dirs);
return ret; return NULL;
} }
/** /**

View file

@ -81,17 +81,19 @@ FILE *open_config_file(const char *cpath, char **ppath) {
// First search for config file in user config directory // First search for config file in user config directory
auto config_home = xdg_config_home(); auto config_home = xdg_config_home();
if (config_home) {
auto ret = open_config_file_at(config_home, ppath); auto ret = open_config_file_at(config_home, ppath);
free((void *)config_home); free((void *)config_home);
if (ret) { if (ret) {
return ret; return ret;
} }
}
// Fall back to legacy config file in user home directory // Fall back to legacy config file in user home directory
const char *home = getenv("HOME"); const char *home = getenv("HOME");
if (home && strlen(home)) { if (home && strlen(home)) {
auto path = mstrjoin(home, config_filename_legacy); auto path = mstrjoin(home, config_filename_legacy);
ret = fopen(path, "r"); auto ret = fopen(path, "r");
if (ret && ppath) { if (ret && ppath) {
*ppath = path; *ppath = path;
} else { } else {
@ -105,7 +107,7 @@ FILE *open_config_file(const char *cpath, char **ppath) {
// Fall back to config file in system config directory // Fall back to config file in system config directory
auto config_dirs = xdg_config_dirs(); auto config_dirs = xdg_config_dirs();
for (int i = 0; config_dirs[i]; i++) { for (int i = 0; config_dirs[i]; i++) {
ret = open_config_file_at(config_dirs[i], ppath); auto ret = open_config_file_at(config_dirs[i], ppath);
if (ret) { if (ret) {
free(config_dirs); free(config_dirs);
return ret; return ret;