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

Cannot start gnome wayland session with mutter/elogind #61

Closed
juanitotc opened this issue May 12, 2018 · 44 comments
Closed

Cannot start gnome wayland session with mutter/elogind #61

juanitotc opened this issue May 12, 2018 · 44 comments

Comments

@juanitotc
Copy link

I'm trying to get gnome-3.28 to work with wayland using mutter/elogind and the minium use of consolekit, polkit, linux-pam and friends.

gnome-3.28 works with an X11 display
weston works with a wayland display

On this distro (tinycorelinux) no daemons are started by default, but gnome-3.28/X11 display works after manually starting the dbus daemon - I presume gnome-session auto starts everything else that it needs and indeed elogind is running in the X11 session.

After modifying the last line of /usr/local/bin/gnome-session from:

XDG_RUNTIME_DIR=/run/user/$(id -u) XDG_SESSION_TYPE=X11 exec /usr/local/lib/gnome-session/gnome-session-binary "$@"

to:

XDG_RUNTIME_DIR=/run/user/$(id -u) XDG_SESSION_TYPE=wayland exec /usr/local/lib/gnome-session/gnome-session-binary "$@"

..I would expect a wayland session to start, but I get:

(gnome-shell:2746): mutter: Failed to create backend: Unable to open display, DISPLAY not set
gnome-session-binary[2722]: WARNING: App 'org.gnome.Shell.desktop' exited with code 1

In the X11 session I see:

$ loginctl
...
SESSION UID USER SEAT TTY

0 sessions listed.

..so I presume the problem is there - if there were a seat 0, then the display wayland-0 would exist.

Is there an easy way to make this work with elogind?

@Yamakuzure
Copy link
Collaborator

Yamakuzure commented May 14, 2018

Yes. The Gentoo Forum has an extensive thread about running Gnome Without Systemd.

Please refer to that, as many Gnome packages have to be patched to accept elogind as a systemd-login drop-in replacement.

@juanitotc
Copy link
Author

I'd seen that thanks, but the link is mostly speaking of earlier versions of gnome, whereas with gnome-3.28.x several of the packages (eg mutter) compile against elogind directly.

In any case, if it were an issue of elements of gnome not playing nicely with elogind, I'd probably get a different error message.

As said, I'm looking for advice on how to start elogind so it gives a seat to a given user and thus allows for the creation of a wayland display - I've done plenty of googling, but have not come up with anything yet.

@udeved
Copy link

udeved commented May 14, 2018

@Yamakuzure
Copy link
Collaborator

Yamakuzure commented May 15, 2018

@juanitotc : The build system installs src/login/org.freedesktop.login1.service, so the first application that requests org.freedesktop.login1 via dbus will cause the elogind daemon to be started. Or you can start it by hand using elogind --daemon before starting anything that might need it and after dbus has been started.

Further, the link I gave you is a whole thread, and main development actually is about Gnome 3.28. Several users have reported, that they could fully install and use Gnome 3.28 with dantrell's help.
Page 26 has a lot of hints about Wayland.

The only other thing that comes to my mind is pam. Without pam, there is no way the system could tell elogind who logs in where, so loginctl will always yield an empty result.

@juanitotc
Copy link
Author

I read through the entire gentoo thread - from page 26 on the majority of the issues are of various gnome components failing to build, whereas I managed to build gnome-3.28.x without problems and against elogind where it was an option.

I know my compiled gnome-3.28.x works because an X11 session runs from startx.

I know wayland works because I can start weston like this:

$ XDG_SESSION_TYPE=wayland XDG_RUNTIME_DIR=/run/user/1001 weston-launch

..and it reports WAYLAND_DISPLAY=wayland-0

However, whether I start elogind manually or let gnome-session start it, this fails:

$ XDG_SESSION_TYPE=wayland XDG_RUNTIME_DIR=/run/user/1001 gnome-session

..with the error mentioned in comment 1

@Yamakuzure
Copy link
Collaborator

Please log into any tty and look what "loginctl" shows. If it works (elogind is running) but no seats are listed, than I ask you to check that PAM is configured properly. You should, for instance, have a /etc/pam.d/system-auth file.

