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

Redesign login shell use in session scripts #1779

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Vogtinator
Copy link
Contributor

@Vogtinator Vogtinator commented Aug 4, 2023

See #1768 (comment)

New approach, which does not suffer from the xprofile behaviour change:

Avoid the re-import of variables into sh by using the user's login shell
to invoke the session.

For the wayland-session script it's straightforward: Just exec the session
command directly within the login shell.

For the Xsession script it's a bit more complex: The login shell environment
has to be loaded first, then the xprofile files, so that they can overwrite
the login shell environment. To achieve this, the script runs in two stages:
The first uses the login shell to exec the second stage, which then reads
xprofile and execs the session.

Draft because only tested outside of a system installation so far.

@Vogtinator
Copy link
Contributor Author

Draft because it's late here and so I didn't test it, but wanted to get it published anyway to show the idea.

Works as expected. Tested with bash, fish, csh and zsh.

bash: /etc/profile is sourced.

fish: /etc/profile is sourced, fish.config is also read.

csh: .cshrc is read, but not /etc/profile (same as before)

zsh: /etc/profile is sourced, .zprofile is also read.

@arrowd
Copy link
Contributor

arrowd commented Aug 9, 2023

If I understand it right, the environment from /etc/profile now overrides the environment set in ~/.xsession? Would that be a POLA violation?

@Vogtinator
Copy link
Contributor Author

If I understand it right, the environment from /etc/profile now overrides the environment set in ~/.xsession? Would that be a POLA violation?

I think so.

Might be possible to just source it unconditionally at the top and assume it won't be sourced again by sh compatible shells through some mechanism like $PROFILEREAD.

@arrowd
Copy link
Contributor

arrowd commented Aug 9, 2023

We don't seem to have PROFILEREAD anywhere on FreeBSD. Is this some sort of well-known env var?

@Vogtinator
Copy link
Contributor Author

We don't seem to have PROFILEREAD anywhere on FreeBSD. Is this some sort of well-known env var?

I don't know. The /etc/profile I have here does

#
# Avoid overwriting user settings if called twice
#
if test -z "$PROFILEREAD" ; then
    readonly PROFILEREAD=true
    export PROFILEREAD
fi

and surrounds most code with test -z "$PROFILEREAD

@arrowd
Copy link
Contributor

arrowd commented Aug 9, 2023

Might be possible to just source it unconditionally at the top and assume it won't be sourced again by sh compatible shells

This won't work on FreeBSD, unfortunately.

I'm confused, why do we try to pull env from bash/fish/zsh at all if now we call $SHELL $@ instead of exec $@?

@CoelacanthusHex
Copy link
Contributor

Draft because it's late here and so I didn't test it, but wanted to get it published anyway to show the idea.

Works as expected. Tested with bash, fish, csh and zsh.

bash: /etc/profile is sourced.

fish: /etc/profile is sourced, fish.config is also read.

csh: .cshrc is read, but not /etc/profile (same as before)

zsh: /etc/profile is sourced, .zprofile is also read.

As zsh doc said, if zsh is invoked with 'zsh', it will not source /etc/profile but /etc/zprofile. Some distro land a /etc/zprofile with emulate sh -c 'source /etc/profile'.
If zsh is invoked with 'sh', it will has same behavior as 'sh'.

@Vogtinator
Copy link
Contributor Author

As zsh doc said, if zsh is invoked with 'zsh', it will not source /etc/profile but /etc/zprofile. Some distro land a /etc/zprofile with emulate sh -c 'source /etc/profile'. If zsh is invoked with 'sh', it will has same behavior as 'sh'.

That means, if we source /etc/profile explicitly and the distro also sources it from /etc/zprofile, it ends up getting sourced twice (which may or may not be an issue). If we don't (like now), /etc/profile might not get sourced at all.

@HerrNaN
Copy link

HerrNaN commented Dec 10, 2023

Tried to incorporate this in my Fedora Sericea build but to no avail, then I saw that the Fedora tests are not passing. Is there any work planned to get this working and into the main branch?

@Vogtinator
Copy link
Contributor Author

Tried to incorporate this in my Fedora Sericea build but to no avail, then I saw that the Fedora tests are not passing. Is there any work planned to get this working and into the main branch?

The Fedora CI failures are for Fedora reasons, not SDDM reasons.

@HerrNaN
Copy link

HerrNaN commented Dec 10, 2023

Tried to incorporate this in my Fedora Sericea build but to no avail, then I saw that the Fedora tests are not passing. Is there any work planned to get this working and into the main branch?

The Fedora CI failures are for Fedora reasons, not SDDM reasons.

I see, I haven't been able to pin-point exactly what those are, do you know?

@Vogtinator
Copy link
Contributor Author

Vogtinator commented Dec 10, 2023

Tried to incorporate this in my Fedora Sericea build but to no avail, then I saw that the Fedora tests are not passing. Is there any work planned to get this working and into the main branch?

The Fedora CI failures are for Fedora reasons, not SDDM reasons.

I see, I haven't been able to pin-point exactly what those are, do you know?

On clang internal compiler errors, i.e. compiler bugs. The current failures on develop are new, the CI workflow needs to be adjusted after fedora switched sddm to Qt 6 (I assume).

@Vogtinator Vogtinator marked this pull request as draft January 26, 2024 20:09
@Vogtinator Vogtinator changed the title RFC: Use the user login shell to invoke the final session command only Redesign login shell use in session scripts Jan 26, 2024
@Vogtinator
Copy link
Contributor Author

I implemented a different approach which should work everywhere without noticable behaviour changes. Needs testing.

@arrowd
Copy link
Contributor

arrowd commented Jan 27, 2024

It looks good to me, but I didn't test it at the runtime.

@Vogtinator
Copy link
Contributor Author

Tested with fish and bash, works.

@Vogtinator Vogtinator marked this pull request as ready for review January 28, 2024 16:16
@Pogogo007
Copy link

Any activity? I had a bug that caused sddm to fail to load any session while using fish and this mr completly fixed the issue

@Vogtinator
Copy link
Contributor Author

It's ready for merge, just needs approval from a maintainer.

@bernhardreiter
Copy link

bernhardreiter commented Apr 8, 2024

It's ready for merge, just needs approval from a maintainer.

Meanwhile you could sync it with the base branch.

Thanks for having put work in towards a solution!

Avoid the re-import of variables into sh by using the user's login shell
to invoke the session.

For the wayland-session script it's straightforward: Just exec the session
command directly within the login shell.

For the Xsession script it's a bit more complex: The login shell environment
has to be loaded first, then the xprofile files, so that they can overwrite
the login shell environment. To achieve this, the script runs in two stages:
The first uses the login shell to exec the second stage, which then reads
xprofile and execs the session.
@jfroy
Copy link

jfroy commented May 11, 2024

For what it's worth, I was really puzzled why sddm failed to create sessions on my system until I found and tested this PR. It does indeed fix the problem if your shell is fish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants