On Tue, 2017-10-31 at 11:46 +0800, Iceyer wrote: > --- > src/modules/module-augment-properties.c | 63 +++++++++++++++++++++------------ > 1 file changed, 40 insertions(+), 23 deletions(-) > > diff --git a/src/modules/module-augment-properties.c b/src/modules/module-augment-properties.c > index 541f0e79..56217d51 100644 > --- a/src/modules/module-augment-properties.c > +++ b/src/modules/module-augment-properties.c > @@ -144,37 +144,54 @@ static void update_rule(struct rule *r) { > { NULL, NULL, NULL, NULL }, > }; > bool found = false; > + const char *state = NULL; > + const char *xdg_data_dirs = NULL; > + char *data_dir = NULL; > + char *desktop_file_dir = NULL; > > pa_assert(r); > - fn = pa_sprintf_malloc(DESKTOPFILEDIR PA_PATH_SEP "%s.desktop", r->process_name); > > - if (stat(fn, &st) == 0) > - found = true; > - else { > + if ((xdg_data_dirs = getenv("XDG_DATA_DIRS"))) { The case where XDG_DATA_DIRS is not set needs to be handled too. Now you just give up entirely if XDG_DATA_DIRS is not set. > + while(data_dir = pa_split(xdg_data_dirs, ":", &state)) { Please use 4 spaces for indenting, and a space between "while" and "(". > + desktop_file_dir = pa_sprintf_malloc("%s" PA_PATH_SEP "applications", data_dir); > + fn = pa_sprintf_malloc("%s" PA_PATH_SEP "%s.desktop", desktop_file_dir, r->process_name); > + if (stat(fn, &st) == 0) { > + found = true; > + break; desktop_file_dir has to be freed. > + } else { > #ifdef DT_DIR > - DIR *desktopfiles_dir; > - struct dirent *dir; > - > - /* Let's try a more aggressive search, but only one level */ > - if ((desktopfiles_dir = opendir(DESKTOPFILEDIR))) { > - while ((dir = readdir(desktopfiles_dir))) { > - if (dir->d_type != DT_DIR > - || pa_streq(dir->d_name, ".") > - || pa_streq(dir->d_name, "..")) > - continue; > - > - pa_xfree(fn); > - fn = pa_sprintf_malloc(DESKTOPFILEDIR PA_PATH_SEP "%s" PA_PATH_SEP "%s.desktop", dir->d_name, r->process_name); > - > - if (stat(fn, &st) == 0) { > - found = true; > - break; > + DIR *desktopfiles_dir; > + struct dirent *dir; > + > + /* Let's try a more aggressive search, but only one level */ > + if ((desktopfiles_dir = opendir(desktop_file_dir))) { > + while ((dir = readdir(desktopfiles_dir))) { > + if (dir->d_type != DT_DIR > + || pa_streq(dir->d_name, ".") > + || pa_streq(dir->d_name, "..")) > + continue; > + > + pa_xfree(fn); > + fn = pa_sprintf_malloc("%s" PA_PATH_SEP "%s" PA_PATH_SEP "%s.desktop", desktop_file_dir, dir->d_name, r->process_name); > + > + if (stat(fn, &st) == 0) { > + found = true; > + break; > + } > } > + closedir(desktopfiles_dir); > + if (found) > + break; desktop_file_dir has to be freed. > } > - closedir(desktopfiles_dir); > - } > #endif > + } > + pa_xfree(desktop_file_dir); data_dir and fn have to be freed. -- Tanu https://www.patreon.com/tanuk