Merge ~macg3/ubuntu/+source/gdebi:fix_pkexec into ubuntu/+source/gdebi:ubuntu/devel

Proposed by Doug Brown
Status: Needs review
Proposed branch: ~macg3/ubuntu/+source/gdebi:fix_pkexec
Merge into: ubuntu/+source/gdebi:ubuntu/devel
Diff against target: 29 lines (+5/-2)
1 file modified
GDebi/GDebiGtk.py (+5/-2)
Reviewer Review Type Date Requested Status
Julian Andres Klode (community) Needs Fixing
Utkarsh Gupta Pending
git-ubuntu import Pending
Review via email: mp+414211@code.launchpad.net

Description of the change

This fixes a longstanding issue that prevents GDebi from working properly when it is launched by a GUI app, such as Firefox or Chrome after downloading a deb file. Ever since Ubuntu 17.10, GDebi just quits immediately when you click Install. It works properly when you run it from a terminal window, but not when launched from Firefox or Chrome. The reason is because pkexec refuses to work if its parent process is init. This change adds an intermediate script that acts as the parent for pkexec.

To test:

- Download a deb file in Firefox/Chrome.
- Open it from within the browser's downloads screen, and choose to open it with GDebi.
- It will open fine. Now, click Install.

Without this change applied, GDebi will immediately quit and the package won't be installed.
After this change is applied, GDebi will successfully install the package.

Another way to test is by directly running GDebi with setsid:

setsid gdebi-gtk package.deb

Without this change, it will fail in the same way. With this change, it will succeed.

The bug that this fixes is Launchpad #1854588. Ideally this would be ported to all of the LTS releases. I'm brand new to this Launchpad workflow, so I'm not sure if there's anything I need to do in order to kickstart this process.

To post a comment you must log in.
Revision history for this message
Robie Basak (racb) wrote :

> I'm brand new to this Launchpad workflow, so I'm not sure if there's anything I need to do in order to kickstart this process.

Sorry, we don't really have a formal way for third parties to submit into this workflow yet - in that there are no reviewers at the other end. To connect the dots, I'm going to link this MP to the bug, and then subscribe ~ubuntu-sponsors to the bug. That way the request will end up in the old sponsorship queue.

Revision history for this message
Julian Andres Klode (juliank) wrote :

This seems unncessarily involved, just run pkexec with subprocess.call() instead or fork and exec such that the gdebi process remains and becomes the parent of the pkexec?

Seems premature optimization to exec into another minimal script first.

review: Needs Fixing
Revision history for this message
Doug Brown (macg3) wrote :

Thanks, Julian. Your feedback makes sense, and seems so obvious in hindsight.

It's been quite a while since I made this request, and in the meantime, Ubuntu 23.04 no longer seems affected by this issue because it ends up being parented by systemd instead of init, so pkexec no longer complains. Is there any value in continuing with this gdebi fix to backport these changes to older LTS releases?

Revision history for this message
Dave Jones (waveform) wrote :

I'd say it's still worth making the change (specifically, the simpler variant Julian suggested). Jammy is still going to be the current LTS until April next year, so that's most of a year that the bug will be sitting there for current LTS users if it's not patched.

Revision history for this message
Doug Brown (macg3) wrote :

Thank you. I will look into resubmitting with Julian's suggested solution. Also, it turns out that this does still affect modern versions of Ubuntu MATE and I was mistaken -- see my latest comment in the related bug report for more info on why it is so weird to reproduce.

57764ef... by Doug Brown <email address hidden>

Stay alive for pkexec

pkexec doesn't allow the parent process to be init. The previous method
of using os.execv() caused this to be the case in some conditions. Keep
the original GDebi instance alive as a parent process and run the
elevated version using subprocess.call() instead.

This fixes the issue of GDebi closing immediately when you click Install
after opening a .deb file from inside of Firefox or Chrome.

Fixes LP #1854588

Revision history for this message
Doug Brown (macg3) wrote :

I updated this merge proposal as per Julian's recommendation to use subprocess.call(). Note that I had to close the main window in the original GDebi process, which also required processing GTK events in order to take effect.

Seems to work great!

Revision history for this message
Robie Basak (racb) wrote :

Thanks! This looks good to me, but the process to land this seems a bit complicated because gdebi seems to be abandoned at its nominated upstream, and has a slew of NMUs. I'm not sure what the etiquette is here. Utkarsh said he'd take a look in the next few days.

Unmerged commits

57764ef... by Doug Brown <email address hidden>

Stay alive for pkexec

pkexec doesn't allow the parent process to be init. The previous method
of using os.execv() caused this to be the case in some conditions. Keep
the original GDebi instance alive as a parent process and run the
elevated version using subprocess.call() instead.

This fixes the issue of GDebi closing immediately when you click Install
after opening a .deb file from inside of Firefox or Chrome.

Fixes LP #1854588

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/GDebi/GDebiGtk.py b/GDebi/GDebiGtk.py
2index e0faa49..1c90d7b 100644
3--- a/GDebi/GDebiGtk.py
4+++ b/GDebi/GDebiGtk.py
5@@ -27,6 +27,7 @@ import logging
6 import os
7 import posix
8 import re
9+import subprocess
10 import sys
11 import time
12 import tempfile
13@@ -603,12 +604,14 @@ class GDebiGtk(SimpleGtkbuilderApp, GDebiCommon):
14
15 if os.getuid() != 0:
16 pkexec_cmd = "/usr/bin/pkexec"
17- pkexec_args = ["pkexec"]
18 gdebi_args = ["gdebi-gtk", "--non-interactive",
19 self._deb.filename]
20 if not install:
21 gdebi_args.append("--remove")
22- os.execv(pkexec_cmd, pkexec_args+gdebi_args)
23+ self.window_main.close()
24+ while Gtk.events_pending():
25+ Gtk.main_iteration()
26+ sys.exit(subprocess.call([pkexec_cmd]+gdebi_args))
27
28 if not self.try_acquire_lock():
29 if install:

Subscribers

People subscribed via source and target branches