Merge lp:~brian-murray/ubuntu-release-upgrader/improve-inhibit-idle into lp:ubuntu-release-upgrader

Proposed by Brian Murray on 2018-07-05
Status: Merged
Merged at revision: 3143
Proposed branch: lp:~brian-murray/ubuntu-release-upgrader/improve-inhibit-idle
Merge into: lp:ubuntu-release-upgrader
Diff against target: 186 lines (+66/-56)
3 files modified
DistUpgrade/DistUpgradeController.py (+55/-0)
DistUpgrade/DistUpgradeQuirks.py (+1/-56)
debian/changelog (+10/-0)
To merge this branch: bzr merge lp:~brian-murray/ubuntu-release-upgrader/improve-inhibit-idle
Reviewer Review Type Date Requested Status
Steve Langasek 2018-07-05 Approve on 2018-07-06
Sebastien Bacher 2018-07-05 Approve on 2018-07-06
Review via email: mp+349028@code.launchpad.net

Description of the change

It seems safer to continue to inhibit gnome-session idle so that people are not locked out of their system after upgrading, but we should warn them that this will be happening.

To post a comment you must log in.
Sebastien Bacher (seb128) wrote :

The changes seem fine to me

review: Approve
Steve Langasek (vorlon) wrote :

one wording suggestion.

review: Approve
3143. By Brian Murray on 2018-07-06

