about summary refs log tree commit diff
path: root/nixos/modules/system/activation/switch-to-configuration.pl
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2017-08-12 21:14:36 +0200
committeredef <edef@edef.eu>2018-03-05 12:05:01 -0500
commit2fa1165e89db2c49ccd616a39507c9bdd30c50d2 (patch)
tree6905651ed0fa2cb6a797cf37f53349bec31a74a8 /nixos/modules/system/activation/switch-to-configuration.pl
parente65676d25dd1789b714596e1204891749b45ad1f (diff)
downloadnixlib-2fa1165e89db2c49ccd616a39507c9bdd30c50d2.tar
nixlib-2fa1165e89db2c49ccd616a39507c9bdd30c50d2.tar.gz
nixlib-2fa1165e89db2c49ccd616a39507c9bdd30c50d2.tar.bz2
nixlib-2fa1165e89db2c49ccd616a39507c9bdd30c50d2.tar.lz
nixlib-2fa1165e89db2c49ccd616a39507c9bdd30c50d2.tar.xz
nixlib-2fa1165e89db2c49ccd616a39507c9bdd30c50d2.tar.zst
nixlib-2fa1165e89db2c49ccd616a39507c9bdd30c50d2.zip
switch-to-configuration: use Net::DBus to retrieve the list of units
This resolves the FIXME, and opens up the possibility of using more of
the systemd DBus interface to make things more robust.
Diffstat (limited to 'nixos/modules/system/activation/switch-to-configuration.pl')
-rw-r--r--nixos/modules/system/activation/switch-to-configuration.pl19
1 files changed, 9 insertions, 10 deletions
diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl
index 87a4ab2a586d..2ce04ed5342c 100644
--- a/nixos/modules/system/activation/switch-to-configuration.pl
+++ b/nixos/modules/system/activation/switch-to-configuration.pl
@@ -4,6 +4,7 @@ use strict;
 use warnings;
 use File::Basename;
 use File::Slurp;
+use Net::DBus;
 use Sys::Syslog qw(:standard :macros);
 use Cwd 'abs_path';
 
@@ -67,17 +68,15 @@ EOF
 $SIG{PIPE} = "IGNORE";
 
 sub getActiveUnits {
-    # FIXME: use D-Bus or whatever to query this, since parsing the
-    # output of list-units is likely to break.
-    # Use current version of systemctl binary before daemon is reexeced.
-    my $lines = `LANG= /run/current-system/sw/bin/systemctl list-units --full --no-legend`;
+    my $mgr = Net::DBus->system->get_service("org.freedesktop.systemd1")->get_object("/org/freedesktop/systemd1");
+    my $units = $mgr->ListUnitsByPatterns([], []);
     my $res = {};
-    foreach my $line (split '\n', $lines) {
-        chomp $line;
-        last if $line eq "";
-        $line =~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s/ or next;
-        next if $1 eq "UNIT";
-        $res->{$1} = { load => $2, state => $3, substate => $4 };
+    for my $item (@$units) {
+        my ($id, $description, $load_state, $active_state, $sub_state,
+            $following, $unit_path, $job_id, $job_type, $job_path) = @$item;
+        next unless $following eq '';
+        next if $job_id == 0 and $active_state eq 'inactive';
+        $res->{$id} = { load => $load_state, state => $active_state, substate => $sub_state };
     }
     return $res;
 }