Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.6] Bug 1933075: backport systemd dropin/units zero-length handling #2435

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion pkg/daemon/daemon.go
Expand Up @@ -1381,7 +1381,24 @@ func checkV3Units(units []ign3types.Unit) error {
for _, u := range units {
for j := range u.Dropins {
path := filepath.Join(pathSystemd, u.Name+".d", u.Dropins[j].Name)
if err := checkFileContentsAndMode(path, []byte(*u.Dropins[j].Contents), defaultFilePermissions); err != nil {

var content string
if u.Dropins[j].Contents == nil {
content = ""
} else {
content = *u.Dropins[j].Contents
}

if _, err := os.Stat(path); content == "" && err != nil {
if os.IsNotExist(err) {
continue
}
return err
}

// To maintain backwards compatibility, we allow existing zero length files to exist.
// Thus we are also ok if the dropin exists but has no content
if err := checkFileContentsAndMode(path, []byte(content), defaultFilePermissions); err != nil {
return err
}
}
Expand Down
17 changes: 16 additions & 1 deletion pkg/daemon/update.go
Expand Up @@ -1304,8 +1304,23 @@ func (dn *Daemon) writeUnits(units []ign3types.Unit) error {
for _, u := range units {
// write the dropin to disk
for i := range u.Dropins {
glog.Infof("Writing systemd unit dropin %q", u.Dropins[i].Name)
dpath := filepath.Join(pathSystemd, u.Name+".d", u.Dropins[i].Name)
if u.Dropins[i].Contents == nil || *u.Dropins[i].Contents == "" {
glog.Infof("Dropin for %s has no content, skipping write", u.Dropins[i].Name)
if _, err := os.Stat(dpath); err != nil {
if os.IsNotExist(err) {
continue
}
return err
}
glog.Infof("Removing %q, updated file has zero length", dpath)
if err := os.Remove(dpath); err != nil {
return err
}
continue
}

glog.Infof("Writing systemd unit dropin %q", u.Dropins[i].Name)
if _, err := os.Stat("/usr" + dpath); err == nil &&
(operatingSystem == MachineConfigDaemonOSRHCOS || operatingSystem == MachineConfigDaemonOSFCOS) {
if err := createOrigFile("/usr"+dpath, dpath); err != nil {
Expand Down