mirror of
https://github.com/luxfi/vm.git
synced 2026-10-30 15:13:40 +00:00
api/* — all seven service/handler files swap codec/jsonrpc for luxfi/utils/json (Uint32, Uint64, NewCodec, RawMessage). api carries no codec.Manager use; the api types only quote integers for the JSON-RPC boundary. components/index/index.go — codec/wrappers -> luxfi/utils/wrappers. Used only for wrappers.LongLen byte-slice sizing. rpc/runtime/subprocess/linux_stopper.go — drop wrappers.Errs in favor of errors.Join (stdlib since Go 1.20) for the SIGTERM + Wait fan-in. One fewer dependency on a doomed module. vm no longer directly imports any codec/* subpackage. codec is still pulled in indirectly through chains/atomic (Wave 2E, hand-rolled binary marshal already in but go.sum still pins codec) and through the proto/p test fixtures.
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
//go:build linux
|
|
// +build linux
|
|
|
|
// ^ SIGTERM signal is not available on Windows
|
|
// ^ syscall.SysProcAttr only has field Pdeathsig on Linux
|
|
|
|
package subprocess
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os/exec"
|
|
"syscall"
|
|
|
|
"github.com/luxfi/log"
|
|
"github.com/luxfi/vm/rpc/runtime"
|
|
)
|
|
|
|
func NewCmd(path string, args ...string) *exec.Cmd {
|
|
cmd := exec.Command(path, args...)
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{Pdeathsig: syscall.SIGTERM}
|
|
return cmd
|
|
}
|
|
|
|
func stop(ctx context.Context, log log.Logger, cmd *exec.Cmd) {
|
|
waitChan := make(chan error)
|
|
go func() {
|
|
// attempt graceful shutdown
|
|
sigErr := cmd.Process.Signal(syscall.SIGTERM)
|
|
_, waitErr := cmd.Process.Wait()
|
|
waitChan <- errors.Join(sigErr, waitErr)
|
|
close(waitChan)
|
|
}()
|
|
|
|
ctx, cancel := context.WithTimeout(ctx, runtime.DefaultGracefulTimeout)
|
|
defer cancel()
|
|
|
|
select {
|
|
case err := <-waitChan:
|
|
if err == nil {
|
|
log.Debug("subprocess gracefully shutdown")
|
|
} else {
|
|
log.Error("subprocess graceful shutdown failed", "error", err)
|
|
}
|
|
case <-ctx.Done():
|
|
// force kill
|
|
err := cmd.Process.Kill()
|
|
log.Error("subprocess was killed", "error", err)
|
|
}
|
|
}
|