From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id DEFE9138247 for ; Thu, 21 Nov 2013 09:06:48 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id EBCD8E0A04; Thu, 21 Nov 2013 09:06:37 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 06356E0A04 for ; Thu, 21 Nov 2013 09:06:36 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D54C833F253 for ; Thu, 21 Nov 2013 09:06:35 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id B9C88E54CC for ; Thu, 21 Nov 2013 09:06:32 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1385024410.2d9697c7d872652a9146d4904cb63af53be62e70.dol-sen@gentoo> Subject: [gentoo-commits] proj/catalyst:3.0 commit in: targets/support/ X-VCS-Repository: proj/catalyst X-VCS-Files: targets/support/livecdfs-update.sh X-VCS-Directories: targets/support/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 2d9697c7d872652a9146d4904cb63af53be62e70 X-VCS-Branch: 3.0 Date: Thu, 21 Nov 2013 09:06:32 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 2df3c9e3-0894-499f-8873-d2da72106b03 X-Archives-Hash: 69d02a7d97dca3be638258b4ea86588e commit: 2d9697c7d872652a9146d4904cb63af53be62e70 Author: W. Trevor King tremily us> AuthorDate: Sun Mar 3 16:48:11 2013 +0000 Commit: Brian Dolbec gmail com> CommitDate: Thu Nov 21 09:00:10 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=2d9697c7 livecdfs-update.sh: Use `bash --login` to spawn startx Starting a "login" version of Bash via `su` is tricky. The naive: su - ${first_user} -c startx fails because `su - ...` clears a number of environment variables (so the prefixed `source /etc/profile` doesn't accomplish anything), but Bash isn't started with the `--login` option, so it doesn't source /etc/profile internally. From bash(1): A login shell is one whose first character of argument zero is a -, or one started with the --login option. ... An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)), or one started with the -i option... ... When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior. In order to get the login-style profile loading with a non-interactive `su` invocation, you need to use something like: echo "${command}" | su - "${user}" This starts a login shell and pipes the command in via stdin, which seems to fake Bash into thinking its running from an interactive terminal. Not the most elegant, but the other implementations I can think of are even worse: su - "${user}" -c "bash --login -c ${command}" su - "${user}" -c 'source /etc/profile && (source .bash_profile || ...) && ${command}" The old expression was broken anyway due to unescaped ampersands in the sed expression. From sed(1): s/regexp/replacement/ Attempt to match regexp against the pattern space. If successful, replace that portion matched with replacement. The replacement may contain the special character & to refer to that portion of the pattern space which matched, and the special escapes \1 through \9 to refer to the corresponding matching sub-expressions in the regexp. This means that the old expression (with unescaped ampersands) lead to: source /etc/profile ##STARTX##STARTX su - ${first_user} -c startx with ${first_user} expanded. This commented out startx, so it was never run. --- targets/support/livecdfs-update.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/targets/support/livecdfs-update.sh b/targets/support/livecdfs-update.sh index e9cdec1..dc4f71f 100755 --- a/targets/support/livecdfs-update.sh +++ b/targets/support/livecdfs-update.sh @@ -387,9 +387,7 @@ esac # We want the first user to be used when auto-starting X if [ -e /etc/startx ] then - sed -i \ - "s:##STARTX:source /etc/profile \&\& su - ${first_user} -c startx:" \ - /root/.bashrc + sed -i "s:##STARTX:echo startx | su - '${first_user}':" /root/.bashrc fi if [ -e /lib/rcscripts/addons/udev-start.sh ]