Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LXC bash completion can kill X session on initialization #521

Closed
lucaswerkmeister opened this issue May 13, 2015 · 1 comment
Closed

LXC bash completion can kill X session on initialization #521

lucaswerkmeister opened this issue May 13, 2015 · 1 comment

Comments

@lucaswerkmeister
Copy link
Contributor

@lucaswerkmeister lucaswerkmeister commented May 13, 2015

My .profile sources my .bashrc if the current shell is a Bash. .bashrc, in turn, sources Bash completions, including the LXC bash completions if installed. /etc/bash_completion.d/lxc (repository: config/bash/lxc.in looks basically like this:

have lxc-start && (
    #
    _lxc-generic-n() {
        #
    }
    #
    complete -o default -F _lxc-generic-n lxc-attach
    #
}

It seems that Xsession initialization, run by GDM, also runs within a Bash – but for some reason, that Bash rejects these identifiers. Log entry:

… /usr/lib/gdm/gdm-x-session[604]: /etc/bash_completion.d/lxc: line 103: `_lxc-generic-n': not a valid identifier

This causes Bash to exit, terminating the X session. In other words, with LXC bash completion installed, I cannot start a desktop session, except using Gnome on Wayland.

By defining test functions in .profile directly, I can determine that the problematic character is the hyphen – the underscore works fine.

The proper solution to this problem is probably to not source .bashrc from .profile, because it doesn’t belong there. On the other hand, this is (when it happens) such a serious problem that I suggest LXC should mitigate it as well, by renaming these functions to only use underscores.

@lucaswerkmeister

This comment has been minimized.

Copy link
Contributor Author

@lucaswerkmeister lucaswerkmeister commented May 13, 2015

/etc/gdm/Xsession has the shebang #!/bin/sh. On my system, /bin/sh is a symlink to bash. From the bash(1) manpage (bold emphasis mine):

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order. The --noprofile option may be used to inhibit this behavior. When invoked as an interactive shell with the name sh, bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. Since a shell invoked as sh does not attempt to read and execute commands from any other startup files, the --rcfile option has no effect. A non-interactive shell invoked with the name sh does not attempt to read any other startup files. When invoked as sh, bash enters posix mode after the startup files are read.

POSIX 3.231 NAME:

In the shell command language, a word consisting solely of underscores, digits, and alphabetics from the portable character set. The first character of a name is not a digit.

So, in POSIX mode, Bash rejects hyphens in (function and other) names.

stgraber added a commit that referenced this issue Jul 1, 2015
When running in posix mode (for example, because it was invoked as `sh`,
or with the --posix option), bash rejects the function names previously
used because they contain hyphens, which are not legal POSIX names, and
exits immediately.

This is a particularly serious problem on a system in which the
following three conditions hold:

1. The `sh` executable is provided by bash, e. g. via a symlink
2. Gnome Display Manager is used to launch X sessions
3. Bash completion is loaded in the (system or user) profile file
   instead of in the bashrc file

In that case, GDM's Xsession script (run with `sh`, i. e., bash in posix
mode) sources the profile files, thus causing the shell to load the bash
completion files. Upon encountering the non-POSIX-compliant function
names, bash would then exit, immediately ending the X session.

Fixes #521.

Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
stgraber added a commit that referenced this issue Aug 14, 2015
When running in posix mode (for example, because it was invoked as `sh`,
or with the --posix option), bash rejects the function names previously
used because they contain hyphens, which are not legal POSIX names, and
exits immediately.

This is a particularly serious problem on a system in which the
following three conditions hold:

1. The `sh` executable is provided by bash, e. g. via a symlink
2. Gnome Display Manager is used to launch X sessions
3. Bash completion is loaded in the (system or user) profile file
   instead of in the bashrc file

In that case, GDM's Xsession script (run with `sh`, i. e., bash in posix
mode) sources the profile files, thus causing the shell to load the bash
completion files. Upon encountering the non-POSIX-compliant function
names, bash would then exit, immediately ending the X session.

Fixes #521.

Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
z-image pushed a commit to z-image/lxc that referenced this issue Oct 16, 2016
When running in posix mode (for example, because it was invoked as `sh`,
or with the --posix option), bash rejects the function names previously
used because they contain hyphens, which are not legal POSIX names, and
exits immediately.

This is a particularly serious problem on a system in which the
following three conditions hold:

1. The `sh` executable is provided by bash, e. g. via a symlink
2. Gnome Display Manager is used to launch X sessions
3. Bash completion is loaded in the (system or user) profile file
   instead of in the bashrc file

In that case, GDM's Xsession script (run with `sh`, i. e., bash in posix
mode) sources the profile files, thus causing the shell to load the bash
completion files. Upon encountering the non-POSIX-compliant function
names, bash would then exit, immediately ending the X session.

Fixes lxc#521.

Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant
You can’t perform that action at this time.