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 45923198005 for ; Wed, 6 Mar 2013 17:03:29 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 940B3E0B65; Wed, 6 Mar 2013 17:03:24 +0000 (UTC) Received: from vms173003pub.verizon.net (vms173003pub.verizon.net [206.46.173.3]) by pigeon.gentoo.org (Postfix) with ESMTP id 244B5E0B4D for ; Wed, 6 Mar 2013 17:03:24 +0000 (UTC) Received: from odin.tremily.us ([unknown] [72.68.87.226]) by vms173003.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0MJ9004IL0P4M520@vms173003.mailsrvcs.net> for gentoo-catalyst@lists.gentoo.org; Wed, 06 Mar 2013 11:03:05 -0600 (CST) Received: by odin.tremily.us (Postfix, from userid 1000) id E27699068D1; Wed, 06 Mar 2013 12:03:03 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tremily.us; s=odin; t=1362589383; bh=xoE1wi3SW0kKiEx+8u9ASl7TuXuT0TzH2KdUqU9NMYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References; b=cvi2V0mzAeFJ5g4fwEfZ/DyRxrz59UsjxlE3+nYuRTcQeTmlRAhiTbMqFJW98Lqr8 eXclDpc0qWGWDRzH4NKhqZvlPyxQHA+lXnt6RkZdPJ1A4wKv6qEZ5LsvEdd+s+x4WF Stk5dUanaMub2QThHIIMo+jzirXgKYMKUqK0lxxw= From: "W. Trevor King" To: Catalyst Cc: "W. Trevor King" Subject: [gentoo-catalyst] [PATCH v2 2/2] livecdfs-update.sh: Use `bash --login` to spawn startx Date: Wed, 06 Mar 2013 12:02:59 -0500 Message-id: X-Mailer: git-send-email 1.7.12.4 In-reply-to: References: <6d3c93bde552943c26acbf6c1946dae23821860c.1362366795.git.wking@tremily.us> In-reply-to: References: Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-catalyst@lists.gentoo.org Reply-to: gentoo-catalyst@lists.gentoo.org X-Archives-Salt: e1426004-a091-4ff2-ab06-a2cf603eac36 X-Archives-Hash: 49225b70724880d38733a58296b0bfbd From: "W. Trevor King" 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 77d694e..0ac41dd 100644 --- a/targets/support/livecdfs-update.sh +++ b/targets/support/livecdfs-update.sh @@ -388,9 +388,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 ] -- 1.8.2.rc0.16.g20a599e