Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Codecov Report

Merging #1215 (b558997) into master (5ef093c) will decrease coverage by 0.04%.
The diff coverage is 62.50%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@            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.

Files Coverage Δ
test/option_parser.c 99.44% <100.00%> (+<0.01%) ⬆️
test/utils.c 100.00% <100.00%> (ø)
src/utils.c 85.24% <47.82%> (-4.14%) ⬇️

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@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
test/utils.c Outdated Show resolved Hide resolved
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
14 of 18 checks passed
@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