#1 xonsh login shell problems on X session
Closed 4 years ago by tofik. Opened 4 years ago by tofik.
Unknown source master  into  master

Fixed almalgam patch
Jerzy Drozdz • 4 years ago  
Patches changing exec and -l switch
Jerzy Drozdz • 4 years ago  
file added
+3
@@ -0,0 +1,3 @@

+ [Seat:*]

+ session-wrapper=/usr/sbin/xonsh-session

+ 

@@ -0,0 +1,100 @@

+ diff --git a/xonsh/aliases.py b/xonsh/aliases.py

+ index 47502f17..7af245ef 100644

+ --- a/xonsh/aliases.py

+ +++ b/xonsh/aliases.py

+ @@ -609,7 +609,7 @@ def source_cmd(args, stdin=None):

+  

+  

+  def xexec(args, stdin=None):

+ -    """exec [-h|--help] command [args...]

+ +    """exec [-h|--help] [-cl] [-a name] command [args...]

+  

+      exec (also aliased as xexec) uses the os.execvpe() function to

+      replace the xonsh process with the specified program. This provides

+ @@ -619,6 +619,13 @@ def xexec(args, stdin=None):

+          bash $

+  

+      The '-h' and '--help' options print this message and exit.

+ +    If the '-l' option is supplied, the shell places a dash at the

+ +    beginning of the zeroth argument passed to command to simulate login

+ +    shell.

+ +    The '-c' option causes command to be executed with an empty environment.

+ +    If '-a' is supplied, the shell passes name as the zeroth argument

+ +    to the executed command.

+ +

+  

+      Notes

+      -----

+ @@ -632,18 +639,39 @@ def xexec(args, stdin=None):

+      """

+      if len(args) == 0:

+          return (None, "xonsh: exec: no args specified\n", 1)

+ -    elif args[0] == "-h" or args[0] == "--help":

+ +

+ +    parser = argparse.ArgumentParser(add_help=False)

+ +    parser.add_argument('-h', '--help', action='store_true')

+ +    parser.add_argument('-l', dest='login', action='store_true')

+ +    parser.add_argument('-c', dest='clean', action='store_true')

+ +    parser.add_argument('-a', dest='name', nargs='?')

+ +    parser.add_argument('command', nargs=argparse.REMAINDER)

+ +    args = parser.parse_args(args)

+ +

+ +    if args.help:

+          return inspect.getdoc(xexec)

+ -    else:

+ +

+ +    if len(args.command) == 0:

+ +        return (None, "xonsh: exec: no command specified\n", 1)

+ +

+ +    command = args.command[0]

+ +    if args.name is not None:

+ +        args.command.insert(0, args.name)

+ +    if args.login:

+ +        args.command[0] = '-{}'.format(args.command[0])

+ +

+ +    denv = {}

+ +    if not args.clean:

+          denv = builtins.__xonsh__.env.detype()

+ -        try:

+ -            os.execvpe(args[0], args, denv)

+ -        except FileNotFoundError as e:

+ -            return (

+ -                None,

+ -                "xonsh: exec: file not found: {}: {}" "\n".format(e.args[1], args[0]),

+ -                1,

+ -            )

+ +

+ +    try:

+ +        os.execvpe(command, args.command, denv)

+ +    except FileNotFoundError as e:

+ +        return (

+ +            None,

+ +            "xonsh: exec: file not found: {}: {}" "\n".format(e.args[1], args[0]),

+ +            1,

+ +        )

+  

+  

+  class AWitchAWitch(argparse.Action):

+ diff --git a/xonsh/main.py b/xonsh/main.py

+ index 45ab31a9..8c05ab93 100644

+ --- a/xonsh/main.py

+ +++ b/xonsh/main.py

+ @@ -292,7 +292,7 @@ def start_services(shell_kwargs, args):

+      env = builtins.__xonsh__.env

+      rc = shell_kwargs.get("rc", None)

+      rc = env.get("XONSHRC") if rc is None else rc

+ -    if args.mode != XonshMode.interactive and not args.force_interactive:

+ +    if args.mode != XonshMode.interactive and not args.force_interactive and not args.login:

+          #  Don't load xonshrc if not interactive shell

+          rc = None

+      events.on_pre_rc.fire()

+ @@ -329,7 +329,8 @@ def premain(argv=None):

+          "cacheall": args.cacheall,

+          "ctx": builtins.__xonsh__.ctx,

+      }

+ -    if args.login:

+ +    if args.login or sys.argv[0].startswith('-'):

+ +        args.login = True

+          shell_kwargs["login"] = True

+      if args.norc:

+          shell_kwargs["rc"] = ()

@@ -0,0 +1,95 @@

+ diff -Naur xonsh-0.9.13_orig/xonsh/__amalgam__.py xonsh-0.9.13/xonsh/__amalgam__.py

+ --- xonsh-0.9.13_orig/xonsh/__amalgam__.py	2020-01-15 18:34:16.891000000 +0100

+ +++ xonsh-0.9.13/xonsh/__amalgam__.py	2020-01-15 18:36:21.998000000 +0100

+ @@ -21251,7 +21251,7 @@

+  

+  

+  def xexec(args, stdin=None):

+ -    """exec [-h|--help] command [args...]

