ignition/0001-stages-files-fix-unit-relabeling-to-exclude-DestDir.patch
2019-03-27 18:27:16 -04:00

78 lines
2.5 KiB
Diff

From 5d57d6107a56fecfe9b6c8bb1a06f2dd1889a7e0 Mon Sep 17 00:00:00 2001
From: Benjamin Gilbert <bgilbert@redhat.com>
Date: Wed, 27 Mar 2019 17:29:15 -0400
Subject: [PATCH] stages/files: fix unit relabeling to exclude DestDir
Non-runtime units and dropins need to be relabeled relative to DestDir,
since relabeling happens in the real root.
e42ecb08f9b5 addressed this for files.
---
internal/exec/stages/files/units.go | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/internal/exec/stages/files/units.go b/internal/exec/stages/files/units.go
index 98c0797..c73141c 100644
--- a/internal/exec/stages/files/units.go
+++ b/internal/exec/stages/files/units.go
@@ -15,7 +15,9 @@
package files
import (
+ "fmt"
"path/filepath"
+ "strings"
"github.com/coreos/ignition/config/v3_0/types"
"github.com/coreos/ignition/internal/distro"
@@ -85,6 +87,14 @@ func (s *stage) writeSystemdUnit(unit types.Unit, runtime bool) error {
s.Logger.Crit("error converting systemd dropin: %v", err)
return err
}
+ relabelPath := f.Node.Path
+ if !runtime {
+ // trim off prefix since this needs to be relative to the sysroot
+ if !strings.HasPrefix(f.Node.Path, s.DestDir) {
+ panic(fmt.Sprintf("Dropin path %s isn't under prefix %s", f.Node.Path, s.DestDir))
+ }
+ relabelPath = f.Node.Path[len(s.DestDir):]
+ }
if err := s.Logger.LogOp(
func() error { return u.PerformFetch(f) },
"writing systemd drop-in %q at %q", dropin.Name, f.Node.Path,
@@ -92,7 +102,7 @@ func (s *stage) writeSystemdUnit(unit types.Unit, runtime bool) error {
return err
}
if !relabeledDropinDir {
- s.relabel(filepath.Dir("/" + f.Node.Path))
+ s.relabel(filepath.Dir(relabelPath))
relabeledDropinDir = true
}
}
@@ -106,13 +116,21 @@ func (s *stage) writeSystemdUnit(unit types.Unit, runtime bool) error {
s.Logger.Crit("error converting unit: %v", err)
return err
}
+ relabelPath := f.Node.Path
+ if !runtime {
+ // trim off prefix since this needs to be relative to the sysroot
+ if !strings.HasPrefix(f.Node.Path, s.DestDir) {
+ panic(fmt.Sprintf("Unit path %s isn't under prefix %s", f.Node.Path, s.DestDir))
+ }
+ relabelPath = f.Node.Path[len(s.DestDir):]
+ }
if err := s.Logger.LogOp(
func() error { return u.PerformFetch(f) },
"writing unit %q at %q", unit.Name, f.Node.Path,
); err != nil {
return err
}
- s.relabel("/" + f.Node.Path)
+ s.relabel(relabelPath)
return nil
}, "processing unit %q", unit.Name)
--
2.20.1