@@ -173,13 +173,18 @@ sub parseSystemdIni {
173173#
174174# If a directory with the same basename ending in .d exists next to the unit file, it will be
175175# assumed to contain override files which will be parsed as well and handled properly.
176−sub parseUnit {
177− my ($unitPath) = @_;
176+sub parse_unit {
177+ my ($unit_path) = @_;
178178
179179 # Parse the main unit and all overrides
180− my %unitData;
181− parseSystemdIni(\%unitData, $_) for glob("${unitPath}{,.d/*.conf}");
182− return %unitData;
180+ my %unit_data;
181+ # Replace \ with \\ so glob() still works with units that have a \ in them
182+ # Valid characters in unit names are ASCII letters, digits, ":", "-", "_", ".", and "\"
183+ $unit_path =~ s/\\/\\\\/gmsx;
184+ foreach (glob "${unit_path}{,.d/*.conf}") {
185+ parseSystemdIni(\%unit_data, "$_")
186+ }
187+ return %unit_data;
183188}
184189
185190# Checks whether a specified boolean in a systemd unit is true
@@ -310,7 +315,7 @@ sub handleModifiedUnit {
310315 # Revert of the attempt: https://github.com/NixOS/nixpkgs/pull/147609
311316 # More details: https://github.com/NixOS/nixpkgs/issues/74899#issuecomment-981142430
312317 } else {
313− my %unitInfo = $newUnitInfo ? %{$newUnitInfo} : parseUnit($newUnitFile);
318+ my %unitInfo = $newUnitInfo ? %{$newUnitInfo} : parse_unit($newUnitFile);
314319 if (parseSystemdBool(\%unitInfo, "Service", "X-ReloadIfChanged", 0) and not $unitsToRestart->{$unit} and not $unitsToStop->{$unit}) {
315320 $unitsToReload->{$unit} = 1;
316321 recordUnit($reloadListFile, $unit);
@@ -412,12 +417,12 @@ while (my ($unit, $state) = each %{$activePrev}) {
412417
413418 if (-e $prevUnitFile && ($state->{state} eq "active" || $state->{state} eq "activating")) {
414419 if (! -e $newUnitFile || abs_path($newUnitFile) eq "/dev/null") {
415− my %unitInfo = parseUnit($prevUnitFile);
420+ my %unitInfo = parse_unit($prevUnitFile);
416421 $unitsToStop{$unit} = 1 if parseSystemdBool(\%unitInfo, "Unit", "X-StopOnRemoval", 1);
417422 }
418423
419424 elsif ($unit =~ /\.target$/) {
420− my %unitInfo = parseUnit($newUnitFile);
425+ my %unitInfo = parse_unit($newUnitFile);
421426
422427 # Cause all active target units to be restarted below.
423428 # This should start most changed units we stop here as
@@ -451,8 +456,8 @@ while (my ($unit, $state) = each %{$activePrev}) {
451456 }
452457
453458 else {
454− my %old_unit_info = parseUnit($prevUnitFile);
455− my %new_unit_info = parseUnit($newUnitFile);
459+ my %old_unit_info = parse_unit($prevUnitFile);
460+ my %new_unit_info = parse_unit($newUnitFile);
456461 my $diff = compare_units(\%old_unit_info, \%new_unit_info);
457462 if ($diff eq 1) {
458463 handleModifiedUnit($unit, $baseName, $newUnitFile, \%new_unit_info, $activePrev, \%unitsToStop, \%unitsToStart, \%unitsToReload, \%unitsToRestart, \%unitsToSkip);