+ +    """exec [-h|--help] [-cl] [-a name] command [args...]

+  

+      exec (also aliased as xexec) uses the os.execvpe() function to

+      replace the xonsh process with the specified program. This provides

+ @@ -21261,6 +21261,13 @@

+          bash $

+  

+      The '-h' and '--help' options print this message and exit.

+ +    If the '-l' option is supplied, the shell places a dash at the

+ +    beginning of the zeroth argument passed to command to simulate login

+ +    shell.

+ +    The '-c' option causes command to be executed with an empty environment.

+ +    If '-a' is supplied, the shell passes name as the zeroth argument

+ +    to the executed command.

+ +

+  

+      Notes

+      -----

+ @@ -21274,18 +21281,39 @@

+      """

+      if len(args) == 0:

+          return (None, "xonsh: exec: no args specified\n", 1)

+ -    elif args[0] == "-h" or args[0] == "--help":

+ +

+ +    parser = argparse.ArgumentParser(add_help=False)

+ +    parser.add_argument('-h', '--help', action='store_true')

+ +    parser.add_argument('-l', dest='login', action='store_true')

+ +    parser.add_argument('-c', dest='clean', action='store_true')

+ +    parser.add_argument('-a', dest='name', nargs='?')

+ +    parser.add_argument('command', nargs=argparse.REMAINDER)

+ +    args = parser.parse_args(args)

+ +

+ +    if args.help:

+          return inspect.getdoc(xexec)

+ -    else:

+ +

+ +    if len(args.command) == 0:

+ +        return (None, "xonsh: exec: no command specified\n", 1)

+ +

+ +    command = args.command[0]

+ +    if args.name is not None:

+ +        args.command.insert(0, args.name)

+ +    if args.login:

+ +        args.command[0] = '-{}'.format(args.command[0])

+ +

+ +    denv = {}

+ +    if not args.clean:

+          denv = builtins.__xonsh__.env.detype()

+ -        try:

+ -            os.execvpe(args[0], args, denv)

+ -        except FileNotFoundError as e:

+ -            return (

+ -                None,

+ -                "xonsh: exec: file not found: {}: {}" "\n".format(e.args[1], args[0]),

+ -                1,

+ -            )

+ +

+ +    try:

+ +        os.execvpe(command, args.command, denv)

+ +    except FileNotFoundError as e:

+ +        return (

+ +            None,

+ +            "xonsh: exec: file not found: {}: {}" "\n".format(e.args[1], args[0]),

+ +            1,

+ +        )

+  

+  

+  class AWitchAWitch(argparse.Action):

+ @@ -23908,7 +23936,7 @@

+      env = builtins.__xonsh__.env

+      rc = shell_kwargs.get("rc", None)

+      rc = env.get("XONSHRC") if rc is None else rc

+ -    if args.mode != XonshMode.interactive and not args.force_interactive:

+ +    if args.mode != XonshMode.interactive and not args.force_interactive and not args.login:

+          #  Don't load xonshrc if not interactive shell

+          rc = None

+      events.on_pre_rc.fire()

+ @@ -23945,7 +23973,8 @@

+          "cacheall": args.cacheall,

+          "ctx": builtins.__xonsh__.ctx,

+      }

+ -    if args.login:

+ +    if args.login or sys.argv[0].startswith('-'):

+ +        args.login = True

+          shell_kwargs["login"] = True

+      if args.norc:

+          shell_kwargs["rc"] = ()

file added
+43
@@ -0,0 +1,43 @@

+ #!/usr/bin/bash

+ #

+ #   Xsession script for users which use xnosh as login shell

+ #

+ #   Copyright (c) 2020 Jerzy Drozdz (t0fik)

+ #

+ #   This program is free software: you can redistribute it and/or modify

+ #   it under the terms of the GNU General Public License as published by

+ #   the Free Software Foundation, either version 3 of the License.

+ #

+ #   This program is distributed in the hope that it will be useful,

+ #   but WITHOUT ANY WARRANTY; without even the implied warranty of

+ #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

+ #   GNU General Public License for more details.

+ #

+ #   You should have received a copy of the GNU General Public License

+ #   along with this program. If not, see <http://www.gnu.org/licenses/>.

+ #

