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

lpac: don't overwrite env variables #25258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

blocktrron
Copy link
Member

Maintainer: me
Compile tested: (put here arch, model, OpenWrt version)
Run tested: (put here arch, model, OpenWrt version, tests done)

Description:

Don't override env variables which are already set when execuring the wrapper script. This makes it possible to override the options set by UCI in the calling programm.

Don't override env variables which are already set when execuring the
wrapper script. This makes it possible to override the options set by
UCI in the calling programm.

Signed-off-by: David Bauer <mail@david-bauer.net>
Copy link
Contributor

@bam80 bam80 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#25046 doesn't have drawbacks mentioned

Comment on lines 8 to 9
HTTP_BACKEND="$(uci_get lpac global http_backend curl)"
HTTP_DEBUG="$(uci_get lpac global http_debug 0)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Extra variables
  • Default values are unneeded and shouldn't be used in the script here (because it's a code)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are default values not needed?

I don't go with "extra variables, they do not propagate outside the script.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separating code and data is a good practice.
Additionally, the default values are just not needed here.

Please pay attention to the alternative implementation which doesn't use the defaults in code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't go with "extra variables, they do not propagate outside the script.

Having a mix of the real Lpac's env vars and your extra (unneeded) ones makes the script harder to read.

Comment on lines +11 to +16
function export_if_not_in_env {
eval "value=\${$1}"
if [ -z "$value" ]; then
export "$1=$2"
fi
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the function is overkill, see my approach which goes without:
https://github.com/openwrt/packages/pull/25046/files

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It provides a clean way of achieving the common task of only overwriting set values from the outside script.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't name it "a clean way", sorry.

Comment on lines +18 to +20
export_if_not_in_env LPAC_HTTP "$HTTP_BACKEND"
if [ "$HTTP_DEBUG" -eq 1 ]; then
export LIBEUICC_DEBUG_HTTP="1"
export_if_not_in_env LIBEUICC_DEBUG_HTTP "1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#25046 (comment)

The problem with your handling of the debug options, as I see it, is that you have to interpret their values, which our scripts shouldn't do anyway.

Not addressed.
See the alternative approach above, again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you mean to not set the debug env variables if they are not enabled? This would suffice if we remove UCI handling from them, which i am fine with.

Copy link
Contributor

@bam80 bam80 Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, the UCI handling is in place, so we could (and should) rely on that instead of trying to be smart and interfere with lpac's envs interpretation in this script.

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.

2 participants