2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 static bool user = false;
26 public string format_time(uint64 time_ns) {
29 Time timestamp = Time.local((time_t) (time_ns / 1000000));
30 return timestamp.format("%a, %d %b %Y %H:%M:%S");
33 public void new_column(TreeView view, int column_id, string title) {
35 col = new TreeViewColumn.with_attributes(title, new CellRendererText(), "text", column_id);
36 col.set_sort_column_id(column_id);
37 view.insert_column(col, -1);
40 public class LeftLabel : Label {
41 public LeftLabel(string? text = null) {
43 set_markup("<b>%s</b>".printf(text));
49 public class RightLabel : WrapLabel {
51 public RightLabel(string? text = null) {
56 public void set_text_or_na(string? text = null) {
57 if (text == null || text == "")
58 set_markup("<i>n/a</i>");
63 public void set_markup_or_na(string? text = null) {
64 if (text == null || text == "")
65 set_markup("<i>n/a</i>");
71 public class MainWindow : Window {
73 private string? current_unit_id;
74 private uint32 current_job_id;
76 private TreeView unit_view;
77 private TreeView job_view;
79 private ListStore unit_model;
80 private ListStore job_model;
82 private Gee.HashMap<string, Unit> unit_map;
84 private Button start_button;
85 private Button stop_button;
86 private Button restart_button;
87 private Button reload_button;
88 private Button cancel_button;
90 private Entry unit_load_entry;
91 private Button unit_load_button;
93 private Button server_snapshot_button;
94 private Button server_reload_button;
96 private Manager manager;
98 private RightLabel unit_id_label;
99 private RightLabel unit_aliases_label;
100 private RightLabel unit_dependency_label;
101 private RightLabel unit_description_label;
102 private RightLabel unit_load_state_label;
103 private RightLabel unit_active_state_label;
104 private RightLabel unit_sub_state_label;
105 private RightLabel unit_fragment_path_label;
106 private RightLabel unit_active_enter_timestamp_label;
107 private RightLabel unit_active_exit_timestamp_label;
108 private RightLabel unit_can_start_label;
109 private RightLabel unit_can_reload_label;
110 private RightLabel unit_cgroup_label;
112 private RightLabel job_id_label;
113 private RightLabel job_state_label;
114 private RightLabel job_type_label;
116 private ComboBox unit_type_combo_box;
117 private CheckButton inactive_checkbox;
119 public MainWindow() throws IOError {
120 title = user ? "systemd User Service Manager" : "systemd System Manager";
121 set_position(WindowPosition.CENTER);
122 set_default_size(1000, 700);
123 set_border_width(12);
124 destroy.connect(Gtk.main_quit);
126 Notebook notebook = new Notebook();
129 Box unit_vbox = new VBox(false, 12);
130 notebook.append_page(unit_vbox, new Label("Units"));
131 unit_vbox.set_border_width(12);
133 Box job_vbox = new VBox(false, 12);
134 notebook.append_page(job_vbox, new Label("Jobs"));
135 job_vbox.set_border_width(12);
137 unit_type_combo_box = new ComboBox.text();
138 Box type_hbox = new HBox(false, 6);
139 type_hbox.pack_start(unit_type_combo_box, false, false, 0);
140 unit_vbox.pack_start(type_hbox, false, false, 0);
142 unit_type_combo_box.append_text("All unit types");
143 unit_type_combo_box.append_text("Targets");
144 unit_type_combo_box.append_text("Services");
145 unit_type_combo_box.append_text("Devices");
146 unit_type_combo_box.append_text("Mounts");
147 unit_type_combo_box.append_text("Automounts");
148 unit_type_combo_box.append_text("Swaps");
149 unit_type_combo_box.append_text("Sockets");
150 unit_type_combo_box.append_text("Paths");
151 unit_type_combo_box.append_text("Timers");
152 unit_type_combo_box.append_text("Snapshots");
153 unit_type_combo_box.set_active(0); // Show All
154 unit_type_combo_box.changed.connect(unit_type_changed);
156 inactive_checkbox = new CheckButton.with_label("inactive too");
157 inactive_checkbox.toggled.connect(unit_type_changed);
158 type_hbox.pack_start(inactive_checkbox, false, false, 0);
160 unit_load_entry = new Entry();
161 unit_load_button = new Button.with_mnemonic("_Load");
162 unit_load_button.set_sensitive(false);
164 unit_load_entry.changed.connect(on_unit_load_entry_changed);
165 unit_load_entry.activate.connect(on_unit_load);
166 unit_load_button.clicked.connect(on_unit_load);
168 Box unit_load_hbox = new HBox(false, 6);
169 unit_load_hbox.pack_start(unit_load_entry, false, true, 0);
170 unit_load_hbox.pack_start(unit_load_button, false, true, 0);
172 server_snapshot_button = new Button.with_mnemonic("Take S_napshot");
173 server_reload_button = new Button.with_mnemonic("Reload _Configuration");
175 server_snapshot_button.clicked.connect(on_server_snapshot);
176 server_reload_button.clicked.connect(on_server_reload);
178 type_hbox.pack_end(server_snapshot_button, false, true, 0);
179 type_hbox.pack_end(server_reload_button, false, true, 0);
180 type_hbox.pack_end(unit_load_hbox, false, true, 24);
182 unit_model = new ListStore(7, typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(Unit));
183 job_model = new ListStore(6, typeof(string), typeof(string), typeof(string), typeof(string), typeof(Job), typeof(uint32));
185 unit_map = new Gee.HashMap<string, Unit>();
187 TreeModelFilter unit_model_filter;
188 unit_model_filter = new TreeModelFilter(unit_model, null);
189 unit_model_filter.set_visible_func(unit_filter);
191 TreeModelSort unit_model_sort = new TreeModelSort.with_model(unit_model_filter);
193 unit_view = new TreeView.with_model(unit_model_sort);
194 job_view = new TreeView.with_model(job_model);
196 unit_view.cursor_changed.connect(unit_changed);
197 job_view.cursor_changed.connect(job_changed);
199 new_column(unit_view, 2, "Load State");
200 new_column(unit_view, 3, "Active State");
201 new_column(unit_view, 4, "Unit State");
202 new_column(unit_view, 0, "Unit");
203 new_column(unit_view, 5, "Job");
205 new_column(job_view, 0, "Job");
206 new_column(job_view, 1, "Unit");
207 new_column(job_view, 2, "Type");
208 new_column(job_view, 3, "State");
210 ScrolledWindow scroll = new ScrolledWindow(null, null);
211 scroll.set_policy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
212 scroll.set_shadow_type(ShadowType.IN);
213 scroll.add(unit_view);
214 unit_vbox.pack_start(scroll, true, true, 0);
216 scroll = new ScrolledWindow(null, null);
217 scroll.set_policy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
218 scroll.set_shadow_type(ShadowType.IN);
219 scroll.add(job_view);
220 job_vbox.pack_start(scroll, true, true, 0);
222 unit_id_label = new RightLabel();
223 unit_aliases_label = new RightLabel();
224 unit_dependency_label = new RightLabel();
225 unit_description_label = new RightLabel();
226 unit_load_state_label = new RightLabel();
227 unit_active_state_label = new RightLabel();
228 unit_sub_state_label = new RightLabel();
229 unit_fragment_path_label = new RightLabel();
230 unit_active_enter_timestamp_label = new RightLabel();
231 unit_active_exit_timestamp_label = new RightLabel();
232 unit_can_start_label = new RightLabel();
233 unit_can_reload_label = new RightLabel();
234 unit_cgroup_label = new RightLabel();
236 job_id_label = new RightLabel();
237 job_state_label = new RightLabel();
238 job_type_label = new RightLabel();
240 unit_dependency_label.set_track_visited_links(false);
241 unit_dependency_label.set_selectable(false);
242 unit_dependency_label.activate_link.connect(on_activate_link);
244 unit_fragment_path_label.set_track_visited_links(false);
246 Table unit_table = new Table(8, 6, false);
247 unit_table.set_row_spacings(6);
248 unit_table.set_border_width(0);
249 unit_vbox.pack_start(unit_table, false, true, 0);
251 Table job_table = new Table(2, 2, false);
252 job_table.set_row_spacings(6);
253 job_table.set_border_width(0);
254 job_vbox.pack_start(job_table, false, true, 0);
256 unit_table.attach(new LeftLabel("Id:"), 0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
257 unit_table.attach(unit_id_label, 1, 6, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
258 unit_table.attach(new LeftLabel("Aliases:"), 0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
259 unit_table.attach(unit_aliases_label, 1, 6, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
260 unit_table.attach(new LeftLabel("Description:"), 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
261 unit_table.attach(unit_description_label, 1, 6, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
262 unit_table.attach(new LeftLabel("Dependencies:"), 0, 1, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
263 unit_table.attach(unit_dependency_label, 1, 6, 3, 4, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
264 unit_table.attach(new LeftLabel("Fragment Path:"), 0, 1, 4, 5, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
265 unit_table.attach(unit_fragment_path_label, 1, 6, 4, 5, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
266 unit_table.attach(new LeftLabel("Control Group:"), 0, 1, 5, 6, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
267 unit_table.attach(unit_cgroup_label, 1, 6, 5, 6, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
269 unit_table.attach(new LeftLabel("Load State:"), 0, 1, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
270 unit_table.attach(unit_load_state_label, 1, 2, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
271 unit_table.attach(new LeftLabel("Active State:"), 0, 1, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
272 unit_table.attach(unit_active_state_label, 1, 2, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
273 unit_table.attach(new LeftLabel("Unit State:"), 0, 1, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
274 unit_table.attach(unit_sub_state_label, 1, 2, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
276 unit_table.attach(new LeftLabel("Active Enter Timestamp:"), 2, 3, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
277 unit_table.attach(unit_active_enter_timestamp_label, 3, 4, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
278 unit_table.attach(new LeftLabel("Active Exit Timestamp:"), 2, 3, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
279 unit_table.attach(unit_active_exit_timestamp_label, 3, 4, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
281 unit_table.attach(new LeftLabel("Can Start/Stop:"), 4, 5, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
282 unit_table.attach(unit_can_start_label, 5, 6, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
283 unit_table.attach(new LeftLabel("Can Reload:"), 4, 5, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
284 unit_table.attach(unit_can_reload_label, 5, 6, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
286 job_table.attach(new LeftLabel("Id:"), 0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
287 job_table.attach(job_id_label, 1, 2, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
288 job_table.attach(new LeftLabel("State:"), 0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
289 job_table.attach(job_state_label, 1, 2, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
290 job_table.attach(new LeftLabel("Type:"), 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
291 job_table.attach(job_type_label, 1, 2, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
293 ButtonBox bbox = new HButtonBox();
294 bbox.set_layout(ButtonBoxStyle.START);
296 unit_vbox.pack_start(bbox, false, true, 0);
298 start_button = new Button.with_mnemonic("_Start");
299 stop_button = new Button.with_mnemonic("Sto_p");
300 reload_button = new Button.with_mnemonic("_Reload");
301 restart_button = new Button.with_mnemonic("Res_tart");
303 start_button.clicked.connect(on_start);
304 stop_button.clicked.connect(on_stop);
305 reload_button.clicked.connect(on_reload);
306 restart_button.clicked.connect(on_restart);
308 bbox.pack_start(start_button, false, true, 0);
309 bbox.pack_start(stop_button, false, true, 0);
310 bbox.pack_start(restart_button, false, true, 0);
311 bbox.pack_start(reload_button, false, true, 0);
313 bbox = new HButtonBox();
314 bbox.set_layout(ButtonBoxStyle.START);
316 job_vbox.pack_start(bbox, false, true, 0);
318 cancel_button = new Button.with_mnemonic("_Cancel");
320 cancel_button.clicked.connect(on_cancel);
322 bbox.pack_start(cancel_button, false, true, 0);
324 manager = Bus.get_proxy_sync(
325 user ? BusType.SESSION : BusType.SYSTEM,
326 "org.freedesktop.systemd1",
327 "/org/freedesktop/systemd1");
329 manager.unit_new.connect(on_unit_new);
330 manager.job_new.connect(on_job_new);
331 manager.unit_removed.connect(on_unit_removed);
332 manager.job_removed.connect(on_job_removed);
338 populate_unit_model();
339 populate_job_model();
342 public void populate_unit_model() throws IOError {
345 var list = manager.list_units();
347 foreach (var i in list) {
350 Properties p = Bus.get_proxy_sync(
351 user ? BusType.SESSION : BusType.SYSTEM,
352 "org.freedesktop.systemd1",
355 p.properties_changed.connect(on_unit_changed);
357 Unit u = Bus.get_proxy_sync(
358 user ? BusType.SESSION : BusType.SYSTEM,
359 "org.freedesktop.systemd1",
364 unit_model.append(out iter);
371 5, i.job_type != "" ? "→ %s".printf(i.job_type) : "",
376 public void populate_job_model() throws IOError {
379 var list = manager.list_jobs();
381 foreach (var i in list) {
384 Properties p = Bus.get_proxy_sync(
385 user ? BusType.SESSION : BusType.SYSTEM,
386 "org.freedesktop.systemd1",
389 p.properties_changed.connect(on_job_changed);
391 Job j = Bus.get_proxy_sync(
392 user ? BusType.SESSION : BusType.SYSTEM,
393 "org.freedesktop.systemd1",
396 job_model.append(out iter);
398 0, "%u".printf(i.id),
400 2, "→ %s".printf(i.type),
407 public Unit? get_current_unit() {
409 unit_view.get_cursor(out p, null);
414 TreeModel model = unit_view.get_model();
418 model.get_iter(out iter, p);
419 model.get(iter, 6, out u);
424 public Unit? get_unit(string id) {
425 return this.unit_map[id];
428 public void unit_changed() {
429 Unit u = get_current_unit();
437 public void clear_unit() {
438 current_unit_id = null;
440 start_button.set_sensitive(false);
441 stop_button.set_sensitive(false);
442 reload_button.set_sensitive(false);
443 restart_button.set_sensitive(false);
445 unit_id_label.set_text_or_na();
446 unit_aliases_label.set_text_or_na();
447 unit_description_label.set_text_or_na();
448 unit_description_label.set_text_or_na();
449 unit_load_state_label.set_text_or_na();
450 unit_active_state_label.set_text_or_na();
451 unit_sub_state_label.set_text_or_na();
452 unit_fragment_path_label.set_text_or_na();
453 unit_active_enter_timestamp_label.set_text_or_na();
454 unit_active_exit_timestamp_label.set_text_or_na();
455 unit_can_reload_label.set_text_or_na();
456 unit_can_start_label.set_text_or_na();
457 unit_cgroup_label.set_text_or_na();
460 public string make_dependency_string(string? prefix, string word, string[] dependencies) {
469 foreach (string i in dependencies) {
471 r += first ? "\n" : ",";
478 r += " <a href=\"" + i + "\">" + i + "</a>";
484 public void show_unit(Unit unit) {
485 current_unit_id = unit.id;
487 unit_id_label.set_text_or_na(current_unit_id);
490 foreach (string i in unit.names) {
491 if (i == current_unit_id)
500 unit_aliases_label.set_text_or_na(a);
503 requires = unit.requires,
504 requires_overridable = unit.requires_overridable,
505 requisite = unit.requisite,
506 requisite_overridable = unit.requisite_overridable,
508 required_by = unit.required_by,
509 required_by_overridable = unit.required_by_overridable,
510 wanted_by = unit.wanted_by,
511 conflicts = unit.conflicts,
512 before = unit.before,
515 unit_dependency_label.set_markup_or_na(
516 make_dependency_string(
517 make_dependency_string(
518 make_dependency_string(
519 make_dependency_string(
520 make_dependency_string(
521 make_dependency_string(
522 make_dependency_string(
523 make_dependency_string(
524 make_dependency_string(
525 make_dependency_string(
526 make_dependency_string(null,
527 "requires", requires),
528 "overridable requires", requires_overridable),
529 "requisite", requisite),
530 "overridable requisite", requisite_overridable),
532 "conflicts", conflicts),
533 "required by", required_by),
534 "overridable required by", required_by_overridable),
535 "wanted by", wanted_by),
539 unit_description_label.set_text_or_na(unit.description);
540 unit_load_state_label.set_text_or_na(unit.load_state);
541 unit_active_state_label.set_text_or_na(unit.active_state);
542 unit_sub_state_label.set_text_or_na(unit.sub_state);
544 string fp = unit.fragment_path;
546 unit_fragment_path_label.set_markup_or_na("<a href=\"file://" + fp +"\">" + fp + "</a>" );
548 unit_fragment_path_label.set_text_or_na();
551 unit_active_enter_timestamp_label.set_text_or_na(format_time(unit.active_enter_timestamp));
553 unit_active_exit_timestamp_label.set_text_or_na(format_time(unit.active_exit_timestamp));
555 bool b = unit.can_start;
556 start_button.set_sensitive(b);
557 stop_button.set_sensitive(b);
558 restart_button.set_sensitive(b);
559 unit_can_start_label.set_text_or_na(b ? "Yes" : "No");
562 reload_button.set_sensitive(b);
563 unit_can_reload_label.set_text_or_na(b ? "Yes" : "No");
565 unit_cgroup_label.set_text_or_na(unit.default_control_group);
568 public Job? get_current_job() {
570 job_view.get_cursor(out p, null);
576 TreeModel model = job_view.get_model();
579 model.get_iter(out iter, p);
580 model.get(iter, 4, out j);
585 public void job_changed() {
586 Job j = get_current_job();
594 public void clear_job() {
597 job_id_label.set_text_or_na();
598 job_state_label.set_text_or_na();
599 job_type_label.set_text_or_na();
601 cancel_button.set_sensitive(false);
604 public void show_job(Job job) {
605 current_job_id = job.id;
607 job_id_label.set_text_or_na("%u".printf(current_job_id));
608 job_state_label.set_text_or_na(job.state);
609 job_type_label.set_text_or_na(job.job_type);
611 cancel_button.set_sensitive(true);
614 public void on_start() {
615 Unit u = get_current_unit();
622 } catch (IOError e) {
623 show_error(e.message);
627 public void on_stop() {
628 Unit u = get_current_unit();
635 } catch (IOError e) {
636 show_error(e.message);
640 public void on_reload() {
641 Unit u = get_current_unit();
648 } catch (IOError e) {
649 show_error(e.message);
653 public void on_restart() {
654 Unit u = get_current_unit();
660 u.restart("replace");
661 } catch (IOError e) {
662 show_error(e.message);
666 public void on_cancel() {
667 Job j = get_current_job();
674 } catch (IOError e) {
675 show_error(e.message);
679 public void update_unit_iter(TreeIter iter, string id, Unit u) {
683 Unit.JobLink jl = u.job;
686 Job j = Bus.get_proxy_sync(
687 user ? BusType.SESSION : BusType.SYSTEM,
688 "org.freedesktop.systemd1",
700 5, t != "" ? "→ %s".printf(t) : "",
702 } catch (IOError e) {
703 show_error(e.message);
707 public void on_unit_new(string id, ObjectPath path) {
710 Properties p = Bus.get_proxy_sync(
711 user ? BusType.SESSION : BusType.SYSTEM,
712 "org.freedesktop.systemd1",
715 p.properties_changed.connect(on_unit_changed);
718 unit_model.append(out iter);
720 Unit u = Bus.get_proxy_sync(
721 user ? BusType.SESSION : BusType.SYSTEM,
722 "org.freedesktop.systemd1",
727 update_unit_iter(iter, id, u);
728 } catch (IOError e) {
729 show_error(e.message);
733 public void update_job_iter(TreeIter iter, uint32 id, Job j) {
737 2, "→ %s".printf(j.job_type),
743 public void on_job_new(uint32 id, ObjectPath path) {
747 Properties p = Bus.get_proxy_sync(
748 user ? BusType.SESSION : BusType.SYSTEM,
749 "org.freedesktop.systemd1",
752 p.properties_changed.connect(on_job_changed);
755 job_model.append(out iter);
757 Job j = Bus.get_proxy_sync(
758 user ? BusType.SESSION : BusType.SYSTEM,
759 "org.freedesktop.systemd1",
762 update_job_iter(iter, id, j);
764 } catch (IOError e) {
765 show_error(e.message);
769 public void on_unit_removed(string id, ObjectPath path) {
771 if (!(unit_model.get_iter_first(out iter)))
777 unit_model.get(iter, 0, out name);
780 if (current_unit_id == name)
783 unit_model.remove(iter);
787 } while (unit_model.iter_next(ref iter));
792 public void on_job_removed(uint32 id, ObjectPath path, string res) {
794 if (!(job_model.get_iter_first(out iter)))
800 job_model.get(iter, 5, out j);
803 if (current_job_id == j)
806 job_model.remove(iter);
811 } while (job_model.iter_next(ref iter));
814 public void on_unit_changed(Properties p, string iface, HashTable<string, Value?> changed_properties, string[] invalidated_properties) {
820 Unit u = Bus.get_proxy_sync(
821 user ? BusType.SESSION : BusType.SYSTEM,
823 p.get_object_path());
825 if (!(unit_model.get_iter_first(out iter)))
833 unit_model.get(iter, 0, out name);
836 update_unit_iter(iter, id, u);
838 if (current_unit_id == id)
844 } while (unit_model.iter_next(ref iter));
846 } catch (IOError e) {
847 show_error(e.message);
851 public void on_job_changed(Properties p, string iface, HashTable<string, Value?> changed_properties, string[] invalidated_properties) {
856 Job j = Bus.get_proxy_sync(
857 user ? BusType.SESSION : BusType.SYSTEM,
859 p.get_object_path());
861 if (!(job_model.get_iter_first(out iter)))
869 job_model.get(iter, 5, out k);
872 update_job_iter(iter, id, j);
874 if (current_job_id == id)
880 } while (job_model.iter_next(ref iter));
882 } catch (IOError e) {
883 show_error(e.message);
887 public bool unit_filter(TreeModel model, TreeIter iter) {
888 string id, active_state, job;
890 model.get(iter, 0, out id, 3, out active_state, 5, out job);
895 if (!inactive_checkbox.get_active()
896 && active_state == "inactive" && job == "")
899 switch (unit_type_combo_box.get_active()) {
903 return id.has_suffix(".target");
905 return id.has_suffix(".service");
907 return id.has_suffix(".device");
909 return id.has_suffix(".mount");
911 return id.has_suffix(".automount");
913 return id.has_suffix(".swap");
915 return id.has_suffix(".socket");
917 return id.has_suffix(".path");
919 return id.has_suffix(".timer");
921 return id.has_suffix(".snapshot");
928 public void unit_type_changed() {
929 TreeModelFilter model = (TreeModelFilter) ((TreeModelSort) unit_view.get_model()).get_model();
934 public void on_server_reload() {
937 } catch (IOError e) {
938 show_error(e.message);
942 public void on_server_snapshot() {
944 manager.create_snapshot();
946 if (unit_type_combo_box.get_active() != 0)
947 unit_type_combo_box.set_active(8);
949 } catch (IOError e) {
950 show_error(e.message);
954 public void on_unit_load() {
955 string t = unit_load_entry.get_text();
961 var path = manager.load_unit(t);
963 Unit u = Bus.get_proxy_sync(
964 user ? BusType.SESSION : BusType.SYSTEM,
965 "org.freedesktop.systemd1",
968 var m = new MessageDialog(this,
969 DialogFlags.DESTROY_WITH_PARENT,
972 "Unit available as id %s", u.id);
978 } catch (IOError e) {
979 show_error(e.message);
983 public void on_unit_load_entry_changed() {
984 unit_load_button.set_sensitive(unit_load_entry.get_text() != "");
987 public bool on_activate_link(string uri) {
990 string path = manager.get_unit(uri);
992 Unit u = Bus.get_proxy_sync(
993 user ? BusType.SESSION : BusType.SYSTEM,
994 "org.freedesktop.systemd1",
998 } catch (IOError e) {
999 show_error(e.message);
1005 public void show_error(string e) {
1006 var m = new MessageDialog(this,
1007 DialogFlags.DESTROY_WITH_PARENT,
1009 ButtonsType.CLOSE, "%s", e);
1017 static const OptionEntry entries[] = {
1018 { "user", 0, 0, OptionArg.NONE, out user, "Connect to user service manager", null },
1019 { "system", 0, OptionFlags.REVERSE, OptionArg.NONE, out user, "Connect to system manager", null },
1023 void show_error(string e) {
1024 var m = new MessageDialog(null, 0, MessageType.ERROR, ButtonsType.CLOSE, "%s", e);
1029 int main(string[] args) {
1032 Gtk.init_with_args(ref args, "[OPTION...]", entries, "systemadm");
1034 MainWindow window = new MainWindow();
1038 } catch (IOError e) {
1039 show_error(e.message);
1040 } catch (GLib.Error e) {
1041 stderr.printf("%s\n", e.message);