Summary: | genkernel 3.4.18 doesn't recognize paths containing ~ | ||
---|---|---|---|
Product: | Gentoo Hosted Projects | Reporter: | Marc Richter <richter_marc> |
Component: | genkernel | Assignee: | Gentoo Genkernel Maintainers <genkernel> |
Status: | RESOLVED FIXED | ||
Severity: | minor | ||
Priority: | Normal | ||
Version: | unspecified | ||
Hardware: | All | ||
OS: | Linux | ||
See Also: | https://bugs.gentoo.org/show_bug.cgi?id=698828 | ||
Whiteboard: | |||
Package list: | Runtime testing required: | --- |
Description
Marc Richter
2012-04-17 10:58:27 UTC
... come ooon: Really, >4 months to confirm a bug? Takes <5 minutes to follow the example :/ (In reply to comment #1) > ... come ooon: Really, >4 months to confirm a bug? Takes <5 minutes to > follow the example :/ Point taken, a reply would have been nice. It's not about confirming though, it's about the implementation. Ideally it would be complete and consistent, meaning that * it needs to be analyzed which parameters besides --kernel-config should support this feature * there are variants that we may want to support, too: * "~" --> "/home/sping" * "~root" --> "/root/" * "~missing" --> "~missing" * "~-" --> "${OLDPWD}" * "~*" --> "${PWD}" For now, that's why there is no fix, yet. (In reply to comment #2) > * "~*" --> "${PWD}" Pardon, that would be "~+". Re-making Bash's support 1:1 is going to be fun, if not done by Bash for us. # echo -- foo~ -- foo~ # echo -- foo=~ -- foo=/home/sping # echo -- -foo=~ -- -foo=~ Letting bash do the work like # val=~root/foo # val=$(bash -c "echo -- ${val}" | sed 's|^-- ||') # echo "${val}" /root/foo is dangerous since ${val} could be anything. Any ideas how to make it safe? Hi Sebastian, thank you for your answer! :) In my opinion, there are 2 possible solutions: Either implement Bash's usual behavior 1:1 with *any* possible shortcuts like you suggested (which would scale better if things are changed in the future) or only implement the called "bug" and only implement the plain "~/". Before nothing is happening, because the 1:1 behavior is discussed for years, perhaps the better (quicker) solution woulc be to implement the two widest spread syntaxes: "~/" and "~user/". There is a another problem. If you compare # echo ~ /home/sping with # sudo echo ~ /home/sping it becomes obvious that tilde expansion is done for the user that the shell belongs to, rather than user running genkernel. Now we could look at ${SUDO_USER} (or ${SUDO_UID}) to find what user was executing genkernel using sudo. This is what I built: =============================================================== # https://www.kernel.org/doc/man-pages/online/pages/man5/proc.5.html if [[ -z "${SUDO_USER}" ]]; then # Expand for same user as current process tilde_target=${HOME} else # Expand for user who executed sudo tilde_target=$(bash -c 'bash -c "echo ~${SUDO_USER}/"') fi expand_tilde() { # Bash does not expand "--config=~/foo", so we do (bug #412321) val=$1 case "${val}" in \~) val=${tilde_target} ;; \~/*) val=${tilde_target}${val:1} ;; esac echo "${val}" } =============================================================== While that should support invocation using sudo or a root shell it breaks when sudo is nested, see here: =============================================================== # sudo -u daemon env | fgrep SUDO_ # single sudo SUDO_COMMAND=/bin/env SUDO_USER=sping SUDO_UID=1000 SUDO_GID=1000 # sudo sudo -u daemon env | fgrep SUDO_ # nested sudo SUDO_COMMAND=/bin/env SUDO_USER=root SUDO_UID=0 SUDO_GID=0 =============================================================== So that would be dirty, incomplete, fragile and probably not supported by any app around. The bug has been closed via the following commit(s): https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=db881955a5d03740db2dd55f33ffeeda373bf611 commit db881955a5d03740db2dd55f33ffeeda373bf611 Author: Thomas Deutschmann <whissi@gentoo.org> AuthorDate: 2019-03-29 02:53:53 +0000 Commit: Thomas Deutschmann <whissi@gentoo.org> CommitDate: 2019-03-29 04:12:22 +0000 determine_config_file(): add support for file path (tilde) expansion In addition, we make --kernel-config parameter more exclusive: Before this change, if user had set --kernel-config but value was invalid (i.e. file didn't exist) we silently fallback to default configuration. Now we will error out if --kernel-config is set but value is invalid (i.e. no file). Closes: https://bugs.gentoo.org/412321 Signed-off-by: Thomas Deutschmann <whissi@gentoo.org> gen_configkernel.sh | 67 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 24 deletions(-) Additionally, it has been referenced in the following commit(s): https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=a42e9e779795d1a4eff1a48ba14e70f03a64b98e commit a42e9e779795d1a4eff1a48ba14e70f03a64b98e Author: Thomas Deutschmann <whissi@gentoo.org> AuthorDate: 2019-03-29 02:47:43 +0000 Commit: Thomas Deutschmann <whissi@gentoo.org> CommitDate: 2019-03-29 02:51:22 +0000 Add new function expand_file() to allow file path expansion Relies on Python os.path.expanduser and realpath from coreutils. Bug: https://bugs.gentoo.org/412321 Signed-off-by: Thomas Deutschmann <whissi@gentoo.org> gen_funcs.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) |