using Gtk;
using GLib;
-using DBus;
using Pango;
-static bool session = false;
+static bool user = false;
+
+public string format_time(uint64 time_ns) {
+ if (time_ns <= 0)
+ return "";
+ Time timestamp = Time.local((time_t) (time_ns / 1000000));
+ return timestamp.format("%a, %d %b %Y %H:%M:%S");
+}
+
+public void new_column(TreeView view, int column_id, string title) {
+ TreeViewColumn col;
+ col = new TreeViewColumn.with_attributes(title, new CellRendererText(), "text", column_id);
+ col.set_sort_column_id(column_id);
+ view.insert_column(col, -1);
+}
public class LeftLabel : Label {
public LeftLabel(string? text = null) {
private Button server_snapshot_button;
private Button server_reload_button;
- private Connection bus;
private Manager manager;
private RightLabel unit_id_label;
private RightLabel job_type_label;
private ComboBox unit_type_combo_box;
+ private CheckButton inactive_checkbox;
- public MainWindow() throws DBus.Error {
- title = session ? "systemd Session Manager" : "systemd System Manager";
- position = WindowPosition.CENTER;
+ public MainWindow() throws IOError {
+ title = user ? "systemd User Service Manager" : "systemd System Manager";
+ set_position(WindowPosition.CENTER);
set_default_size(1000, 700);
set_border_width(12);
destroy.connect(Gtk.main_quit);
type_hbox.pack_start(unit_type_combo_box, false, false, 0);
unit_vbox.pack_start(type_hbox, false, false, 0);
- unit_type_combo_box.append_text("Show All Units");
- unit_type_combo_box.append_text("Show Only Live Units");
+ unit_type_combo_box.append_text("Show All");
unit_type_combo_box.append_text("Services");
unit_type_combo_box.append_text("Sockets");
unit_type_combo_box.append_text("Devices");
unit_type_combo_box.append_text("Automounts");
unit_type_combo_box.append_text("Targets");
unit_type_combo_box.append_text("Snapshots");
- unit_type_combo_box.set_active(1);
+ unit_type_combo_box.set_active(0); // Show All
unit_type_combo_box.changed.connect(unit_type_changed);
+ inactive_checkbox = new CheckButton.with_label("inactive too");
+ inactive_checkbox.toggled.connect(unit_type_changed);
+ type_hbox.pack_start(inactive_checkbox, false, false, 0);
+
unit_load_entry = new Entry();
unit_load_button = new Button.with_mnemonic("_Load");
unit_load_button.set_sensitive(false);
unit_model_filter = new TreeModelFilter(unit_model, null);
unit_model_filter.set_visible_func(unit_filter);
- unit_view = new TreeView.with_model(unit_model_filter);
+ TreeModelSort unit_model_sort = new TreeModelSort.with_model(unit_model_filter);
+
+ unit_view = new TreeView.with_model(unit_model_sort);
job_view = new TreeView.with_model(job_model);
unit_view.cursor_changed.connect(unit_changed);
job_view.cursor_changed.connect(job_changed);
- unit_view.insert_column_with_attributes(-1, "Load State", new CellRendererText(), "text", 2);
- unit_view.insert_column_with_attributes(-1, "Active State", new CellRendererText(), "text", 3);
- unit_view.insert_column_with_attributes(-1, "Unit State", new CellRendererText(), "text", 4);
- unit_view.insert_column_with_attributes(-1, "Unit", new CellRendererText(), "text", 0);
- unit_view.insert_column_with_attributes(-1, "Job", new CellRendererText(), "text", 5);
+ new_column(unit_view, 2, "Load State");
+ new_column(unit_view, 3, "Active State");
+ new_column(unit_view, 4, "Unit State");
+ new_column(unit_view, 0, "Unit");
+ new_column(unit_view, 5, "Job");
- job_view.insert_column_with_attributes(-1, "Job", new CellRendererText(), "text", 0);
- job_view.insert_column_with_attributes(-1, "Unit", new CellRendererText(), "text", 1);
- job_view.insert_column_with_attributes(-1, "Type", new CellRendererText(), "text", 2);
- job_view.insert_column_with_attributes(-1, "State", new CellRendererText(), "text", 3);
+ new_column(job_view, 0, "Job");
+ new_column(job_view, 1, "Unit");
+ new_column(job_view, 2, "Type");
+ new_column(job_view, 3, "State");
ScrolledWindow scroll = new ScrolledWindow(null, null);
scroll.set_policy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
bbox.pack_start(cancel_button, false, true, 0);
- bus = DBus.Bus.get(session ? DBus.BusType.SESSION : DBus.BusType.SYSTEM);
-
- manager = bus.get_object(
+ manager = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager") as Manager;
+ "/org/freedesktop/systemd1");
manager.unit_new.connect(on_unit_new);
manager.job_new.connect(on_job_new);
populate_job_model();
}
- public void populate_unit_model() throws DBus.Error {
+ public void populate_unit_model() throws IOError {
unit_model.clear();
var list = manager.list_units();
foreach (var i in list) {
TreeIter iter;
- Properties p = bus.get_object(
+ Properties p = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- i.unit_path,
- "org.freedesktop.DBus.Properties") as Properties;
-
+ i.unit_path);
p.properties_changed.connect(on_unit_changed);
- Unit u = bus.get_object(
+ Unit u = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- i.unit_path,
- "org.freedesktop.systemd1.Unit") as Unit;
+ i.unit_path);
unit_model.append(out iter);
unit_model.set(iter,
}
}
- public void populate_job_model() throws DBus.Error {
+ public void populate_job_model() throws IOError {
job_model.clear();
var list = manager.list_jobs();
foreach (var i in list) {
TreeIter iter;
- Properties p = bus.get_object(
+ Properties p = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- i.job_path,
- "org.freedesktop.DBus.Properties") as Properties;
+ i.job_path);
p.properties_changed.connect(on_job_changed);
- Job j = bus.get_object(
+ Job j = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- i.job_path,
- "org.freedesktop.systemd1.Job") as Job;
+ i.job_path);
job_model.append(out iter);
job_model.set(iter,
else
unit_fragment_path_label.set_text_or_na();
- uint64 t = unit.active_enter_timestamp;
- if (t > 0) {
- Time timestamp = Time.local((time_t) (t / 1000000));
- unit_active_enter_timestamp_label.set_text_or_na(timestamp.format("%a, %d %b %Y %H:%M:%S %z"));
- } else
- unit_active_enter_timestamp_label.set_text_or_na();
- t = unit.active_exit_timestamp;
- if (t > 0) {
- Time timestamp = Time.local((time_t) (t / 1000000));
- unit_active_exit_timestamp_label.set_text_or_na(timestamp.format("%a, %d %b %Y %H:%M:%S %z"));
- } else
- unit_active_exit_timestamp_label.set_text_or_na();
+ unit_active_enter_timestamp_label.set_text_or_na(format_time(unit.active_enter_timestamp));
+
+ unit_active_exit_timestamp_label.set_text_or_na(format_time(unit.active_exit_timestamp));
bool b = unit.can_start;
start_button.set_sensitive(b);
try {
u.start("replace");
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
u.stop("replace");
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
u.reload("replace");
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
u.restart("replace");
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
j.cancel();
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
public void update_unit_iter(TreeIter iter, string id, Unit u) {
- string t = "";
- Unit.JobLink jl = u.job;
+ try {
+ string t = "";
+ Unit.JobLink jl = u.job;
- if (jl.id != 0) {
- Job j = bus.get_object(
- "org.freedesktop.systemd1",
- jl.path,
- "org.freedesktop.systemd1.Job") as Job;
+ if (jl.id != 0) {
+ Job j = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ "org.freedesktop.systemd1",
+ jl.path);
- t = j.job_type;
- }
+ t = j.job_type;
+ }
- unit_model.set(iter,
- 0, id,
- 1, u.description,
- 2, u.load_state,
- 3, u.active_state,
- 4, u.sub_state,
- 5, t != "" ? "→ %s".printf(t) : "",
- 6, u);
+ unit_model.set(iter,
+ 0, id,
+ 1, u.description,
+ 2, u.load_state,
+ 3, u.active_state,
+ 4, u.sub_state,
+ 5, t != "" ? "→ %s".printf(t) : "",
+ 6, u);
+ } catch (IOError e) {
+ show_error(e.message);
+ }
}
public void on_unit_new(string id, ObjectPath path) {
- Properties p = bus.get_object(
- "org.freedesktop.systemd1",
- path,
- "org.freedesktop.DBus.Properties") as Properties;
+ try {
- p.properties_changed.connect(on_unit_changed);
+ Properties p = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ "org.freedesktop.systemd1",
+ path);
- TreeIter iter;
- unit_model.append(out iter);
+ p.properties_changed.connect(on_unit_changed);
- Unit u = bus.get_object(
- "org.freedesktop.systemd1",
- path,
- "org.freedesktop.systemd1.Unit") as Unit;
+ TreeIter iter;
+ unit_model.append(out iter);
+
+ Unit u = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ "org.freedesktop.systemd1",
+ path);
- update_unit_iter(iter, id, u);
+ update_unit_iter(iter, id, u);
+ } catch (IOError e) {
+ show_error(e.message);
+ }
}
public void update_job_iter(TreeIter iter, uint32 id, Job j) {
public void on_job_new(uint32 id, ObjectPath path) {
- Properties p = bus.get_object(
- "org.freedesktop.systemd1",
- path,
- "org.freedesktop.DBus.Properties") as Properties;
+ try {
- p.properties_changed.connect(on_job_changed);
+ Properties p = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ "org.freedesktop.systemd1",
+ path);
- TreeIter iter;
- job_model.append(out iter);
+ p.properties_changed.connect(on_job_changed);
- Job j = bus.get_object(
- "org.freedesktop.systemd1",
- path,
- "org.freedesktop.systemd1.Job") as Job;
+ TreeIter iter;
+ job_model.append(out iter);
+
+ Job j = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ "org.freedesktop.systemd1",
+ path);
+
+ update_job_iter(iter, id, j);
- update_job_iter(iter, id, j);
+ } catch (IOError e) {
+ show_error(e.message);
+ }
}
public void on_unit_removed(string id, ObjectPath path) {
} while (unit_model.iter_next(ref iter));
}
- public void on_job_removed(uint32 id, ObjectPath path, bool success) {
+ public void on_job_removed(uint32 id, ObjectPath path, string res) {
TreeIter iter;
if (!(job_model.get_iter_first(out iter)))
return;
}
public void on_unit_changed(Properties p, string iface, HashTable<string, Value?> changed_properties, string[] invalidated_properties) {
- TreeIter iter;
- string id;
- Unit u = bus.get_object(
- p.get_bus_name(),
- p.get_path(),
- "org.freedesktop.systemd1.Unit") as Unit;
+ try {
+ TreeIter iter;
+ string id;
- if (!(unit_model.get_iter_first(out iter)))
- return;
+ Unit u = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ p.get_name(),
+ p.get_object_path());
- id = u.id;
+ if (!(unit_model.get_iter_first(out iter)))
+ return;
- do {
- string name;
+ id = u.id;
- unit_model.get(iter, 0, out name);
+ do {
+ string name;
- if (id == name) {
- update_unit_iter(iter, id, u);
+ unit_model.get(iter, 0, out name);
- if (current_unit_id == id)
- show_unit(u);
+ if (id == name) {
+ update_unit_iter(iter, id, u);
- break;
- }
+ if (current_unit_id == id)
+ show_unit(u);
- } while (unit_model.iter_next(ref iter));
+ break;
+ }
+
+ } while (unit_model.iter_next(ref iter));
+
+ } catch (IOError e) {
+ show_error(e.message);
+ }
}
public void on_job_changed(Properties p, string iface, HashTable<string, Value?> changed_properties, string[] invalidated_properties) {
- TreeIter iter;
- uint32 id;
+ try {
+ TreeIter iter;
+ uint32 id;
- Job j = bus.get_object(
- p.get_bus_name(),
- p.get_path(),
- "org.freedesktop.systemd1.Job") as Job;
+ Job j = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
+ p.get_name(),
+ p.get_object_path());
- if (!(job_model.get_iter_first(out iter)))
- return;
+ if (!(job_model.get_iter_first(out iter)))
+ return;
- id = j.id;
+ id = j.id;
- do {
- uint32 k;
+ do {
+ uint32 k;
- job_model.get(iter, 5, out k);
+ job_model.get(iter, 5, out k);
- if (id == k) {
- update_job_iter(iter, id, j);
+ if (id == k) {
+ update_job_iter(iter, id, j);
- if (current_job_id == id)
- show_job(j);
+ if (current_job_id == id)
+ show_job(j);
- break;
- }
+ break;
+ }
- } while (job_model.iter_next(ref iter));
+ } while (job_model.iter_next(ref iter));
+
+ } catch (IOError e) {
+ show_error(e.message);
+ }
}
public bool unit_filter(TreeModel model, TreeIter iter) {
if (id == null)
return false;
- switch (unit_type_combo_box.get_active()) {
-
- case 0:
- return true;
-
- case 1:
- return active_state != "inactive" || job != "";
-
- case 2:
- return id.has_suffix(".service");
-
- case 3:
- return id.has_suffix(".socket");
-
- case 4:
- return id.has_suffix(".device");
-
- case 5:
- return id.has_suffix(".mount");
-
- case 6:
- return id.has_suffix(".automount");
-
- case 7:
- return id.has_suffix(".target");
+ if (!inactive_checkbox.get_active()
+ && active_state == "inactive" && job == "")
+ return false;
- case 8:
- return id.has_suffix(".snapshot");
+ switch (unit_type_combo_box.get_active()) {
+ case 0:
+ return true;
+ case 1:
+ return id.has_suffix(".service");
+ case 2:
+ return id.has_suffix(".socket");
+ case 3:
+ return id.has_suffix(".device");
+ case 4:
+ return id.has_suffix(".mount");
+ case 5:
+ return id.has_suffix(".automount");
+ case 6:
+ return id.has_suffix(".target");
+ case 7:
+ return id.has_suffix(".snapshot");
+ default:
+ assert(false);
+ return false;
}
-
- return false;
}
public void unit_type_changed() {
- TreeModelFilter model = (TreeModelFilter) unit_view.get_model();
+ TreeModelFilter model = (TreeModelFilter) ((TreeModelSort) unit_view.get_model()).get_model();
model.refilter();
}
public void on_server_reload() {
try {
manager.reload();
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
if (unit_type_combo_box.get_active() != 0)
unit_type_combo_box.set_active(8);
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
var path = manager.load_unit(t);
- Unit u = bus.get_object(
+ Unit u = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- path,
- "org.freedesktop.systemd1.Unit") as Unit;
+ path);
var m = new MessageDialog(this,
DialogFlags.DESTROY_WITH_PARENT,
m.destroy();
show_unit(u);
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
try {
string path = manager.get_unit(uri);
- Unit u = bus.get_object(
+ Unit u = Bus.get_proxy_sync(
+ user ? BusType.SESSION : BusType.SYSTEM,
"org.freedesktop.systemd1",
- path,
- "org.freedesktop.systemd1.Unit") as Unit;
+ path);
show_unit(u);
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
}
}
static const OptionEntry entries[] = {
- { "session", 0, 0, OptionArg.NONE, out session, "Connect to session bus", null },
- { "system", 0, OptionFlags.REVERSE, OptionArg.NONE, out session, "Connect to system bus", null },
+ { "user", 0, 0, OptionArg.NONE, out user, "Connect to user service manager", null },
+ { "system", 0, OptionFlags.REVERSE, OptionArg.NONE, out user, "Connect to system manager", null },
{ null }
};
m.destroy();
}
-int main (string[] args) {
+int main(string[] args) {
try {
Gtk.init_with_args(ref args, "[OPTION...]", entries, "systemadm");
window.show_all();
Gtk.main();
- } catch (DBus.Error e) {
+ } catch (IOError e) {
show_error(e.message);
} catch (GLib.Error e) {
- show_error(e.message);
+ stderr.printf("%s\n", e.message);
}
return 0;