-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,26 +8,29 @@ APDU_DEBUG="$(uci_get lpac global apdu_debug 0)" | |
HTTP_BACKEND="$(uci_get lpac global http_backend curl)" | ||
HTTP_DEBUG="$(uci_get lpac global http_debug 0)" | ||
|
||
export LPAC_HTTP="$HTTP_BACKEND" | ||
function export_if_not_in_env { | ||
eval "value=\${$1}" | ||
if [ -z "$value" ]; then | ||
export "$1=$2" | ||
fi | ||
} | ||
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, the function is overkill, see my approach which goes without: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't name it "a clean way", sorry. |
||
|
||
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" | ||
Comment on lines
+18
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not addressed. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
fi | ||
|
||
export LPAC_APDU="$APDU_BACKEND" | ||
export_if_not_in_env LPAC_APDU "$APDU_BACKEND" | ||
if [ "$APDU_DEBUG" -eq 1 ]; then | ||
export LIBEUICC_DEBUG_APDU="1" | ||
export_if_not_in_env LIBEUICC_DEBUG_APDU "1" | ||
fi | ||
|
||
if [ "$APDU_BACKEND" = "at" ]; then | ||
AT_DEVICE="$(uci_get lpac at device /dev/ttyUSB2)" | ||
AT_DEBUG="$(uci_get lpac at debug 0)" | ||
export AT_DEVICE="$AT_DEVICE" | ||
export AT_DEBUG="$AT_DEBUG" | ||
export_if_not_in_env AT_DEVICE "$(uci_get lpac at device /dev/ttyUSB2)" | ||
export_if_not_in_env AT_DEBUG "$(uci_get lpac at debug 0)" | ||
elif [ "$APDU_BACKEND" = "uqmi" ]; then | ||
UQMI_DEV="$(uci_get lpac uqmi device /dev/cdc-wdm0)" | ||
UQMI_DEBUG="$(uci_get lpac uqmi debug 0)" | ||
export LPAC_QMI_DEV="$UQMI_DEV" | ||
export LPAC_QMI_DEBUG="$UQMI_DEBUG" | ||
export_if_not_in_env LPAC_QMI_DEV "$(uci_get lpac uqmi device /dev/cdc-wdm0)" | ||
export_if_not_in_env LPAC_QMI_DEBUG "$(uci_get lpac uqmi debug 0)" | ||
fi | ||
|
||
/usr/lib/lpac "$@" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a mix of the real Lpac's env vars and your extra (unneeded) ones makes the script harder to read.