cmd/finit: switch to generic receive func
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
parent
ef8fd37e9d
commit
f69e8e753e
@ -1,19 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
init0 "git.ophivana.moe/security/fortify/cmd/finit/ipc"
|
init0 "git.ophivana.moe/security/fortify/cmd/finit/ipc"
|
||||||
"git.ophivana.moe/security/fortify/internal"
|
"git.ophivana.moe/security/fortify/internal"
|
||||||
"git.ophivana.moe/security/fortify/internal/fmsg"
|
"git.ophivana.moe/security/fortify/internal/fmsg"
|
||||||
|
"git.ophivana.moe/security/fortify/internal/proc"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -48,30 +47,24 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup pipe fd from environment
|
// receive setup payload
|
||||||
var setup *os.File
|
var (
|
||||||
if s, ok := os.LookupEnv(init0.Env); !ok {
|
payload init0.Payload
|
||||||
fmsg.Fatal("FORTIFY_INIT not set")
|
closeSetup func() error
|
||||||
panic("unreachable")
|
)
|
||||||
} else {
|
if f, err := proc.Receive(init0.Env, &payload); err != nil {
|
||||||
if fd, err := strconv.Atoi(s); err != nil {
|
if errors.Is(err, proc.ErrInvalid) {
|
||||||
fmsg.Fatalf("cannot parse %q: %v", s, err)
|
fmsg.Fatal("invalid config descriptor")
|
||||||
panic("unreachable")
|
}
|
||||||
} else {
|
if errors.Is(err, proc.ErrNotSet) {
|
||||||
setup = os.NewFile(uintptr(fd), "setup")
|
fmsg.Fatal("FORTIFY_INIT not set")
|
||||||
if setup == nil {
|
|
||||||
fmsg.Fatal("invalid config descriptor")
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var payload init0.Payload
|
fmsg.Fatalf("cannot decode init setup payload: %v", err)
|
||||||
if err := gob.NewDecoder(setup).Decode(&payload); err != nil {
|
|
||||||
fmsg.Fatal("cannot decode init setup payload:", err)
|
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
} else {
|
} else {
|
||||||
fmsg.SetVerbose(payload.Verbose)
|
fmsg.SetVerbose(payload.Verbose)
|
||||||
|
closeSetup = f
|
||||||
|
|
||||||
// child does not need to see this
|
// child does not need to see this
|
||||||
if err = os.Unsetenv(init0.Env); err != nil {
|
if err = os.Unsetenv(init0.Env); err != nil {
|
||||||
@ -98,7 +91,7 @@ func main() {
|
|||||||
fmsg.Suspend()
|
fmsg.Suspend()
|
||||||
|
|
||||||
// close setup pipe as setup is now complete
|
// close setup pipe as setup is now complete
|
||||||
if err := setup.Close(); err != nil {
|
if err := closeSetup(); err != nil {
|
||||||
fmsg.Println("cannot close setup pipe:", err)
|
fmsg.Println("cannot close setup pipe:", err)
|
||||||
// not fatal
|
// not fatal
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user