Merge lp:~jamesodhunt/upstart/bug-881885 into lp:upstart

Proposed by James Hunt
Status: Merged
Merged at revision: 1429
Proposed branch: lp:~jamesodhunt/upstart/bug-881885
Merge into: lp:upstart
Diff against target: 77 lines (+30/-1) (has conflicts)
2 files modified
ChangeLog (+11/-0)
scripts/init-checkconf.sh (+19/-1)
Text conflict in ChangeLog
To merge this branch: bzr merge lp:~jamesodhunt/upstart/bug-881885
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Upstart Reviewers Pending
Review via email: mp+142540@code.launchpad.net

Description of the change

* scripts/init-checkconf.sh:
  - Check copy is successful.
  - Auto-start dbus-launch if not running and command is available (for
    example in non-desktop environments) (LP: #881885).
  - Auto-stop dbus-daemon if we started it.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

I know this is a bash script, but even in bash scripts I would prefer that we always used the form "[ test ] && [ test ]" rather than "[ test -a test ]"; it's more portable in case somebody wants to convert it to portable /bin/sh later, and the parsing rules are so much clearer.

I'd suggest a slightly simpler approach rather than having to manually kill dbus-launch: move the dbus-launch call as far up the script as is practical, and have the script re-exec itself under dbus-launch (i.e. 'exec dbus-launch "$0" "$@"' or similar). dbus-launch will then automatically exit when the script finishes, and the net result should be much less code.

review: Needs Fixing
lp:~jamesodhunt/upstart/bug-881885 updated
1425. By James Hunt

* scripts/init-checkconf.sh: use '&&' rather than '-a' for expression
  grouping to make more portable.

Revision history for this message
James Hunt (jamesodhunt) wrote :

Hi Colin,

Unfortunately, it looks like we can't use your elegant re-exec solution since although dbus-launch correctly exits, it leaves behind a dbus-daemon process. This appears to be 'working as designed' according to the man page, but irritating nonetheless :)

I've updated the script wrt '-a' though.

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-01-21 16:52:57 +0000
3+++ ChangeLog 2013-01-23 14:31:25 +0000
4@@ -1,3 +1,4 @@
5+<<<<<<< TREE
6 2013-01-21 Dmitrijs Ledkovs <xnox@ubuntu.com>
7
8 * init/xdg.[ch]: add xdg_get_cache_home and get_user_log_dir
9@@ -26,6 +27,16 @@
10 directory becomes writeable.
11 (LP: #1096531).
12
13+=======
14+2013-01-09 James Hunt <james.hunt@ubuntu.com>
15+
16+ * scripts/init-checkconf.sh:
17+ - Check copy is successful.
18+ - Auto-start dbus-launch if not running and command is available (for
19+ example in non-desktop environments) (LP: #881885).
20+ - Auto-stop dbus-daemon if we started it.
21+
22+>>>>>>> MERGE-SOURCE
23 2013-01-04 Dmitrijs Ledkovs <xnox@ubuntu.com>
24
25 * init/conf.c: add ability to apply override files from higher
26
27=== modified file 'scripts/init-checkconf.sh'
28--- scripts/init-checkconf.sh 2011-06-06 12:52:08 +0000
29+++ scripts/init-checkconf.sh 2013-01-23 14:31:25 +0000
30@@ -34,6 +34,8 @@
31 file_valid=n
32 running=n
33 check_scripts=y
34+dbus_cmd=dbus-launch
35+started_dbus=n
36
37 cleanup()
38 {
39@@ -44,6 +46,13 @@
40 kill -9 "$upstart_pid" >/dev/null 2>&1
41 fi
42
43+ if [ "$started_dbus" = y ] && [ -n "$DBUS_SESSION_BUS_PID" ]
44+ then
45+ debug "stopping dbus-daemon (running with PID $DBUS_SESSION_BUS_PID)"
46+ kill -0 "$DBUS_SESSION_BUS_PID" >/dev/null 2>&1 && \
47+ kill -9 "$DBUS_SESSION_BUS_PID" >/dev/null 2>&1
48+ fi
49+
50 [ -d "$confdir" ] && rm -rf "$confdir"
51 [ $file_valid = y ] && exit 0
52 exit 1
53@@ -182,7 +191,7 @@
54
55 job="${filename%.conf}"
56
57-cp "$file" "$confdir"
58+cp "$file" "$confdir" || die "failed to copy file $file to $confdir"
59 debug "job=$job"
60
61 upstart_running
62@@ -192,6 +201,15 @@
63 upstart_out="$(mktemp --tmpdir "${script_name}-upstart-output.XXXXXXXXXX")"
64 debug "upstart_out=$upstart_out"
65
66+# auto-start dbus if it isn't already running (required in non-desktop
67+# environments).
68+if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
69+ [ -z "$(which $dbus_cmd)" ] && die "cannot find $dbus_cmd"
70+ eval $($dbus_cmd --auto-syntax)
71+ started_dbus=y
72+ debug "started $dbus_cmd"
73+fi
74+
75 upstart_cmd=$(printf \
76 "%s --session --no-sessions --no-startup-event --verbose --confdir %s" \
77 "$upstart_path" \

Subscribers

People subscribed via source and target branches