modify wording based off reviewer feedback

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'DistUpgrade/DistUpgradeController.py'
2--- DistUpgrade/DistUpgradeController.py 2018-06-27 23:34:19 +0000
3+++ DistUpgrade/DistUpgradeController.py 2018-07-06 17:47:44 +0000
4@@ -188,6 +188,9 @@
5
6 # apt cron job
7 self._aptCronJobPerms = 0o755
8+ # for inhibiting idle
9+ self._uid = ''
10+ self._user_env = {}
11
12 def openCache(self, lock=True, restore_sources_list_on_fail=False):
13 logging.debug("openCache()")
14@@ -1894,6 +1897,7 @@
15 self._view.updateStatus(_("Calculating the changes"))
16 if not self.askDistUpgrade():
17 self.abort()
18+ self._inhibitIdle()
19
20 # fetch the stuff
21 self._view.setStep(Step.FETCH)
22@@ -1984,6 +1988,57 @@
23 _("The partial upgrade was completed."))
24 return True
25
26+ def _inhibitIdle(self):
27+ if os.path.exists("/usr/bin/gnome-session-inhibit"):
28+ self._uid = os.environ.get('SUDO_UID', '')
29+ if not self._uid:
30+ self._uid = os.environ.get('PKEXEC_UID', '')
31+ if not self._uid:
32+ logging.debug("failed to determine user upgrading")
33+ logging.error("failed to inhibit gnome-session idle")
34+ return
35+ self._getUserEnv()
36+ if not self._user_env:
37+ return
38+ #seteuid so dbus user session can be accessed
39+ os.seteuid(int(self._uid))
40+
41+ logging.debug("inhibit gnome-session idle")
42+ try:
43+ xdg_desktop = self._user_env.get("XDG_CURRENT_DESKTOP", "")
44+ if not xdg_desktop:
45+ logging.debug("failed to find XDG_CURRENT_DESKTOP")
46+ logging.error("failed to inhibit gnome-session idle")
47+ return
48+ idle = subprocess.Popen(["gnome-session-inhibit", "--inhibit",
49+ "idle", "--inhibit-only"],
50+ env=self._user_env)
51+ self._view.information(_("Lock screen disabled"),
52+ _("Your lock screen has been "
53+ "disabled and will remain "
54+ "disabled until you reboot."))
55+ except (OSError, ValueError):
56+ logging.exception("failed to inhibit gnome-session idle")
57+ os.seteuid(os.getuid())
58+
59+ def _getUserEnv(self):
60+ try:
61+ pid = subprocess.check_output(["pgrep", "-u", self._uid,
62+ "gnome-session"])
63+ pid = pid.decode().split('\n')[0]
64+ with open('/proc/' + pid + '/environ', 'r') as f:
65+ data = f.read().split('\x00')
66+ for line in data:
67+ if len(line):
68+ env = line.split('=', 1)
69+ self._user_env[env[0]] = env[1]
70+ except subprocess.CalledProcessError as e:
71+ if e.returncode == 1:
72+ logging.debug("gnome-session not running for user")
73+ else:
74+ logging.exception("failed to read user env")
75+
76+
77
78 if __name__ == "__main__":
79 from .DistUpgradeViewText import DistUpgradeViewText
80
81=== modified file 'DistUpgrade/DistUpgradeQuirks.py'
82--- DistUpgrade/DistUpgradeQuirks.py 2017-07-13 22:49:22 +0000
83+++ DistUpgrade/DistUpgradeQuirks.py 2018-07-06 17:47:44 +0000
84@@ -60,8 +60,6 @@
85 self.arch = get_arch()
86 self.plugin_manager = PluginManager(self.controller, ["./plugins"])
87 self._poke = None
88- self._uid = ''
89- self._user_env = {}
90
91 # the quirk function have the name:
92 # $Name (e.g. PostUpgrade)
93@@ -137,7 +135,6 @@
94 self._killKBluetooth()
95 self._killScreensaver()
96 self._pokeScreensaver()
97- self._inhibitIdle()
98 self._stopDocvertConverter()
99
100 # individual quirks handler that run *after* the dist-upgrade was
101@@ -388,7 +385,7 @@
102 def _pokeScreensaver(self):
103 if (os.path.exists("/usr/bin/xdg-screensaver") and
104 os.environ.get('DISPLAY')):
105- logging.debug("setup poke timer for the scrensaver")
106+ logging.debug("setup poke timer for the screensaver")
107 cmd = "while true;"
108 cmd += " do /usr/bin/xdg-screensaver reset >/dev/null 2>&1;"
109 cmd += " sleep 30; done"
110@@ -398,58 +395,6 @@
111 except (OSError, ValueError):
112 logging.exception("failed to setup screensaver poke")
113
114- def _getUserEnv(self):
115- try:
116- pid = subprocess.check_output(["pgrep", "-u", self._uid,
117- "gnome-session"])
118- pid = pid.decode().split('\n')[0]
119- with open('/proc/' + pid + '/environ', 'r') as f:
120- data = f.read().split('\x00')
121- for line in data:
122- if len(line):
123- env = line.split('=', 1)
124- self._user_env[env[0]] = env[1]
125- except subprocess.CalledProcessError as e:
126- if e.returncode == 1:
127- logging.debug("gnome-session not running for user")
128- else:
129- logging.exception("failed to read user env")
130-
131- def _inhibitIdle(self):
132- if os.path.exists("/usr/bin/gnome-session-inhibit"):
133- self._uid = os.environ.get('SUDO_UID', '')
134- if not self._uid:
135- self._uid = os.environ.get('PKEXEC_UID', '')
136- if not self._uid:
137- logging.debug("failed to determine user upgrading")
138- logging.error("failed to inhibit gnome-session idle")
139- return
140- self._getUserEnv()
141- if not self._user_env:
142- return
143- #seteuid so dbus user session can be accessed
144- os.seteuid(int(self._uid))
145-
146- logging.debug("inhibit gnome-session idle")
147- try:
148- xdg_desktop = self._user_env.get("XDG_CURRENT_DESKTOP", "")
149- if not xdg_desktop:
150- logging.debug("failed to find XDG_CURRENT_DESKTOP")
151- logging.error("failed to inhibit gnome-session idle")
152- return
153- xdg_desktop = xdg_desktop.split(':')
154- idle = subprocess.Popen(["gnome-session-inhibit", "--inhibit",
155- "idle", "--inhibit-only"],
156- env=self._user_env)
157- # leave the inhibitor in place on Ubuntu GNOME, since the
158- # lock screen will be broken after upgrade (LP: #1565178)
159- for desktop in xdg_desktop:
160- if "GNOME" not in desktop:
161- atexit.register(idle.terminate)
162- except (OSError, ValueError):
163- logging.exception("failed to inhibit gnome-session idle")
164- os.seteuid(os.getuid())
165-
166 def _stopPokeScreensaver(self):
167 res = False
168 if self._poke is not None:
169
170=== modified file 'debian/changelog'
171--- debian/changelog 2018-06-27 23:34:34 +0000
172+++ debian/changelog 2018-07-06 17:47:44 +0000
173@@ -1,3 +1,13 @@
174+ubuntu-release-upgrader (1:18.10.4) UNRELEASED; urgency=medium
175+
176+ * DistUpgradeQuirks.py, DistUpgradeController.py: move inhibiting of
177+ gnome-session idle so that it is called immediately after the upgrade
178+ starts (LP: #1778817), present a dialog notifying that the lock screen has
179+ been disabled (LP: #1174093), and do not reenable the lock screen as it
180+ may fail to work after a release upgrade. (LP: #1780342)
181+
182+ -- Brian Murray <brian@ubuntu.com> Thu, 05 Jul 2018 16:17:42 -0700
183+
184 ubuntu-release-upgrader (1:18.10.3) cosmic; urgency=medium
185
186 [ Dimitri John Ledkov ]

Subscribers

People subscribed via source and target branches