Skip to content

Use wordexp to resolve variables like $HOME in path like settings#1215

Merged
fwsmit merged 1 commit intodunst-project:masterfrom
zappolowski:use-wordexp-for-resolving-path-like-variables
Dec 31, 2023
Merged

Use wordexp to resolve variables like $HOME in path like settings#1215
fwsmit merged 1 commit intodunst-project:masterfrom
zappolowski:use-wordexp-for-resolving-path-like-variables

Conversation

@zappolowski
Copy link
Member

This fixes #1173 - in combination with #1210

This is a spin-off of #1210 to properly handle environment variables for defining path like variables.

Open questions:

  • Which flags to pass to wordexp?
    • 0 (like e.g. i3wm does) - allows for a maximum of flexibility. E.g. the output of a script could be used to set the variable (default_icon = $(some_random_command)), but this also allows for arbitrary code execution.
    • WRDE_NOCMD - prohibits expansion of commands, but allows for all variables - even undefined ones.
    • WRDE_NOCMD | WRDE_UNDEF - strictest way of expansion, which ignores undefined variables
  • Is LOG_W enough to inform user of failed expansion? Should this be more detailed wrt. kind of failure?

@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2023

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 62.50000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.16%. Comparing base (5ef093c) to head (b558997).
⚠️ Report is 397 commits behind head on master.

Files with missing lines Patch % Lines
src/utils.c 47.82% 12 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1215      +/-   ##
==========================================
- Coverage   66.19%   66.16%   -0.04%     
==========================================
  Files          46       46              
  Lines        7671     7698      +27     
==========================================
+ Hits         5078     5093      +15     
- Misses       2593     2605      +12     
Flag Coverage Δ
unittests 66.16% <62.50%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zappolowski zappolowski force-pushed the use-wordexp-for-resolving-path-like-variables branch from ece52ce to 3dd33d7 Compare October 23, 2023 15:17
@fwsmit
Copy link
Member

fwsmit commented Oct 24, 2023

Are there convincing use cases for needing command expansion? If not, then I would not include it. It can always be added later.

I think both not expanding undefined variables and expanding them are fine. Not expanding might make it easier for the user to spot errors.

It would be nice if the error message would be a bit more specific depending on the return value of wordexp. Maybe you can use some implementation somewhere that has this already (for example in i3). Keep in mind the license of course.

@zappolowski zappolowski force-pushed the use-wordexp-for-resolving-path-like-variables branch from 3dd33d7 to 8958394 Compare October 26, 2023 16:30
@zappolowski
Copy link
Member Author

zappolowski commented Oct 26, 2023

I agree that command substitution is not that important at the moment and adding some functionality later on is easier than removing it (and breaking configs).

It would be nice if the error message would be a bit more specific depending on the return value of wordexp.

I've expanded the warnings for each possible case. Please check, whether that suffices. I've also expanded the documentation where paths are expanded (basically, browser and dmenu also use paths, but I left them out as they most probably are absolute paths anyhow).

PS: I've checked the build failure and AFAICT wordexp on musl doesn't support WRDE_UNDEF. I could disable this test when it runs on musl (but this would also mean, that this feature doesn't work properly on musl-based distros ... Void comes to mind).

@zappolowski zappolowski force-pushed the use-wordexp-for-resolving-path-like-variables branch from 8958394 to 7ec7005 Compare October 26, 2023 18:25
@zappolowski
Copy link
Member Author

@fwsmit any further actions required?

@fwsmit
Copy link
Member

fwsmit commented Nov 9, 2023

I'll take a look once I have the time

@zappolowski zappolowski force-pushed the use-wordexp-for-resolving-path-like-variables branch from 7ec7005 to 3458da5 Compare November 9, 2023 18:20
It seems like the wordexp implementation in musl leaks memory and thus a
new suppression is required to pass CI. It also doesn't fully implement
all POSIX features and thus at least one test has to be deactivated in
that case.
@zappolowski zappolowski force-pushed the use-wordexp-for-resolving-path-like-variables branch from 3458da5 to b558997 Compare November 12, 2023 18:47
@fwsmit
Copy link
Member

fwsmit commented Dec 31, 2023

Thanks, the implementation and documentation look good. I'll go ahead and merge it.

@fwsmit fwsmit merged commit e9a27c0 into dunst-project:master Dec 31, 2023
@zappolowski zappolowski deleted the use-wordexp-for-resolving-path-like-variables branch January 2, 2024 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't set default_icon path with environment variable ($HOME or ~)

3 participants