+ 

+ 

+ if [[ $1 == "/usr/bin/startdde" ]];then

+     exec /etc/sbin/deepin-session $@

+ elif [[ $SHELL != */bin/xonsh ]];then

+     exec /etc/X11/xinit/Xsession $@

+ fi

+ 

+ . /etc/X11/xinit/xinitrc-common

+ 

+ # Load Xsession scripts

+ xsessionddir="/etc/X11/Xsession.d"

+ if [ -d "$xsessionddir" ]; then

+     for i in `ls $xsessionddir`; do

+         script="$xsessionddir/$i"

+         echo "Loading X session script $script"

+         if [ -r "$script"  -a -f "$script" ] && expr "$i" : '^[[:alnum:]_-]\+$' > /dev/null; then

+             . "$script"

+         fi

+     done

+ fi

+ 

+ dde=$(which $1)

+ exec $SSH_AGENT /bin/sh -c "exec $SHELL -l -c 'exec $dde'"

+ 

file modified
+19 -2
@@ -1,6 +1,6 @@

  Name:           xonsh

  Version:        0.9.13

- Release:        1%{?dist}

+ Release:        2%{?dist}

  Summary:        A general purpose, Python-ish shell

  

  # xonsh is BSD-2-Clause.
@@ -8,6 +8,11 @@

  License:        BSD and MIT

  URL:            https://xon.sh

  Source0:        %pypi_source

+ Source1:	65-xonsh.conf

+ Source2:	xonsh-session

+ Patch0:         xonsh-0.9.13-exec-well-behaviour.patch

+ Patch1:         xonsh-0.9.13-update-amalgam.patch

+ 

  BuildArch:      noarch

  

  BuildRequires:  python%{python3_pkgversion}-devel
@@ -33,7 +38,7 @@

  and novices alike.

  

  %prep

- %autosetup -n %{name}-%{version}

+ %autosetup -p1 -n %{name}-%{version}

  

  %build

  # Remove shebang.
@@ -49,6 +54,11 @@

  pathfix.py -i "%{__python3} %{py3_shbang_opts}u" -p -n %{buildroot}%{_bindir}/xonsh

  pathfix.py -i "%{__python3} %{py3_shbang_opts}u" -p -n %{buildroot}%{_bindir}/xonsh-cat

  

+ install -d %{buildroot}%{_sbindir}

+ install -d %{buildroot}%{_datadir}/lightdm/lightdm.conf.d

+ install -pm 0755 %{SOURCE2} %{buildroot}%{_sbindir}/

+ install -pm 0644 %{SOURCE1} %{buildroot}%{_datadir}/lightdm/lightdm.conf.d/

+ 

  %check

  # The tests only succeed if:

  #
@@ -92,8 +102,15 @@

  %{python3_sitelib}/xonsh/

  %{python3_sitelib}/xontrib/

  %{python3_sitelib}/xonsh-%{version}*-py?.?.egg-info/

+ %{_datadir}/lightdm/lightdm.conf.d/65-xonsh.conf

+ %{_sbindir}/xonsh-session

  

  %changelog

+ * Sun Jan 12 2020 Jerzy Drozdz <jerzy.drozdz@jdsieci.pl> - 0.9.13-2

+ - Added X session wrapper script and config for lightdm

+ - '-l' switch allows loading rc files in non-interactive shell

+ - exec implements all switches from bash/zsh

+ 

  * Fri Nov 22 2019 Carmen Bianca Bakker <carmenbianca@fedoraproject.org> - 0.9.13-1

  - New upstream version.

  - Python 3.8 should no longer crash.

If user have xonsh set as login shell following problems are solved:
- Logout from X session is not possible due to '-c' not using execvpe syscall
- Environment variables not set on staring X session

Hello! Is there a bug report for this? Will these changes find their way back to upstream?

I'm struggling a little bit with figuring out what this patch does, but admittedly I haven't properly sat down and thoroughly combed through the code yet.

@carmenbianca
I do not think that there is bug report.
I noticed mentioned problems, when I decided to switch my login shell to xonsh.
I'm preparing the pull request for upstream.

xonsh-0.9.13-exec-well-behaviour.patch:
- implements exec behaviour compatible with bash/zsh exec
- xonsh did not loads environment for non-interactive shell, even if -l switch was available,
patch fixes that

xonsh-0.9.13-update-amalgam.patch: do same as above, needed because python3-amalgam not available and update of amalgam.py is not possible during building rpm

Thank you! Let me know how it goes upstream.

2 new commits added

  • Patches changing exec and -l switch
  • Added X session wrapper and lightdm config
4 years ago

1 new commit added

  • Fixed almalgam patch
4 years ago

Pull-Request has been closed by tofik

4 years ago