Merge lp:~ogra/session-manager/posix-rewrite into lp:session-manager

Proposed by Oliver Grawert
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 49
Merged at revision: 45
Proposed branch: lp:~ogra/session-manager/posix-rewrite
Merge into: lp:session-manager
Diff against target: 267 lines (+92/-92)
7 files modified
debian/changelog (+13/-0)
debian/ubuntu-session.install (+1/-0)
ubuntu-session (+66/-92)
ubuntu-session.d/GT-I9100.conf (+3/-0)
ubuntu-session.d/dlx.conf (+3/-0)
ubuntu-session.d/grouper.conf (+3/-0)
ubuntu-session.d/manta.conf (+3/-0)
To merge this branch: bzr merge lp:~ogra/session-manager/posix-rewrite
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+153542@code.launchpad.net

Commit message

posix rewrite and configuration management changes

Description of the change

- complete rewrite of ubuntu-session to comply with Ubuntus usually used POSIX standard
- switch to cyanogenmod device naming
- add support for /etc/ubuntu-session.d/$device.conf configurations to make it easier to add new devices
- make sure processes are killled in reverse order in which they were started
- keep the last ubuntu-session log around for better debugging

To post a comment you must log in.
Revision history for this message
Oliver Grawert (ogra) wrote :

that code was tested on my GT-I9100

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Loïc Minier (lool) wrote :

On Fri, Mar 15, 2013, Oliver Grawert wrote:
> --- ubuntu-session.d/dlx.conf 1970-01-01 00:00:00 +0000
> +++ ubuntu-session.d/dlx.conf 2013-03-15 12:47:33 +0000
> +services="/etc/phone-services"
> +FORM_FACTOR="phone"
>
> --- ubuntu-session.d/grouper.conf 1970-01-01 00:00:00 +0000
> +++ ubuntu-session.d/grouper.conf 2013-03-15 12:47:33 +0000
> +services="/etc/tablet-services"
> +FORM_FACTOR="tablet"
>
> --- ubuntu-session.d/i9100.conf 1970-01-01 00:00:00 +0000
> +++ ubuntu-session.d/i9100.conf 2013-03-15 12:47:33 +0000
> +services="/etc/phone-services"
> +FORM_FACTOR="phone"
>
> --- ubuntu-session.d/manta.conf 1970-01-01 00:00:00 +0000
> +++ ubuntu-session.d/manta.conf 2013-03-15 12:47:33 +0000
> +services="/etc/tablet-services"
> +FORM_FACTOR="tablet"

Seems services= doesn't need to be set each time; just using
/etc/$FORM_FACTOR-services should work?

--
Loïc Minier

46. By Oliver Grawert

instead of using the services variable, rather re-use the FORM_FACTOR

Revision history for this message
Oliver Grawert (ogra) wrote :

thanks, changed ...

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

123 -device=`grep Hardware /proc/cpuinfo | awk '{print $3}'`
124 +device=$(grep ro.cm.device /system/build.prop |sed -e 's/.*=//')

Here we should use ro.product.device instead, as that would also cover people porting the devices based on AOSP or any other !CM based images.

111 +# /proc is is not properly mapped yet, so we need to use ps to find the
112 +# right pid to be able to modify oom_adj
113 +echo $DEFAULT_OOMADJ > /proc/$(pgrep ubuntu-session)/oom_adj

Here we don't need to use ps/pgrep to find the correct pid anymore, so we could something smarter to avoid the possibility of another process called ubuntu-session (that's why the old code was using the entire path). Maybe using $$?

review: Needs Fixing
Revision history for this message
Oliver Grawert (ogra) wrote :

i'm not sure i like the switch to ro.product.device. While you are indeed right that we could more easily support non CM builds i fear that we will find a lot of devices with spaces or special chars (like slashes and brackets) in their naming scheme in that property.

Switching the OOMADJ to $$ now ...

47. By Oliver Grawert

switch OOMADJ pid setting from pgrep to $$

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
48. By Oliver Grawert

move device matching to ro.product.device, drop one obsolete comment, move i9100.conf to GT-I9100.conf

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

121 +device=$(grep ro.product.device /system/build.prop |sed -e 's/.*=//')

This is not a safe check yet as at the nexus based devices we have an additional line at build.prop which breaks the device argument: "# ro.build.product is obsolete; use ro.product.device".

+ grep ro.product.device /system/build.prop
+ device=mako
# ro.build.product is obsolete; use ro.product.device
+ echo Device=mako
# ro.build.product is obsolete; use ro.product.device

