From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-catalyst+bounces-2646-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	by finch.gentoo.org (Postfix) with ESMTP id C573F198003
	for <garchives@archives.gentoo.org>; Sat,  9 Mar 2013 02:55:31 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 759A9E0675;
	Sat,  9 Mar 2013 02:55:30 +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 D03ADE0675
	for <gentoo-catalyst@lists.gentoo.org>; Sat,  9 Mar 2013 02:55:29 +0000 (UTC)
Received: from mail-qe0-f54.google.com (mail-qe0-f54.google.com [209.85.128.54])
	(using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits))
	(No client certificate requested)
	(Authenticated sender: mattst88)
	by smtp.gentoo.org (Postfix) with ESMTPSA id 893B933E144
	for <gentoo-catalyst@lists.gentoo.org>; Sat,  9 Mar 2013 02:55:28 +0000 (UTC)
Received: by mail-qe0-f54.google.com with SMTP id i11so1436943qej.27
        for <gentoo-catalyst@lists.gentoo.org>; Fri, 08 Mar 2013 18:55:27 -0800 (PST)
X-Received: by 10.49.127.199 with SMTP id ni7mr7527472qeb.17.1362797727117;
 Fri, 08 Mar 2013 18:55:27 -0800 (PST)
Precedence: bulk
List-Post: <mailto:gentoo-catalyst@lists.gentoo.org>
List-Help: <mailto:gentoo-catalyst+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-catalyst+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-catalyst+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-catalyst.gentoo.org>
X-BeenThere: gentoo-catalyst@lists.gentoo.org
Reply-to: gentoo-catalyst@lists.gentoo.org
MIME-Version: 1.0
Received: by 10.49.121.167 with HTTP; Fri, 8 Mar 2013 18:55:07 -0800 (PST)
In-Reply-To: <aef26be897370eda98515d666a012ba02b27117b.1362589155.git.wking@tremily.us>
References: <6d3c93bde552943c26acbf6c1946dae23821860c.1362366795.git.wking@tremily.us>
 <cover.1362589155.git.wking@tremily.us> <aef26be897370eda98515d666a012ba02b27117b.1362589155.git.wking@tremily.us>
From: Matt Turner <mattst88@gentoo.org>
Date: Fri, 8 Mar 2013 18:55:07 -0800
Message-ID: <CAEdQ38G6b4T86CKD+cigvMZyJ2fFrFnFdoz073P1RAmgx7q9aA@mail.gmail.com>
Subject: Re: [gentoo-catalyst] [PATCH v2 2/2] livecdfs-update.sh: Use `bash
 --login` to spawn startx
To: gentoo-catalyst@lists.gentoo.org
Cc: "W. Trevor King" <wking@tremily.us>
Content-Type: text/plain; charset=ISO-8859-1
X-Archives-Salt: 0ff3b5b3-c693-45b7-8c6f-03c1dd35b68e
X-Archives-Hash: 757f38ae4d43303e7698b5cf0bfd057f

On Wed, Mar 6, 2013 at 9:02 AM, W. Trevor King <wking@tremily.us> wrote:
> From: "W. Trevor King" <wking@tremily.us>
>
> 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
>
>

This doesn't apply after PATCH 1/2 in this series. Probably why the
first PATCH wasn't labeled as 1/2. Want to confirm what you want to do
here?