From e4e60525c6d5abc4172eeb7bac3923cbc1f164fa Mon Sep 17 00:00:00 2001 From: Mikita Iwanowski Date: Fri, 3 Jan 2025 16:09:22 +0100 Subject: [PATCH 1/7] fix: cmd runner output reader --- providers/os/connection/device/linux/device_manager.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/providers/os/connection/device/linux/device_manager.go b/providers/os/connection/device/linux/device_manager.go index e880bbf3f9..5890a4b068 100644 --- a/providers/os/connection/device/linux/device_manager.go +++ b/providers/os/connection/device/linux/device_manager.go @@ -6,6 +6,7 @@ package linux import ( "bytes" "fmt" + "io" "os" "path" "path/filepath" @@ -154,8 +155,8 @@ func (d *LinuxDeviceManager) attemptFindFstab(dir string) ([]resources.FstabEntr log.Error().Err(err).Msg("error searching for fstab") return nil, nil } - var out []byte - _, err = cmd.Stdout.Read(out) + + out, err := io.ReadAll(cmd.Stdout) if err != nil { log.Error().Err(err).Msg("error reading find output") return nil, nil From ea711a5aabf1b7ec4fe4d8c3abd208de886bc48d Mon Sep 17 00:00:00 2001 From: Mikita Iwanowski Date: Fri, 3 Jan 2025 17:18:08 +0100 Subject: [PATCH 2/7] expand partitions info: debug log --- providers/os/connection/device/linux/device_manager.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/providers/os/connection/device/linux/device_manager.go b/providers/os/connection/device/linux/device_manager.go index 5890a4b068..310ff55bdc 100644 --- a/providers/os/connection/device/linux/device_manager.go +++ b/providers/os/connection/device/linux/device_manager.go @@ -100,6 +100,8 @@ func (d *LinuxDeviceManager) IdentifyMountTargets(opts map[string]string) ([]*sn } func (d *LinuxDeviceManager) attemptExpandPartitions(partitions []*snapshot.PartitionInfo) ([]*snapshot.PartitionInfo, error) { + log.Debug().Msg("attempting to expand partitions infos") + fstabEntries, err := d.hintFSTypes(partitions) if err != nil { log.Warn().Err(err).Msg("could not find fstab") From 4f19c28af27e314164211080420507bdbfbce336 Mon Sep 17 00:00:00 2001 From: Mikita Iwanowski Date: Mon, 6 Jan 2025 12:55:25 +0100 Subject: [PATCH 3/7] debug: attempt using standard exec --- .../connection/device/linux/device_manager.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/providers/os/connection/device/linux/device_manager.go b/providers/os/connection/device/linux/device_manager.go index 310ff55bdc..d291c2018f 100644 --- a/providers/os/connection/device/linux/device_manager.go +++ b/providers/os/connection/device/linux/device_manager.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "os" + "os/exec" "path" "path/filepath" "sort" @@ -158,6 +159,27 @@ func (d *LinuxDeviceManager) attemptFindFstab(dir string) ([]resources.FstabEntr return nil, nil } + debug := func() { + stderr, err := io.ReadAll(cmd.Stderr) + if err != nil { + log.Error().Err(err). + Int("exit-status", cmd.ExitStatus). + Msg("error reading find stderr") + } else { + log.Warn().Bytes("find-stderr", stderr). + Int("exit-status", cmd.ExitStatus). + Msg("!!! find stderr !!!") + } + + cmd2 := exec.Command("find", dir, "-type", "f", "-wholename", `*/etc/fstab`) + out2, err := cmd2.CombinedOutput() + if err != nil { + log.Error().Err(err).Bytes("find", out2).Msg("error searching for fstab") + } + log.Warn().Bytes("find", out2).Msg("!!! find2 output !!!") + } + defer debug() + out, err := io.ReadAll(cmd.Stdout) if err != nil { log.Error().Err(err).Msg("error reading find output") From 676421654f10b26c2f93a8ecf4ea1e7019dc51dc Mon Sep 17 00:00:00 2001 From: Mikita Iwanowski Date: Mon, 6 Jan 2025 15:06:34 +0100 Subject: [PATCH 4/7] debug: ls --- .../connection/device/linux/device_manager.go | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/providers/os/connection/device/linux/device_manager.go b/providers/os/connection/device/linux/device_manager.go index d291c2018f..9d20464403 100644 --- a/providers/os/connection/device/linux/device_manager.go +++ b/providers/os/connection/device/linux/device_manager.go @@ -177,6 +177,27 @@ func (d *LinuxDeviceManager) attemptFindFstab(dir string) ([]resources.FstabEntr log.Error().Err(err).Bytes("find", out2).Msg("error searching for fstab") } log.Warn().Bytes("find", out2).Msg("!!! find2 output !!!") + + ls := exec.Command("ls", "-la", dir) + out, err := ls.CombinedOutput() + if err != nil { + log.Error().Err(err).Bytes("ls", out).Msg("error listing dir") + } + log.Warn().Bytes("ls", out).Msg("!!! ls output !!!") + + ls = exec.Command("ls", "-la", path.Join(dir, "etc")) + out, err = ls.CombinedOutput() + if err != nil { + log.Error().Err(err).Bytes("ls", out).Msg("error listing dir") + } + log.Warn().Bytes("ls", out).Msg("!!! ls output !!!") + + ls = exec.Command("ls", "-la", path.Join(dir, "root", "etc")) + out, err = ls.CombinedOutput() + if err != nil { + log.Error().Err(err).Bytes("ls", out).Msg("error listing dir") + } + log.Warn().Bytes("ls", out).Msg("!!! ls output !!!") } defer debug() From 0c5fa7549176434b6baa089fd809a5fae5c472d2 Mon Sep 17 00:00:00 2001 From: Mikita Iwanowski Date: Mon, 6 Jan 2025 16:03:24 +0100 Subject: [PATCH 5/7] debug logs --- providers/os/connection/device/linux/device_manager.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/providers/os/connection/device/linux/device_manager.go b/providers/os/connection/device/linux/device_manager.go index 9d20464403..b4d1cf529f 100644 --- a/providers/os/connection/device/linux/device_manager.go +++ b/providers/os/connection/device/linux/device_manager.go @@ -144,6 +144,7 @@ func (d *LinuxDeviceManager) hintFSTypes(partitions []*snapshot.PartitionInfo) ( } if ok := d.attemptFindOSTree(dir, partition); ok { + log.Debug().Str("device", partition.Name).Msg("ostree found") return nil, nil } @@ -228,6 +229,8 @@ func (d *LinuxDeviceManager) attemptFindFstab(dir string) ([]resources.FstabEntr } func (d *LinuxDeviceManager) attemptFindOSTree(dir string, partition *snapshot.PartitionInfo) bool { + log.Debug().Str("device", partition.Name).Msg("attempting to find ostree") + info, err := os.Stat(path.Join(dir, "ostree")) if err != nil { if os.IsNotExist(err) { @@ -239,6 +242,7 @@ func (d *LinuxDeviceManager) attemptFindOSTree(dir string, partition *snapshot.P } if !info.IsDir() { + log.Warn().Str("device", partition.Name).Msg("ostree is not a directory") return false } @@ -255,6 +259,7 @@ func (d *LinuxDeviceManager) attemptFindOSTree(dir string, partition *snapshot.P } if len(matches) == 0 { + log.Debug().Str("device", partition.Name).Msg("no ostree matches") return false } else if len(matches) > 1 { log.Warn().Str("device", partition.Name).Msg("multiple ostree matches") From 5db2c871d528affad22a42509c6ed049278232fb Mon Sep 17 00:00:00 2001 From: Mikita Iwanowski Date: Mon, 6 Jan 2025 16:03:36 +0100 Subject: [PATCH 6/7] fix: pointer receiver --- providers/os/connection/snapshot/partition.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/os/connection/snapshot/partition.go b/providers/os/connection/snapshot/partition.go index 3063db5767..b88ce2465f 100644 --- a/providers/os/connection/snapshot/partition.go +++ b/providers/os/connection/snapshot/partition.go @@ -59,7 +59,7 @@ func (i PartitionInfo) RootDir() string { return path.Join(i.MountPoint, i.bind) } -func (i PartitionInfo) SetBind(bind string) PartitionInfo { +func (i *PartitionInfo) SetBind(bind string) *PartitionInfo { i.bind = bind return i } From bd85bcfcfbbd5e2fe8532ea4d2fbfae19f7e6804 Mon Sep 17 00:00:00 2001 From: Mikita Iwanowski Date: Mon, 6 Jan 2025 16:13:55 +0100 Subject: [PATCH 7/7] cleanup --- .../connection/device/linux/device_manager.go | 43 ------------------- 1 file changed, 43 deletions(-) diff --git a/providers/os/connection/device/linux/device_manager.go b/providers/os/connection/device/linux/device_manager.go index b4d1cf529f..2cc79c35ae 100644 --- a/providers/os/connection/device/linux/device_manager.go +++ b/providers/os/connection/device/linux/device_manager.go @@ -8,7 +8,6 @@ import ( "fmt" "io" "os" - "os/exec" "path" "path/filepath" "sort" @@ -160,48 +159,6 @@ func (d *LinuxDeviceManager) attemptFindFstab(dir string) ([]resources.FstabEntr return nil, nil } - debug := func() { - stderr, err := io.ReadAll(cmd.Stderr) - if err != nil { - log.Error().Err(err). - Int("exit-status", cmd.ExitStatus). - Msg("error reading find stderr") - } else { - log.Warn().Bytes("find-stderr", stderr). - Int("exit-status", cmd.ExitStatus). - Msg("!!! find stderr !!!") - } - - cmd2 := exec.Command("find", dir, "-type", "f", "-wholename", `*/etc/fstab`) - out2, err := cmd2.CombinedOutput() - if err != nil { - log.Error().Err(err).Bytes("find", out2).Msg("error searching for fstab") - } - log.Warn().Bytes("find", out2).Msg("!!! find2 output !!!") - - ls := exec.Command("ls", "-la", dir) - out, err := ls.CombinedOutput() - if err != nil { - log.Error().Err(err).Bytes("ls", out).Msg("error listing dir") - } - log.Warn().Bytes("ls", out).Msg("!!! ls output !!!") - - ls = exec.Command("ls", "-la", path.Join(dir, "etc")) - out, err = ls.CombinedOutput() - if err != nil { - log.Error().Err(err).Bytes("ls", out).Msg("error listing dir") - } - log.Warn().Bytes("ls", out).Msg("!!! ls output !!!") - - ls = exec.Command("ls", "-la", path.Join(dir, "root", "etc")) - out, err = ls.CombinedOutput() - if err != nil { - log.Error().Err(err).Bytes("ls", out).Msg("error listing dir") - } - log.Warn().Bytes("ls", out).Msg("!!! ls output !!!") - } - defer debug() - out, err := io.ReadAll(cmd.Stdout) if err != nil { log.Error().Err(err).Msg("error reading find output")