Changing to "121 +device=$(grep ^ro.product.device= /system/build.prop |sed -e 's/.*=//')" fixes the issue.

Other than that it works fine, will work to merge it first thing at my morning.

review: Needs Fixing
49. By Oliver Grawert

narrow the pattern matching for ro.product.device so we only pick up values and not comments

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Worked fine, tested with mako, manta, maguro and dlx.

Thanks for the fix, this will improve the porting experience for sure.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2013-03-14 00:19:45 +0000
3+++ debian/changelog 2013-03-21 13:25:25 +0000
4@@ -1,3 +1,16 @@
5+ubuntu-session (0.43) quantal; urgency=low
6+
7+ * rewrite ubuntu-session in distro compliant POSIX, remove all bashisms and
8+ tidy it up a bit
9+ * switch device pattern matching to cyanogenmod device names
10+ * rewrite the kill code so that processes are killed in the reverse order in
11+ which they were started
12+ * move device specific configs to /etc/ubuntu-session.d/$device.conf, so
13+ adding a new device just needs adding of such a conf file
14+ * keep the last ubuntu-session log around
15+
16+ -- Oliver Grawert <ogra@ubuntu.com> Fri, 15 Mar 2013 13:31:45 +0100
17+
18 ubuntu-session (0.42) quantal; urgency=low
19
20 * add support for SMDK4210 (Samsung GT-I9100) to ubuntu-session
21
22=== modified file 'debian/ubuntu-session.install'
23--- debian/ubuntu-session.install 2013-02-06 14:35:26 +0000
24+++ debian/ubuntu-session.install 2013-03-21 13:25:25 +0000
25@@ -3,3 +3,4 @@
26 etc/dbus-1/system.d
27 startup-scripts/* /usr/bin/
28 *.override /etc/init
29+ubuntu-session.d/* /etc/ubuntu-session.d/
30
31=== modified file 'ubuntu-session'
32--- ubuntu-session 2013-03-14 00:19:45 +0000
33+++ ubuntu-session 2013-03-21 13:25:25 +0000
34@@ -1,106 +1,84 @@
35-#!/bin/bash
36+#!/bin/sh
37+
38+set -e
39
40 ################################################################################
41 # Copyright 2012-2013 Canonical Ltd.
42 #
43-# This program is free software: you can redistribute it and/or modify it
44-# under the terms of the GNU General Public License version 3, as published
45+# This program is free software: you can redistribute it and/or modify it
46+# under the terms of the GNU General Public License version 3, as published
47 # by the Free Software Foundation.
48-#
49-# This program is distributed in the hope that it will be useful, but
50-# WITHOUT ANY WARRANTY; without even the implied warranties of
51-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
52+#
53+# This program is distributed in the hope that it will be useful, but
54+# WITHOUT ANY WARRANTY; without even the implied warranties of
55+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
56 # PURPOSE. See the GNU General Public License for more details.
57-#
58-# You should have received a copy of the GNU General Public License along
59+#
60+# You should have received a copy of the GNU General Public License along
61 # with this program. If not, see <http://www.gnu.org/licenses/>.
62 ################################################################################
63
64 export HOME=/home/phablet
65+
66+logdir=$HOME/.ubuntu-session/logs/
67+logfile=$logdir/ubuntu-session.log
68+bashrc=$HOME/.bashrc
69+
70+[ ! -d $logdir ] || mkdir -p $logdir
71+[ -e $logfile ] && cp $logfile $logfile.old
72+
73 echo "Redirecting output to local session logs"
74-exec &> "$HOME/.ubuntu-session/logs/ubuntu-session.log"
75-
76-# Default for any application executed from this script
77-DEFAULT_OOMADJ=-10
78-
79-# /proc is is not properly mapped yet, so we need to use ps to find the
80-# right pid to be able to modify oom_adj
81-procpid=$(ps aux | grep -m 1 /usr/bin/ubuntu-session | awk -F' ' '{print $2}')
82-echo $DEFAULT_OOMADJ > /proc/$procpid/oom_adj
83+exec 3>&1 4>&2 >$logfile 2>&1
84
85 on_stop()
86 {
87 echo "Stopping services..."
88- for pid in "${pids[@]}"
89- do
90- tuple=( $pid )
91- echo "Stopping ${tuple[0]}"
92- kill ${tuple[1]}
93+ for pid in $pids; do
94+ echo -n "Stopping $pid"
95+ if kill $pid >/dev/null 2>&1; then
96+ echo " done"
97+ else
98+ echo " failed"
99+ fi
100 done
101 echo "Killing session bus..."
102 kill ${DBUS_SESSION_BUS_PID}
103 echo "Session stopped."
104 }
105
106+trap on_stop EXIT INT QUIT ILL KILL SEGV TERM
107+
108+# Default for any application executed from this script
109+DEFAULT_OOMADJ=-10
110+echo $DEFAULT_OOMADJ > /proc/$$/oom_adj
111+
112 # Initialize environment
113-for var in $(cat /etc/environment);
114-do
115- export $var;
116+for var in $(cat /etc/environment); do
117+ export $var
118 done
119
120-device=`grep Hardware /proc/cpuinfo | awk '{print $3}'`
121+device=$(grep ^ro.product.device= /system/build.prop |sed -e 's/.*=//')
122 echo "Device=$device"
123
124-if [ "$device" == "Manta" ]; then
125- services="/etc/tablet-services"
126- grep -q GRID_UNIT_PX /home/phablet/.bashrc
127- [ $? -ne 0 ] && echo "export GRID_UNIT_PX=20" >> /home/phablet/.bashrc
128- export GRID_UNIT_PX=20
129- grep -q QTWEBKIT_DPR /home/phablet/.bashrc
130- [ $? -ne 0 ] && echo "export QTWEBKIT_DPR=2.5" >> /home/phablet/.bashrc
131- export QTWEBKIT_DPR=2.5
132- export FORM_FACTOR="tablet"
133-elif [ "$device" == "grouper" ]; then
134- services="/etc/tablet-services"
135- grep -q GRID_UNIT_PX /home/phablet/.bashrc
136- [ $? -ne 0 ] && echo "export GRID_UNIT_PX=14" >> /home/phablet/.bashrc
137- export GRID_UNIT_PX=14
138- grep -q QTWEBKIT_DPR /home/phablet/.bashrc
139- [ $? -ne 0 ] && echo "export QTWEBKIT_DPR=1.3" >> /home/phablet/.bashrc
140- export QTWEBKIT_DPR=1.3
141- export FORM_FACTOR="tablet"
142-elif [ "$device" == "HTC DNA" ]; then
143- services="/etc/phone-services"
144- grep -q GRID_UNIT_PX /home/phablet/.bashrc
145- [ $? -ne 0 ] && echo "export GRID_UNIT_PX=30" >> /home/phablet/.bashrc
146- export GRID_UNIT_PX=30
147- grep -q QTWEBKIT_DPR /home/phablet/.bashrc
148- [ $? -ne 0 ] && echo "export QTWEBKIT_DPR=2.5" >> /home/phablet/.bashrc
149- export QTWEBKIT_DPR=2.5
150- export FORM_FACTOR="phone"
151-elif [ "$device" == "SMDK4210" ]; then
152- services="/etc/phone-services"
153- grep -q GRID_UNIT_PX /home/phablet/.bashrc
154- [ $? -ne 0 ] && echo "export GRID_UNIT_PX=12" >> /home/phablet/.bashrc
155- export GRID_UNIT_PX=12
156- grep -q QTWEBKIT_DPR /home/phablet/.bashrc
157- [ $? -ne 0 ] && echo "export QTWEBKIT_DPR=1.2" >> /home/phablet/.bashrc
158- export QTWEBKIT_DPR=1.2
159- export FORM_FACTOR="phone"
160-else
161- services="/etc/phone-services"
162- grep -q GRID_UNIT_PX /home/phablet/.bashrc
163- [ $? -ne 0 ] && echo "export GRID_UNIT_PX=18" >> /home/phablet/.bashrc
164- export GRID_UNIT_PX=18
165- grep -q QTWEBKIT_DPR /home/phablet/.bashrc
166- [ $? -ne 0 ] && echo "export QTWEBKIT_DPR=2.0" >> /home/phablet/.bashrc
167- export QTWEBKIT_DPR=2.0
168- export FORM_FACTOR="phone"
169-fi
170+# defaults
171+GRID_UNIT_PX=18
172+QTWEBKIT_DPR=2.0
173+FORM_FACTOR="phone"
174+
175+# override defaults by sourcing /etc/ubuntu-session.d/$device.conf
176+[ -e /etc/ubuntu-session.d/$device.conf ] && . /etc/ubuntu-session.d/$device.conf
177+
178+grep -q GRID_UNIT_PX $bashrc || echo "export GRID_UNIT_PX=${GRID_UNIT_PX}" >> $bashrc
179+grep -q QTWEBKIT_DPR $bashrc || echo "export QTWEBKIT_DPR=${QTWEBKIT_DPR}" >> $bashrc
180+
181+export GRID_UNIT_PX=${GRID_UNIT_PX}
182+export QTWEBKIT_DPR=${QTWEBKIT_DPR}
183+export FORM_FACTOR=${FORM_FACTOR}
184+
185
186 if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
187 echo "Starting session bus"
188- export `dbus-launch`
189+ export $(dbus-launch)
190 if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
191 echo "Unable to start session bus"
192 exit 1
193@@ -110,27 +88,23 @@
194 echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}" > $HOME/.dbus-session
195 echo "DBUS_SESSION_BUS_PID=${DBUS_SESSION_BUS_PID}" >> $HOME/.dbus-session
196
197-if [ ! -d "$HOME/.ubuntu-session/logs/" ]; then
198- mkdir -p "$HOME/.ubuntu-session/logs"
199-fi
200-
201 while read service; do
202- service=( $service )
203- arguments=${service[@]:2}
204- service_path=( $(echo "${service[1]}" | tr "/" " ") )
205- binary=${service_path[${#service_path[@]}-1]}
206- sleep ${service[0]}
207- ${service[1]} $arguments &> "$HOME/.ubuntu-session/logs/$binary.log" &
208- pids=("${pids[@]}" "${service[1]} $!")
209- echo "Started ${service[1]} with pid $! (${service[0]} secs start delay)"
210- if [ ${service[1]} == "qml-phone-shell" ]; then
211+ delay=$(echo $service|awk '{print $1}')
212+ command=$(echo $service|awk '{print $2}')
213+ args=$(echo $service|awk '{$1=$2=""; print}'|sed -e 's/^[ \t]*//')
214+
215+ if $(echo $command|grep -q /); then
216+ command=$(basename $command)
217+ fi
218+ sleep $delay
219+ $command $args >"$HOME/.ubuntu-session/logs/$command.log" 2>&1 &
220+ pids="$! $pids"
221+ echo "Started $command with pid $! ($delay secs start delay)"
222+ if [ "$command" = "qml-phone-shell" ]; then
223 shell_pid=$!
224- echo "Got Shell pid = ${shell_pid}"
225+ echo "Got Shell pid = $shell_pid"
226 fi
227-
228-done < "$services"
229-
230-trap 'on_stop' TERM
231+done < /etc/$FORM_FACTOR-services
232
233 wait $shell_pid
234 on_stop
235
236=== added directory 'ubuntu-session.d'
237=== added file 'ubuntu-session.d/GT-I9100.conf'
238--- ubuntu-session.d/GT-I9100.conf 1970-01-01 00:00:00 +0000
239+++ ubuntu-session.d/GT-I9100.conf 2013-03-21 13:25:25 +0000
240@@ -0,0 +1,3 @@
241+GRID_UNIT_PX=12
242+QTWEBKIT_DPR=1.2
243+FORM_FACTOR="phone"
244
245=== added file 'ubuntu-session.d/dlx.conf'
246--- ubuntu-session.d/dlx.conf 1970-01-01 00:00:00 +0000
247+++ ubuntu-session.d/dlx.conf 2013-03-21 13:25:25 +0000
248@@ -0,0 +1,3 @@
249+GRID_UNIT_PX=30
250+QTWEBKIT_DPR=2.5
251+FORM_FACTOR="phone"
252
253=== added file 'ubuntu-session.d/grouper.conf'
254--- ubuntu-session.d/grouper.conf 1970-01-01 00:00:00 +0000
255+++ ubuntu-session.d/grouper.conf 2013-03-21 13:25:25 +0000
256@@ -0,0 +1,3 @@
257+GRID_UNIT_PX=14
258+QTWEBKIT_DPR=1.3
259+FORM_FACTOR="tablet"
260
261=== added file 'ubuntu-session.d/manta.conf'
262--- ubuntu-session.d/manta.conf 1970-01-01 00:00:00 +0000
263+++ ubuntu-session.d/manta.conf 2013-03-21 13:25:25 +0000
264@@ -0,0 +1,3 @@
265+GRID_UNIT_PX=20
266+QTWEBKIT_DPR=2.5
267+FORM_FACTOR="tablet"

Subscribers

People subscribed via source and target branches