[gnome-continuous] Allow connecting to the system bus rather than the session bus



commit 139b0e433aae4ac72736b13281c0b9028cc4f68a
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sat Oct 8 22:19:34 2016 -0400

    Allow connecting to the system bus rather than the session bus
    
    If gnome-continuous is run as a system service, there will be no session
    bus for it to connect to, so add a --bus-type=system option to the
    autobuilder so that it connects to the system bus instead. This
    will require an appropriate file to be dropped into /etc/dbus-1/system.d/.

 src/js/builtins/autobuilder.js |   27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/src/js/builtins/autobuilder.js b/src/js/builtins/autobuilder.js
index 6e29899..086670e 100644
--- a/src/js/builtins/autobuilder.js
+++ b/src/js/builtins/autobuilder.js
@@ -48,6 +48,7 @@ const Autobuilder = new Lang.Class({
 
         this.parser.addArgument('--autoupdate-self', { action: 'store' });
         this.parser.addArgument('--autoupdate-rebuild', { action: 'store' });
+        this.parser.addArgument('--bus-type', { action: 'store' });
 
        this._buildNeeded = true;
        this._initialResolveNeeded = true;
@@ -70,12 +71,25 @@ const Autobuilder = new Lang.Class({
        if (args._autoupdate_rebuild)
                this._autoupdate_rebuild = Gio.File.new_for_path(args._autoupdate_rebuild);
 
-       this._ownId = Gio.DBus.session.own_name('org.gnome.OSTreeBuild', Gio.BusNameOwnerFlags.NONE,
-                                               function(name) {},
-                                               function(name) { loop.quit(); });
+        let bus = None;
+        if (args.bus_type == 'session' || args.bus_type == null) {
+            bus = Gio.DBus.session;
+        } else if (args.bus_type == 'system') {
+            bus = Gio.DBus.system;
+        } else if (args.bus_type != 'none') {
+            throw new Error("Bus type " args.bus_type + " must be one of system, session, or none");
+        }
+
+        if (bus) {
+           this._ownId = bus.own_name('org.gnome.OSTreeBuild', Gio.BusNameOwnerFlags.NONE,
+                                                  function(name) {},
+                                                  function(name) { loop.quit(); });
 
-       this._impl = Gio.DBusExportedObject.wrapJSObject(AutoBuilderIface, this);
-       this._impl.export(Gio.DBus.session, '/org/gnome/OSTreeBuild/AutoBuilder');
+           this._impl = Gio.DBusExportedObject.wrapJSObject(AutoBuilderIface, this);
+           this._impl.export(bus, '/org/gnome/OSTreeBuild/AutoBuilder');
+        } else {
+            this._impl = null;
+        }
 
        this._taskmaster = new Task.TaskMaster(this.workdir);
        this._taskmaster.connect('task-executing', Lang.bind(this, this._onTaskExecuting));
@@ -164,7 +178,8 @@ const Autobuilder = new Lang.Class({
            JsonUtil.writeJsonFileAtomic(statusPath, {'running': runningTasks,
                                                      'queued': queuedTasks,
                                                      'systemLoad': loadAvg}, null);
-           this._impl.emit_property_changed('Status', new GLib.Variant("s", this._status));
+           if (this._impl)
+                this._impl.emit_property_changed('Status', new GLib.Variant("s", this._status));
        }
     },
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]