Skip to content

Commit

Permalink
chore: initial execve
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Dec 12, 2024
1 parent d5bdd40 commit 8b4ccea
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions container/container_reexec1.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"
"path/filepath"
"strconv"
"syscall"

"github.com/nixpig/brownie/filesystem"
"github.com/nixpig/brownie/internal/ipc"
Expand Down Expand Up @@ -96,7 +97,7 @@ func (c *Container) Reexec1(log *zerolog.Logger) error {
log.Info().Msg("waiting for start")
if err := ipc.WaitForMsg(listCh, "start", func() error {
log.Info().Msg("received start")
if err := cmd.Start(); err != nil {
if err := syscall.Exec("/proc/self/exe", []string{"/proc/self/exe", "reexec", "--stage", "2", c.ID()}, c.Spec.Process.Env); err != nil {
log.Error().Err(err).Msg("🔷 failed to start container")
c.SetStatus(specs.StateStopped)
if err := c.Save(); err != nil {
Expand All @@ -105,6 +106,15 @@ func (c *Container) Reexec1(log *zerolog.Logger) error {

return err
}
// if err := cmd.Start(); err != nil {
// log.Error().Err(err).Msg("🔷 failed to start container")
// c.SetStatus(specs.StateStopped)
// if err := c.Save(); err != nil {
// return fmt.Errorf("(start 1) write state file: %w", err)
// }
//
// return err
// }

c.SetStatus(specs.StateRunning)
if err := c.Save(); err != nil {
Expand All @@ -122,9 +132,9 @@ func (c *Container) Reexec1(log *zerolog.Logger) error {
fmt.Println("WARNING: ", err)
}

if err := cmd.Wait(); err != nil {
return fmt.Errorf("waiting for cmd wait in reexec: %w", err)
}
// if err := cmd.Wait(); err != nil {
// return fmt.Errorf("waiting for cmd wait in reexec: %w", err)
// }

return nil
}); err != nil {
Expand Down

0 comments on commit 8b4ccea

Please sign in to comment.