NetBSD Problem Report #54851

From www@netbsd.org  Fri Jan 10 22:10:42 2020
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 5E93B7A19B
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 10 Jan 2020 22:10:42 +0000 (UTC)
Message-Id: <20200110221041.916B37A1C8@mollari.NetBSD.org>
Date: Fri, 10 Jan 2020 22:10:41 +0000 (UTC)
From: coypu@sdf.org
Reply-To: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Subject: .profile is not read by sh when using xdm or other login managers
X-Send-Pr-Version: www-1.0

>Number:         54851
>Category:       xsrc
>Synopsis:       .profile is not read by sh when using xdm or other login managers
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    xsrc-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 10 22:15:00 +0000 2020
>Last-Modified:  Sat Jan 11 21:15:01 +0000 2020
>Originator:     coypu
>Release:        netbsd 9.0 rc1
>Organization:
>Environment:
>Description:
Result: ifconfig and ping not in PATH, no tab completion...
>How-To-Repeat:

>Fix:

>Audit-Trail:
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: xsrc/54851: .profile is not read by sh when using xdm or other login managers
Date: Sat, 11 Jan 2020 09:02:06 +0700

     Date:        Fri, 10 Jan 2020 22:15:00 +0000 (UTC)
     From:        coypu@sdf.org
     Message-ID:  <20200110221500.D64567A153@mollari.NetBSD.org>

   | Result: ifconfig and ping not in PATH, no tab completion...

 shells (all shells, not just /bin/sh) read .profile (or their equivalent)
 only when started as a login shell.

 Whatever starts the shell needs to make that happen, if the shell you're
 getting is in an xterm, then starting the xterm with the -ls option
 will cause it to start a login shell, rather than a normal one.

 I don't use xdm, but I believe it uses a .xsession file to decide what
 to start when you log in (or something like that), if you're starting
 xterms and want them to contain login shells, then add the -ls option
 to each xterm started.

 Alternatively, if all you care about is the PATH setting, then simply
 set PATH (and export it) in your .xsession.

 If you want command line editing, the best place to enable that is
 usually in your $ENV file, as that needs to be set for each shell
 started, login shell or not, just do it only for interactive shells:

 	case "$-" in
 	*i*)
 		set -V -o tabcomplete; # or whatever you want
 		;;
 	esac

 and export ENV (from either .profile, or .xsession, or both).

 There are many many different approaches to getting all this right,
 as what is "right" depends heavily upon the preferences of the user
 concerned.   No "one size fits all" is going to work for everyone,
 or for that matter, most likely more than a small subset of users.

 kre

From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: xsrc/54851: .profile is not read by sh when using xdm or other
 login managers
Date: Sat, 11 Jan 2020 07:13:38 +0000

 On Fri, Jan 10, 2020 at 10:15:00PM +0000, coypu@sdf.org wrote:
  > Result: ifconfig and ping not in PATH, no tab completion...

 This is a property of your .xsession file, or if you don't have one
 the default one.

 It looks like nowadays the default xsession file is
 	xrdb -load $HOME/.Xresources
 	exec xsm

 and I don't know enough about how xsm works to find its default
 config, but my guess would be that it isn't opening login shells and
 perhaps it should be.

 -- 
 David A. Holland
 dholland@netbsd.org

From: "John D. Baker" <jdbaker@consolidated.net>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: xsrc/54851: .profile is not read by sh when using xdm or other
 login managers
Date: Sat, 11 Jan 2020 07:43:52 -0600 (CST)

 As noted by others, only login shells read ".profile".

 When 'xdm' starts the session, it is just another fork/chown/exec sequence
 and "/bin/sh" interpreting the master Xsession script
 ("/etc/X11/xdm/Xsession") is not a login shell.  The same is true for any
 display manager program that starts its session script with "/bin/sh".

 Since the various penguin-OS flavors typically have "bash" and it has the
 "-l" option to force it to be a login shell, such installations typically
 use:

   #!/bin/bash -l

 at the top of their master Xsession script.  Since the process is run as
 the local user, it reads their ".profile" (".bash_profile) the same as a
 terminal login.

 Some twenty-odd years ago I figured this out after tracing the "chain of
 custody" of the xdm session process and crafted a "~/.xsession" script
 to handle the situation by explicitly sourcing my ".profile" at the start
 of the script.

 ----------
 #!/bin/sh
 #
 # .xsession -- user-specific GUI session initialization

 # This script is the next-to-last thing that runs in the process started
 # by the display manager.

 # As it functions as a login shell, the script should read the system
 # and user-specific startup files to set up the user's environment.
 # This is often dependent on the shell interpreter used.


 # If we were executed by 'xinit' or included by 'startx', arrange for
 # output/error logging just like Xsession would.
 hostname=$(hostname)
 hostname=${hostname%%.*}
 case $0 in
   *.xinitrc|*/startx)
     exec > ~/.xsession-errors.${hostname} 2>&1
     echo "Executed as:  "${0##*/}
     ;;
   *.xsession)
     # If we were executed as ".xsession", check which interpreter is in use.
     # If it is 'bash', assume we are a login shell already.
     # Otherwise, if it is not 'bash', source .profile to set environment.
     [ -z "$BASH_VERSION" ] && [ -s ~/.profile ] && . ~/.profile
     ;;
 esac
 [...]


 -- 
 |/"\ John D. Baker, KN5UKS               NetBSD     Darwin/MacOS X
 |\ / jdbaker[snail]consolidated[flyspeck]net  OpenBSD            FreeBSD
 | X  No HTML/proprietary data in email.   BSD just sits there and works!
 |/ \ GPGkeyID:  D703 4A7E 479F 63F8 D3F4  BD99 9572 8F23 E4AD 1645

From: Rhialto <rhialto@falu.nl>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: xsrc/54851: .profile is not read by sh when using xdm or other
 login managers
Date: Sat, 11 Jan 2020 22:11:21 +0100

 Having something special in .Xsession (or other session startup script)
 to make a login shell may not propagate properly to xterms you then
 start later (depending on how you set up various shell initialization
 files). Personally I think it makes sense that xterms are all login
 shells in their own right, just like grabbing the next ADM-3a next to
 you and logging in gives you a new login shell.

 My method to get this result is this in my .Xresources:

 xterm.vt100.LoginShell:		on

 -Olaf.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.