An example tells more than 1000 words: morgoth /usr/src/linux # genkernel --kernel-config=~/kernel all Funtoo Linux Genkernel; Version 3.4.18-funtoo Running with options: --kernel-config=~/kernel all Linux Kernel 2.6.32-042stab049.6 for x86_64... kernel: Using config from Previous config backed up to .config--2012-03-31--13-30-17.bak kernel: >> Running mrproper... cp: cannot stat ‘’: No such file or directory ERROR: Could not copy configuration file! -- Grepping log... -- CLEAN include/config CLEAN .config .config.old include/asm .version include/linux/autoconf.h include/linux/version.h include/linux/utsrelease.h include/linux/bounds.h include/asm/asm-offsets.h include/asm-x86/asm-offsets.h Funtoo Linux Genkernel; Version 3.4.18-funtoo Running with options: --kernel-config=~/kernel all ERROR: Could not copy configuration file! -- End log... -- Please consult /var/log/genkernel.log for more information and any errors that were reported above. Report any genkernel bugs to bugs.gentoo.org and assign your bug to genkernel@gentoo.org. Please include as much information as you can in your bug report; attaching /var/log/genkernel.log so that your issue can be dealt with effectively. * Please do not report compilation failures as genkernel bugs! * morgoth /usr/src/linux # As you can see in this, I specified that genkernel should use a kernel config from ~/kernel . genkernel can't find this. You have to give it a relative or absolute path, then it's working, like in /root/kernel or ../../root/kernel . Reproducible: Always Steps to Reproduce: Copy a kernel configfile to your home (e.g. ~/kernel) and issue 'genkernel --kernel-config=~/kernel all'. Actual Results: genkernel doesn't find the file, since it doesn't resolve '~' correctly. Expected Results: Since '~' is a valid syntax in Linux , it should be recognized.
... 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(+)