Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Please post suggestions for improvement of Cinnamon on:
https://github.com/linuxmint/Cinnamon
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

Hi comrades,
I noticed, at least on my machine (Mint 19.1, Cinnamon 4.0.10) that *all* of the commands to restart Cinnamon from TTY cause problems with the gnome polkit authentication agent.
- flatpak programs disappear from Mint Menu
- programs that require elevated priviledges, when called from Mint Menu (eg. ufw) can cause hard cinnamon freezes. (waiting for (impossible) authentication on the other TTY)
- Mintinstall aborts new programs installation without explanation
- (Mintupdate still works)

Workaround when there's no other way to restart cinnamon : restart from TTY. Save your work. Log out. Log back in.
Am I the first one to notice this ? Are there better solutions ?

best regards, :mrgreen:
comrade lofi
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by Termy »

Can you reload the agent to counteract that issue?
I'm also Terminalforlife on GitHub.
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

Thanks for the quick reply (I was about to post my LONG version, maybe not needed)

without sudo : (edited)

Code: Select all

(polkit-gnome-authentication-agent-1:10098): polkit-gnome-1-WARNING **: 22:40:24.131: Failed to register client: GDBus.Error:org.gnome.SessionManager.AlreadyRegistered: Unable to register client
with sudo :

Code: Select all

(polkit-gnome-authentication-agent-1:10067): GLib-CRITICAL **: 22:39:28.996: g_variant_new_string: assertion 'string != NULL' failed

(polkit-gnome-authentication-agent-1:10067): polkit-gnome-1-WARNING **: 22:39:28.996: Failed to register client: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

well, anyway, LONG version of 1st post,


Hi, I love Mint and Cinnamon, I recently found a fix for several problems I had, and I'm here to share the fix (or workaround) with comrades. Finding the cause took a lot of time, and even after it, I searched extensively and can confirm that, apparently, this problem is not documented. It took me 2 days to find exactly how to reproduce this, and try to understand what was happening, and read documentation on cinnamon and the polkit agent, and github issues, and produce good logs, etc. I'm here to share my findings. (and ask comrades if this was fixed since Mint 19.1 (my version) / Cinnamon 4.0.10)

For several months I've had problems with,
- flatpak applications disappearing from Mint menu, after some time...
- Mintinstall unable to install some programs (even non flatpak)
There were workarounds, but the other day I tried to launch ufw (firewall) from Mint Menu. This actually calls gufw, the GUI version. I hit enter or clicked "ufw", and everything froze suddenly. Couldn't restart Cinnamon with Ctrl+Alt + Esc. Couldn't Alt+F2, nothing.

Long story short, I found all these problems are related, and happen after I restart Cinnamon from another TTY, e.g. TTY1.
On my machine, I can confirm that ALL the flavors of "... DISPLAY=:0 ..." cause the problem.

Code: Select all

$ export DISPLAY=:0; cinnamon --replace
$ DISPLAY=:0 cinnamon --replace
$ cinnamon --replace --display=:0
and other flavours like DISPLAY=:0 cinnamon-launcher