@juanitotc
Copy link
Author

Note that on tinycorelinux by default there is no login or password required and, as much as possible, apps such as consolekit, elogind, linux-pam are only used when other apps require them in order to build.

I get the following:
$ loginctl

SESSION UID USER SEAT TTY

0 sessions listed.

$ cat /usr/local/etc/pam.d/system-auth
#system-authentication
auth required pam_env.so
auth sufficient pam_unix.so nullok
auth required pam_deny.so

account required pam_unix.so

password sufficient pam_unix.so use_authtok nullok
password required pam_deny.so

session required pam_limits.so
session required pam_unix.so

@juanitotc
Copy link
Author

I guess this confirm things:

$ gnome-shell --wayland

(gnome-shell:22377): mutter WARNING: Can't initialize KMS backend: Could not get session ID: No such file or directory

..but how can I generate a session ID?

@Yamakuzure
Copy link
Collaborator

Do you have these?

 ~ $ ls -lhd /run/systemd/*
drwxr-xr-x 2 root root 240 30. Mai 17:28 /run/systemd/inhibit
drwxr-xr-x 2 root root  40 29. Mai 07:28 /run/systemd/machines
drwxr-xr-x 2 root root  60 29. Mai 07:29 /run/systemd/seats
drwxr-xr-x 2 root root  80 29. Mai 07:29 /run/systemd/sessions
drwxr-xr-x 2 root root  60 29. Mai 07:29 /run/systemd/users

@juanitotc
Copy link
Author

Yes, I do have those directories

@Yamakuzure
Copy link
Collaborator

Sorry that I did not spot this sooner.

Please add the line

-session optional pam_elogind.so

to your /usr/local/etc/pam.d/system-auth just before the last line that requests pam_unix.so.

Without that no login is reported to elogind and thus no session created. no initial session, no seat.

@juanitotc
Copy link
Author

thanks - unfortunately that doesn't change anything :(

As mentioned, I am not actually logging in to anything - is there a way to simulate a login or disable login, but still create a session?

@juanitotc
Copy link
Author

If I use a gnome X11 session, gnome-session starts elogind, but doesn't seem to seem to use the session ID because things work.

Perhaps with a gnome wayland session, elogind needs to be started in a particular way using dbus prior to starting gnome-session.

I've tried the following, but it still doesn't work:

$ sudo dbus-launch /usr/local/lib/elogind/elogind --daemon
$ dbus-launch-session gnome-session

@Yamakuzure
Copy link
Collaborator

You don't need dbus-launch. You need a dbus system daemon.

If everything works right, then any login will do. Try to log into any tty. CTRL-Alt-F2 gets you on one. If loginctl in there shows a seat and session, then everything is in order. Otherwise your PAM installation does not work or the elogind daemon is not running. The latter can be checked with ps.

@Yamakuzure
Copy link
Collaborator

What is the output of:

echo $DBUS_SESSION_BUS_ADDRESS
echo $DBUS_SESSION_BUS_PID

If it is none, then please try export $(dbus-launch) first.

Further, your two commands would have put elogind and gnome session into two separate dbus sessions. You only need to run 'dbus-launch' once and have a session dbus.

However, having to do this isn't a good sign at all.

Maybe this thread can help: Topic: dbus not starting?
Here, tcFan wrote:

The proper command is "sudo /usr/local/etc/init.d/dbus start" and the dbus file on .X.d/ doesn`t seem to be necessary.

And Juanito replied:

The gnome-session extension will autostart many (but not all) daemons and other processes, but requires the dbus daemon to be started before it will run via "startx".

Does that help?

@juanitotc
Copy link
Author

juanitotc commented Jun 2, 2018

I made some progress in discovering that polkit-0.114 needed a patch for elogind and also patched gnome-session to make sure it used elogind.

Now, when I try to start an X11 session with startx I get:

gnome-session-binary[4746]: WARNING: Could not get session id for session. Check that logind is properly installed and pam_systemd is getting used at login.

..or if I modify things so that gnome-session is called with dbus-run-session, I get:

dbus-daemon[6830]: [session uid=1001 pid=6830] Activating service name='org.a11y.Bus' requested by ':1.2' (uid=1001 pid=6834 comm="/usr/local/lib/gnome-session/gnome-session-check-a")
dbus-daemon[6830]: [session uid=1001 pid=6830] Successfully activated service 'org.a11y.Bus'
dbus-daemon[6865]: Activating service name='org.a11y.atspi.Registry' requested by ':1.0' (uid=1001 pid=6834 comm="/usr/local/lib/gnome-session/gnome-session-check-a")
dbus-daemon[6830]: [session uid=1001 pid=6830] Activating service name='org.gtk.vfs.Daemon' requested by ':1.4' (uid=1001 pid=6834 comm="/usr/local/lib/gnome-session/gnome-session-check-a")
dbus-daemon[6865]: Successfully activated service 'org.a11y.atspi.Registry'
dbus-daemon[6830]: [session uid=1001 pid=6830] Successfully activated service 'org.gtk.vfs.Daemon'
gnome-session-binary[6831]: WARNING: Could not get session id for session. Check that logind is properly installed and pam_systemd is getting used at login.

As compared to previous attempts, gnome-session no longer starts elogind itself and I need to start it prior to "startx"

The problem seems to remain that, on a system that has no login and no passwords set, how do I start a session such that elogind picks up the session ID

Note that in both the above cases, the gnome X11 desktop starts, but a lot of functionality has permission errors.

@juanitotc
Copy link
Author

juanitotc commented Jun 2, 2018

I forgot to mention, I get:

$ echo $DBUS_SESSION_BUS_ADDRESS
unix:abstract=/tmp/dbus-i8SLs07QWW,guid=b1448c9e7d92028751ec93565b12c0d4
$ echo $DBUS_SESSION_BUS_PID
1077 (after export $(dbus-launch)

@Yamakuzure
Copy link
Collaborator

gnome-session-binary[6831]: WARNING: Could not get session id for session. Check that logind is properly installed and pam_systemd is getting used at login.

I think that this is the reason. But I have no real idea how TinyCore actually works. I have read a bit on their web pages, but that is not enough to create much understanding.

Have you tried the TinyCore forums yet? I fear that I can not be of much more help here.

@juanitotc
Copy link
Author

I'm not so sure that the problem is tinycore per se, but more that I do not understand how elogind is meant to be used - I don't think elogind can give gnome-session a session id because it does not have one under /run/systemd/sessions

Is elogind meant to be started before gnome-session is launched (if so, how?) or be started by gnome-session?

Are the files created by elogind under /run/systemd meant to have their permissions adjusted for the user?

Is dbus meant to be configured differently when used with elogind?

@Yamakuzure
Copy link
Collaborator

Is elogind meant to be started before gnome-session is launched (if so, how?) or be started by gnome-session?

It doesn't matter if everything is in the right place. The first process that requests org.freedesktop.login1 from dbus causes dbus to start the daemon if it isn't already running.
For this to work the file /usr/share/dbus-1/system-services/org.freedesktop.login1.service must be present and valid. But I think in TinyCore it would be prefixed with /usr/local.
The service file is built by meson from src/login/org.freedesktop.login1.service.in.

Are the files created by elogind under /run/systemd meant to have their permissions adjusted for the user?

No. The directory structure is created by the elogind daemon, and all files there are owned by it. Which basically means root:root.

Is dbus meant to be configured differently when used with elogind?

No.

elogind is a drop-in replacement for systemd-login.
Thus everything that works with systemd-login works with elogind without any special "fiddling".
The only patching nowadays is the built system of a tool, that has to use pkg-config to add the right CPPFLAGS (-I/usr/include/elogind) and LDFLAGS (-lelogind).
Apart from that the build system must believe it is building against systemd-login.

That's all there is to it.

@juanitotc
Copy link
Author

Hmm - everything seems to be in place, but still no go.

Since tinycorelinux is not systemd I cannot check "everything that works with systemd-login works with elogind"

After starting elogind it only shows a seat0, but no user nor session.

I can get elogind to show a user using "loginctl enable-linger $USER" - is there any test I can use to try and see why it does not show a session or force it to show a session?

@mviereck
Copy link

mviereck commented Jun 5, 2018

Hmm - everything seems to be in place

Do you have a cgroup at /sys/fs/cgroup/elogind?

@juanitotc
Copy link
Author

I believe so:

$ sudo /usr/local/lib/elogind/elogind --daemon

$ ls /sys/fs/cgroup/elogind
cgroup.clone_children cgroup.sane_behavior release_agent
cgroup.procs notify_on_release tasks

@mviereck
Copy link

mviereck commented Jun 6, 2018

ok, that looks fine. It was just an idea as I had some issues with a missing cgroup (without error message) in other circumstances.

@juanitotc
Copy link
Author

I found a small c program using getsid() to find the session ID and tried to activate the session with elogind, but got this:

$ sudo loginctl activate 6416
Failed to issue method call: No session '6416' known

Is getsid() the session id elogind is looking for?

Can I manually find the session ID and pass it to elogind?

Note - I also used strace on elogind, but did not see any obvious errors.

@Yamakuzure
Copy link
Collaborator

You can configure elogind with -Ddebug=elogind --buildtype debug and see what it then logs into dmesg/messages.

I found a small c program using getsid() to find the session ID

That would be the session ID of the program. This has nothing to do with users.
See: ps -eo pid,user,cmd,args,sid --sort user

If no cgroups manager is found, elogind tries to be its own tiny manager. (Works so far on VOID Linux)
However, mounting the file systems alone is not enough, the kernel has to be built with cgroups support.

What is the output of cat /proc/self/cgroup?

@juanitotc
Copy link
Author

I get the following:

$ cat /proc/self/cgroup
1:name=elogind:/
0::/

..and:

$ ps -eo pid,user,cmd,args,sid --sort user
...
2348 tc -sh -sh 2348
2349 tc -sh -sh 2349
4624 tc /usr/local/bin/dbus-daemon /usr/local/bin/dbus-daemon 4624
9783 tc /usr/local/lib/gnome-sessio /usr/local/lib/gnome-sessio 2348
9796 tc dbus-launch --exit-with-ses dbus-launch --exit-with-ses 2348
9797 tc /usr/local/bin/dbus-daemon /usr/local/bin/dbus-daemon 9797
9824 tc /usr/local/lib/at-spi2-core /usr/local/lib/at-spi2-core 9797
9829 tc /usr/local/bin/dbus-daemon /usr/local/bin/dbus-daemon 9797
9831 tc /usr/local/lib/at-spi2-core /usr/local/lib/at-spi2-core 9797
9835 tc /usr/local/lib/gvfs/gvfsd /usr/local/lib/gvfs/gvfsd 9797
etc, etc...

i.e. there seems to be a couple of SID,but I cannot active either with "sudo loginctl activate"

@Yamakuzure
Copy link
Collaborator

No. The SID from ps is the process session ID. This has nothing to do with users. It is only a number for sessions groups of processes run in. See: https://www.win.tue.nl/~aeb/linux/lk/lk-10.html

However, /proc/self/cgroup tells me that your system has no cgroup controller at all.

What init system is used?

Can it be used as a cgroup controller?

Could you try to configure elogind not only with the debugging above, but also with -Ddefault-hierarchy=legacy, please?

@juanitotc
Copy link
Author

Recompiling elogind with "-Ddebug=elogind --buildtype=debug -Ddefault-hierarchy=legacy", I get the attached log when starting elogind from a console prompt and then starting gnome-session via startx

Note that polkitd runs when started manually as root
elogind_legacy_log.tar.gz

@mviereck
Copy link

mviereck commented Jun 6, 2018

You could check if /sys/fs/cgroup/elogind is mounted as a cgroup:

mount -t cgroup | grep elogind

In another setup I created elogind cgroup before starting elogind (without cgmanager or similar) with:

mkdir -p /sys/fs/cgroup/elogind
mount -t cgroup cgroup /sys/fs/cgroup/elogind -o none,name=elogind

@Yamakuzure
Copy link
Collaborator

The log says:

elogind[31290]: Mounting tmpfs to /sys/fs/cgroup of type tmpfs with options mode=755.
elogind[31290]: Mounting cgroup to /sys/fs/cgroup/unified of type cgroup2 with options nsdelegate.
elogind[31290]: Mounting cgroup to /sys/fs/cgroup/elogind of type cgroup with options

That is a hybrid setup. I think we have found an issue with either the build system or elogind playing cgroup controller. That is definitely something I have to investigate.

elogind[31290]: Using cgroup controller name=elogind. File system hierarchy is at /sys/fs/cgroup/elogind.

That one is mounted asa cgroup file system. So basically everything is in order.

elogind[31290]: New seat seat0.
elogind[31290]: VT changed to 1
elogind[31290]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/login1 interface=org.freedesktop.login1.Manager member=SeatNew cookie=3 reply_cookie=0 error-name=n/a error-message=n/a

Alright, the seat is there.

elogind[31290]: Sent message type=method_call sender=n/a destination=org.freedesktop.PolicyKit1 object=/org/freedesktop/PolicyKit1/Authority interface=org.freedesktop.PolicyKit1.Authority member=CheckAuthorization cookie=8 reply_cookie=0 error-name=n/a error-message=n/a
dbus-daemon[31286]: [system] Activating service name='org.freedesktop.PolicyKit1' requested by ':1.0' (uid=0 pid=31290 comm="/usr/local/lib/elogind/elogind --daemon ") (using servicehelper)
elogind[31290]: Got message type=error sender=org.freedesktop.DBus destination=:1.0 object=n/a interface=n/a member=n/a cookie=7 reply_cookie=8 error-name=org.freedesktop.DBus.Error.Spawn.ExecFailed error-message=Failed to execute program org.freedesktop.PolicyKit1: Permission denied

Okay, that is very bad! Please investigate.

For everything elogind asks, dbus tries to spawn org.freedesktop.PolicyKit1 and fails.

@juanitotc
Copy link
Author

btw, to answer an earlier question, tinycorelinux uses busybox init

@juanitotc
Copy link
Author

juanitotc commented Jun 7, 2018

Ref: "For everything elogind asks, dbus tries to spawn org.freedesktop.PolicyKit1 and fails."

org.freedesktop.PolicyKit1 (/usr/local/lib/polkit-1/polkitd) will start as root and then successfully changes to the default user.

This is where I'm confused by elogind - /usr/local/etc/dbus-1/system.d/org.freedesktop.PolicyKit1.conf allows the default user to own org.freedesktop.PolicyKit1 - is this config used by elogind or are separate polkit rules/actions required for elogin to spawn org.freedesktop.PolicyKit1 as root?

If separate polkit rules/actions are required, I'd be grateful if you could point me to an example

$ sudo /usr/local/lib/polkit-1/polkitd
Successfully changed to user tc
Loading rules from directory /usr/local/etc/polkit-1/rules.d
18:48:10.958: Loading rules from directory /usr/local/share/polkit-1/rules.d
18:48:10.958: Finished loading, compiling and executing 4 rules
Entering main event loop
Connected to the system bus
18:48:10.959: Acquired the name org.freedesktop.PolicyKit1 on the system bus

@juanitotc
Copy link
Author

Aaaargh - the permissions on dbus-daemon-launch-helper were incorrect

Now if I:

  • start the dbus daemon
  • start the elogind daemon
  • enable-linger $USER
  • startx

I get:
$ grep elogind /var/log/messages | grep user
Jun 7 21:25:53 boxdell auth.debug elogind[32496]: New user $USER logged in.

..but there is still no session ID
gnome-session-binary[3715]: WARNING: Could not get session id for session. Check that logind is properly installed and pam_systemd is getting used at login.

..and the startup of the gnome desktop and operation of gnome-control-center are much slower than before.

@Yamakuzure
Copy link
Collaborator

As I said. PAM must be used. And please do not use linger, it does not do what you think!

btw, to answer an earlier question, tinycorelinux uses busybox init

And is BusyBox built with PAM support?

You must have any means to log in a user through pam. Without that this will not work. A login manager like SDDM or whatever gnome uses these days should be enough.

@juanitotc
Copy link
Author

I'd really like to avoid using any login manager at all - is there no way to do this by working with pam directly?

@mviereck
Copy link

mviereck commented Jun 7, 2018

A login manager like SDDM or whatever gnome uses these days should be enough.

I'd really like to avoid using any login manager at all

I found that su already triggers login with elogind (at least on devuan, libpam-elogind installed). And su from root to unprivileged user works without a password. (Just a way to avoid display managers).

@juanitotc
Copy link
Author

And is BusyBox built with PAM support?

No, the idea of tinycorelinux is to have the smallest possible bootable system and add anything that is needed afterwards.

I found that su already triggers login with elogind

Switching to root cause elogind to write several files to /run/systemd/inaccessible, but switching back to the default user does not trigger a login with elogind.

A login manager like SDDM or whatever gnome uses these days should be enough.

gnome will not start (gjs gives a critical error) without gdm present, but I have never managed to make gdm work, hence I'm reluctant to try another dm (sddm).

@juanitotc
Copy link
Author

juanitotc commented Jun 9, 2018

Ah-ha - "su" from busybox was being used. If I use "su" from shadow and "su $USER" where $USER is the current default user, things work.

$ ls /run/systemd/*/* /run/systemd/inhibit/10 /run/systemd/inhibit/8 /run/systemd/inhibit/10.ref /run/systemd/inhibit/8.ref /run/systemd/inhibit/6 /run/systemd/seats/seat0 /run/systemd/inhibit/6.ref /run/systemd/sessions/c1 /run/systemd/inhibit/7 /run/systemd/sessions/c1.ref /run/systemd/inhibit/7.ref /run/systemd/users/1001

