Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 452736 - [PATCH] it would be nice if the start script took an optional command with arguments
Summary: [PATCH] it would be nice if the start script took an optional command with ar...
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: Prefix Support (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Gentoo Prefix
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-17 21:00 UTC by Ben Longbons
Modified: 2017-12-03 14:28 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
allow startprefix to take arguments (startprefix-wrapper.patch,900 bytes, patch)
2013-02-02 18:29 UTC, Ben Longbons
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Longbons 2013-01-17 21:00:07 UTC
Justification:
When Gentoo Prefix is not the user's main system, it may be useful to create wrapper scripts in ~/bin/.

Implementation:
# As far as I can tell, this is the simplest way to still execute login scripts.
# Unfortunately, bash seems to skip the logout script... 
# that's an unrelated bug though.

if [ $# -eq 0 ] 
then
    env -i HOME=$HOME TERM=$TERM USER=$USER SHELL=$SHELL $DOPROFILEREAD $SHELL -l
else
    env -i HOME=$HOME TERM=$TERM USER=$USER SHELL=$SHELL $DOPROFILEREAD $SHELL -l -c '"$@"' iminurshellstartingyourprogs "$@"
fi
Comment 1 Fabian Groffen gentoo-dev 2013-02-02 13:18:48 UTC
Would you like to prepare a patch?  I don't really like the idea myself, but if the patch is small and non-intrusive, I don't mind applying it.
Comment 2 Ben Longbons 2013-02-02 18:29:27 UTC
Created attachment 337694 [details, diff]
allow startprefix to take arguments

Okay, here goes.

It should be obvious that it does nothing different in the case of having no arguments.

I found a workaround for the bash bug - ~/.bash_logout *is* called when 'exit'ing explicitly, just not when falling off the end of the -c.

Disclaimer: not tested with shells other than bash. However, it will probably work.
Comment 3 Fabian Groffen gentoo-dev 2013-07-13 07:09:31 UTC
how about

 env -i HOME=$HOME TERM=$TERM USER=$USER SHELL=$SHELL $DOPROFILEREAD ${EPREFIX}/bin/bash -c "$1" -prefix-bash "$@"

instead?

(it doesn't indeed work with all other shells, and since you're just executing a command, why bother doing that with the user's shell)
Comment 4 Ben Longbons 2013-07-14 21:38:18 UTC
(In reply to Fabian Groffen from comment #3)
>  env -i HOME=$HOME TERM=$TERM USER=$USER SHELL=$SHELL $DOPROFILEREAD
> ${EPREFIX}/bin/bash -c "$1" -prefix-bash "$@"
That doesn't work at all. It just executes $1 without arguments, since the $@ is passed to the shell, but the shell doesn't pass them to $1.

You need to have "$@" somewhere within the -c argument, which itself is surrounded by ''. Also, to prevent unwanted whitespace splits in the child, you really can't split the command separately.

Of course, hard-coding shell=bash would otherwise work with my patch.
Comment 5 Fabian Groffen gentoo-dev 2017-12-03 14:28:13 UTC
I'm pretty sure you've found a workaround by now, sorry for not following up in a timely manner.