The commands with "export" cause the worst freezes when trying to launch an application requiring elevated priviledges from Mint Menu. With the mere "DISPLAY=:0" I could go back to TTY1 and understand the problem : the polkit-gnome-authentication-agent does ask for password, but only in the TTY where cinnamon was started. But authenticating is impossible. My name being LOFI, the polkit agent asks the password for "LOFI,,," (three commas added, can't be removed). But even if polkit authentication from TTY was possible, that would be quite a broken user interface ! I noticed that as soon as I click "ufw", a stop signal is sent to cinnamon (status : T). A workaround is to send a SIGCONT to cinnamon, but the polkit problem remains.

What's weird is that auth.log doesn't show a prompt to authentify "LOFI,,," but this,

Code: Select all

[timestamp] [my-computer-name] polkitd(authority=local): Registered Authentication Agent for unix-process:5822:91784 (system bus name :1.90 [pkexec gufw-pkexec LOFI], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
(locale is incorrect)

With flatpak, at least you don't get freezes, as the programs completely disappear from the menu. (they can be launched with flatpak run). As for Mintinstall, you click "install", you often are warned that "several additional packages are required", "ok", then the installation stops without an explanation. I used to think there was a dependency problem, I would try apt from command line, and would be surprised that it worked, for mysterious reasons.
Strangely, the polkit agent problem (when cinnamon was restarted from another TTY) doesn't affect mintupdate.
I found that, for example, polkit rules for flatpak is to allow members of the sudo group. Without the authentication agent, Cinnamon can't run a flatpak program.

I wanted to find a real fix, but I couldn't. Some people say that from TTY1, you are root. I found this is not the case on my configuration. Thanks to the top monitoring command (tree view) I saw that cinnamon or cinnamon --launcher is normally a subprocess of mint-session. With the commands above (display 0 cinnamon --replace), cinnamon becomes a subprocess of (in my case) : init / login -p -- / zsh.
Instead of : init / lightdm / lightdm --session-child / cinnamon-session (polkit-gnome-authentication-agent being on the same level).

The different flavours of DISPLAY=:0 cinnamon commands are widely recommended online, for example in major askubuntu threads. That's why in 2015 Bernd Wechner started a thread here (about cinnamon) and created an issue on github that got quite big. https://github.com/linuxmint/cinnamon/issues/4763 "no clear way to restart cinnamon from TTY"
His point was that sometimes, there's no other way to restart cinnamon than to open another TTY. But the command is not reliable. (but polkit problems were not mentioned) (issue is closed)

Is there a way to restart cinnamon from TTY1 and make sure that it becomes a subprocess of mint-session? How? I've looked into Python subprocesses and searched stack exchange... https://unix.stackexchange.com/question ... ferent-tty I see ideas, but that don't look too good, so much that I didn't try them.

So *if* this is still a problem in Mint 20 and 21, the "workaround" that I propose, when Cinnamon freezes and you can't open a terminal, and Ctrl+Alt + Escape doesn't work, is to restart cinnamon from TTY, save your work, log out and log back in.
Though it would be nice to have a command to restart cinnamon without breaking the link with the polkit agent (maybe restart it from TTY too ??), I'm not doing a feature request. My main point is I worry for less experienced comrades. Unless it was fixed since Mint 19.1, many users must find online, after a hard freeze, the protip to restart Cinnamon from TTY. Then they copy/paste the command, and then they have no way to understand why some programs disappeared, and they can also run into hard freezes, just for trying to open an app that requires elevated priviledges from the Menu.

So I hope that with this post, if confirmed, search engines will bring people here, and they will find that several of their problems are caused by the fact that their running version of cinnamon was started incorrectly.
Else I don't know, from a scale from easy to impossible, how hard it would be for the devs to change cinnamon so that it would detect when it's run from a text TTY, and would ask the user what it is exactly that they want to do ? Anyway, this is not a feature request from my part. This would not be the place anyway, I'd make it on github. I love Mint Cinnamon and I just wanted to share this, and find a way to spare as many comrades as possible from spending hours on it like I did.

best regards
lofi
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

Termy wrote: Sat May 21, 2022 4:27 pm Can you reload the agent to counteract that issue?
New reply @Termy : I found the correct way to restart polkit authentication agent.
cf. viewtopic.php?t=302811 (OP was @gulas)

Code: Select all

=> sudo systemctl restart polkit.service
(in the thread above, someone had a polkit problem, not the same cause, but same effects : GUI applications requiring root not starting)

This time, the polkit agent is correctly registered. But it doesn't solve the problem.
/var/logs/auth.log : https://pastebin.com/KYVwth19 (expires after 1 year)
excerpt :

Code: Select all

polkitd(authority=local): Unregistered Authentication Agent for unix-process:6508:14361117 (system bus name :1.689, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
polkitd(authority=local): Operator of unix-process:6508:14361117 FAILED to authenticate to gain authorization for action com.ubuntu.pkexec.gufw for unix-process:6508:14361117 [<unknown>] (owned by unix-user:LOFI)
I don't know why this says "unregistered agent" while journalctl says the agent was correctly registered.

journalctl logs when I restart polkit auth agent (with cinnamon restarted form tty)
https://pastebin.com/zrAkgvcM
interesting excerpts,
- polkit agent registered correctly

Code: Select all

May 22 16:23:19 [my-computer-name] polkitd(authority=local)[6471]: Registered Authentication Agent for unix-session:c12 (system bus name :1.509 [/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1], object path /org/gnome/PolicyKit1/AuthenticationAgent, locale en_GB.UTF-8)
May 22 16:23:54 [my-computer-name] polkitd(authority=local)[6471]: Registered Authentication Agent for unix-process:6508:14361117 (system bus name :1.689 [pkexec gufw-pkexec LOFI], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
(idk why the locale changes for ufw, from en_GB (my computer) to en_US)
- when I then proceed to try to launch ufw aka gufw from Mint menu

Code: Select all

polkitd(authority=local)[6471]: Registered Authentication Agent for unix-process:6508:14361117 (system bus name :1.689 [pkexec gufw-pkexec LOFI], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Like gulas, I tried pkexec from terminal for a quicker way to get error logs =>

Code: Select all

pkexec gufw
This time, the terminal is able to call the polkit auth agent graphical dialog "an application requires authentication".
But it's not really news : what's broken in this thread's situation, is the link between cinnamon and the polkit agent.

I keep on working on this despite the fact that it's no more a problem for me (workaround). I'm pleased to see that this seems to now be the top Google result... at least for someone who found the link between TTY restarts and polkit problems.
What's more helpful ? Long detailed posts with logs, or short posts ?

I'll make a short post after this one.
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

Comrades, could at least one person test this ?

Steps :

- open TTY1 : Ctrl+Alt + F1
- log in
- type and run command $ DISPLAY=:0 cinnamon --replace &
- go back to GUI aka TTY7 : Ctrl+Alt + F7
- wait... until you see the screen effect (disappear / reappear) meaning cinnamon got restarted
- call Cinnamon menu (Super key)
(a) non-compulsory addtionnal step below
- in Cinnamon Menu, type ufw (this is the linux firewall, aka Uncomplicated FireWall) and press Enter

=> do you,
- get a dialog box asking for password ?
- get a freeze with only the mouse pointer moving ?

In the latter case, my warning would be confirmed. (to escape from the situation, go back to TTY1, press Enter instead of a paswword if asked, go back to TTY7. If it's not enough, go back to TTY1, enter same command as above (DISPLAY=:0...) and go back to TTY7.
In the other case, it would mean that no, restarting cinnamon from another TTY is not dangerous for everyone.


(a) if you have flatpaks installed, check if you can launch them from Cinnamon Menu. This test is actually easier, as it can't cause freezes.

Thank you, I think this is important for all comrades, as the "trick" to restart cinnamon with "DISPLAY=:0" commands is so widespread. (it's even a cinnamon hard-coded option as in "cinnamon --replace --display=:0")
Else, I'll take this to cinnamon's github.

best regards!
lofi :mrgreen:
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by Termy »

lofi wrote: Sun May 22, 2022 12:10 pm [...]
You're definitely onto something here. I just tried this in a Linux Mint 20.3 Cinnamon virtual machine and did in-fact get no dialog windows pop up. Nothing appeared to happen. Looks like the --replace flag isn't too useful on its own. I restarted the PolKit service but the dialog window still wouldn't pop up. To confirm it wasn't something else, I rebooted and ran GUFW again (from the Menu), but the dialog correctly showed up.

BTW, I followed your steps having first logged into my user account via the display manager.

The flag is good in a pinch though, to get the current session functional so you can save opened files and relog or reboot; perhaps that's all it was meant to be?
I'm also Terminalforlife on GitHub.
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

Ah, some recognition at last, thanks!
Termy wrote: Sun May 22, 2022 1:33 pm The flag is good in a pinch though, to get the current session functional so you can save opened files and relog or reboot; perhaps that's all it was meant to be?
I don't know the original intention but yes, I will definitely still use `cinnamon --replace --display=:0` (or another flavour, they don't do exactly the same thing) when there's no other way to restart. As long as one logs out after it. I wish I had more priviledges on the big sites like askubuntu, I think it would be a good thing if someone posted that warning (for Mint also) each time "restart from TTY" is recommended, I want to tell the whole world ! Thanks for testing!
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

PS : I used sudo htop on the tty restarted version of the cinnamon process.
"E" for environment variables.
I compared with the normal state of cinnamon.
The variables are vastly different.
One cannot copy/paste from this screen, and I'd rather not post screenshots (edit : attached and redacted)

(I realize that I did the test with the "cinnamon-launcher" flavor, which is not ideal but it's just a "wrapper" that kills the fallback DE and then launches cinnamon.
poor picture quality intended because 300kb was too much to attach.
normal cinnamon and restarted from another TTY
normal cinnamon and restarted from another TTY
restarted cinnamon :
- no XDG CURRENT DESKTOP
- no DESKTOP SESSION (was = Cinnamon)
- no DEFAULTS_PATH (was = /usr/share/gconf/cinnamon.default.path)
- there's an INVOCATION_ID that was not there

both,
- identical dbus line
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by Termy »

lofi wrote: Sun May 22, 2022 3:03 pm - no XDG CURRENT DESKTOP
- no DESKTOP SESSION (was = Cinnamon)
- no DEFAULTS_PATH (was = /usr/share/gconf/cinnamon.default.path)
- there's an INVOCATION_ID that was not there
I think $XDG_CURRENT_DESKTOP, $DESKTOP_SESSION, and $DEFAULTS_PATH aren't super-critical, at least in this way, but I don't know the ins and outs of Cinnamon. Not sure about the last one you listed. Being in a TTY, I do expect to typically be without various GUI-related environment variables. I don't think environment variables are the problem here, nor that we were in a TTY at the time of running the command with the flag in question. I could certainly be wrong, of course. Sometimes EVs make a big difference, such as $DISPLAY, as you know.

You could try injecting those EVs into the cinnamon command you run in a TTY, in-case it uses those directly, although I expect you tried that.

I'm surprised you haven't had more responses to this thread, but then, it's quite a bit advanced for the target audience of Linux Mint. If only Linux Mint developers hung out here, or at least overtly. :roll: Dunno if I mentioned it already, but you should head on over to GitHub with this, because this is the sort of stuff the developers need to see, although they may already be aware of and working on this. If you're comfortable making a GitHub account, of course. It's a bit stupid you need an account to post a bug report on GitHub, TBH.
I'm also Terminalforlife on GitHub.
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

Termy wrote: Sun May 22, 2022 9:42 pm You could try injecting those EVs into the cinnamon command you run in a TTY, in-case it uses those directly, although I expect you tried that.
Good idea! Nope, I didn't think about it. I'm running out of time, but it would be interesting to test this. It's weird because in htop tree view, I see that my TTY runs processes as children of login -p, where "p" means "preserve environment". Whose environment ?
But I guess the more elegant way would require some Python knowledge. Like I wrote above, the normal (on my machine) cinnamon process is a child of lightdm and cinnamon-session (from TTY it becomes a child of login -p and zsh/bash). I looked quickly into Python subprocesses, but I don't know how to say "launch cinnamon as subprocess of cinnamon-session".
but you should head on over to GitHub with this
Yes, definitely. I've hesitated to post there from the start. But when you read developer information (it used to be developer.linuxmint.com), they make it clear that most bug reports are useless, considering developers don't have the time to look into all of them. A good bug report requires a lot of work, and followup. They clearly say that it's not useful if you didn't find the cause for the bug. Well, at least I have this, somehow.
https://linuxmint-troubleshooting-guide ... en/latest/
And I wonder if it will be considered as a bug, as restarting from TTY is not really official.

Thanks again for the input, I just hadn't made the connection between "(export) DISPLAY=:0" and all the other environment variables that I mentioned, I thought it was much harder to change that.
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by Termy »

lofi wrote: Mon May 23, 2022 9:31 am but I don't know how to say "launch cinnamon as subprocess of cinnamon-session".
If you're referring to child processes, then, as far as I know, running a shell command (presumably os.system()) makes that command(s) the child process(es) whose parent process is that instance of the Python interpreter. That's what I'd expect from PERL (system() and `...`) scripts, and even shell scripts. Put simply, I think what you want to do is already happening by default, due to the nature of how Linux works.

I looked into the subprocess thing just now. The subprocess module came up, which seems to just be for bidirectional transfer (asynchronous execution?) for pipes, like the coproc keyword in BASH, which I'm guessing is not what you're wanting. I've done something like that in PERL, using IPC::Open2 and IPC::Open3, where, if I remember correctly, the former doesn't support a separate filehandle for STDERR, but the latter does.

It's time like this I wish I were a Python programmer, especially as I keep seeing people here running into problems with the various Python-written tools in Linux Mint. It'd be a shame for them not to be receptive to bug reports, given how important they are.
lofi wrote: Mon May 23, 2022 9:31 am It's weird because in htop tree view, I see that my TTY runs processes as children of login -p, where "p" means "preserve environment". Whose environment ?
From looking at the man page for login(1), it would seem that you can use it from an existing user's environment, so presumably the -p flag preserves that environment. I'm not quite sure how it works though, because I've never really messed with login(1), except of course when logging in on a TTY.
I'm also Terminalforlife on GitHub.
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

hey, I was precisely trying to write a good GH issue. Thanks again for the input.
I like the linux spirit : we don't have to call Microsoft support, everything is there in front of our eyes. But it's quite humbling when you try to mess with anything, there's so much to learn. I used to program in Ruby, and it's said that Python is not that different.
But after reading this,
Termy wrote: Mon May 23, 2022 11:33 am I looked into the subprocess thing just now. The subprocess module came up, which seems to just be for bidirectional transfer (asynchronous execution?) for pipes, like the coproc keyword in BASH, which I'm guessing is not what you're wanting. I've done something like that in PERL, using IPC::Open2 and IPC::Open3, where, if I remember correctly, the former doesn't support a separate filehandle for STDERR, but the latter does.
I realize that a subprocess is not what we want here! (I've never heard of coproc in bash)

Can I quote you on github like this ?
I started a post there a couple days ago viewtopic.php?f=208&t=374269&p=2179501 (with my logs and many details + one confirmation from @terminalforlife viewtopic.php?p=2179171#p2179171 )
I thought it was funny to tag you and credit you, but it's not necessary, I haven't posted yet, and will remove from my blueprint if I don't have a greenlight before I finish my issue.
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

Termy wrote: Mon May 23, 2022 11:33 am snip
Issue created. Without your greenlight, I removed my reference to your "bug" confirmation. https://github.com/linuxmint/cinnamon/issues/10804
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by Termy »

Feel free to quote me.
I'm also Terminalforlife on GitHub.
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

Termy wrote: Mon May 23, 2022 12:46 pm Feel free to quote me.
Cool. Edited.
(I also changed the STR : not sure if ufw is installed by default, so "Software Sources" is another way to test the issue)
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by Termy »

lofi wrote: Mon May 23, 2022 1:06 pm [...]
UFW and GUFW are both installed by default in Linux Mint; the latter depends on the former, so even if GUFW is uninstalled, it's very likely a user won't remove UFW itself.
I'm also Terminalforlife on GitHub.
lofi
Level 2
Level 2
Posts: 65
Joined: Sun Mar 10, 2019 3:10 pm
Location: France

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by lofi »

Termy wrote: Mon May 23, 2022 3:22 pm UFW and GUFW are both installed by default in Linux Mint;
oh, thanks. (btw, from the menu, "ufw" calls gufw)
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Warning about restarting Cinnamon from another TTY (polkit issues) (to be confirmed)

Post by Termy »

lofi wrote: Mon May 23, 2022 3:28 pm [...]
Yeah, that's probably just to avoid confusion. Under the hood, it is essentially just using UFW, but GUFW is the GTK front-end, which I believe is written in Python.
I'm also Terminalforlife on GitHub.
Locked

Return to “Cinnamon”