..and gnome runs in both x11 and wayland sessions :)

Thanks for the help and suggestions

@Yamakuzure
Copy link
Collaborator

Wow! Congratulations on finally working this out!

Maybe, if you want, you could describe your findings to the TinyCoreLinux people? That could help others who try what you did in the future.

@juanitotc
Copy link
Author

Already done, see the last post here:

http://forum.tinycorelinux.net/index.php/topic,16875.msg137479.html#msg137479

@Yamakuzure
Copy link
Collaborator

👍

@warpme
Copy link

warpme commented Feb 4, 2021

..and gnome runs in both x11 and wayland sessions :)

@juanitotc,
@Yamakuzure

Forgive me bothering You with thing a bit unrelated to this ticket...but i'm really desperate (and frustrated) - so looking also here for help....

I'm developing linux based appliance and i lost days trying to find solution for: auto-start app. using weston compositor.
Basically: I want to start app from rc scripts and auto-start this app. as userX - not root.
Appliance is minimal OS to run app (mythtv). no systemd, no logind, etc.

As I see:

  • the same level of minimalism in tinycorelinux
  • you solve a bit similar problem

Is it possible to help me to solve problem of getting auto-starting app. which uses weston compositor?
Ideally will be kind of short blog how to achieve this - as other ppl. will also benefit from your's findings!
Alternatively - I can write such blog with your guidance/help...
If you don't have time/energy: any kind of help will be v.appreciated!

Status: i have already all working when i:

  1. log into tty
  2. kick weston-launch
  3. start app i.e. in terminal

Issue is with automating this to get auto-starting at appliance boot...

@Yamakuzure
Copy link
Collaborator

This would then be a matter of the init system. What are you using? SysVInit directly, runnit, openrc, something else? There I'd start looking. Personally I do not know enough about weston to tell you what the requirements are for your app to be auto-startable.

However, here someone seems to have had a similar problem/requirement:
https://unix.stackexchange.com/questions/497647/start-a-qt-wayland-application-on-top-of-weston-on-startup

Maybe you'll get some inspiration there.

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

No branches or pull requests

5 participants