Compare commits

...

2 Commits

Author SHA1 Message Date
51e4774bb2 stuff 2025-10-09 23:33:00 -07:00
8da229bf39 stuff 2025-10-09 23:32:39 -07:00
2 changed files with 67 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module gitea.narnian.us/lordwelch/Podman
go 1.25.2

64
main.go Normal file
View File

@ -0,0 +1,64 @@
package Podman
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"os/signal"
"path/filepath"
"regexp"
"strconv"
"strings"
"syscall"
)
func Run(args ...string) error {
podman := exec.Command("/user/podman", args...)
podman.Env = append(os.Environ(), "TMPDIR=/tmp")
podman.Stdin = os.Stdin
podman.Stdout = os.Stdout
podman.Stderr = os.Stderr
exit := make(chan os.Signal, 1)
signal.Notify(exit, os.Interrupt, syscall.SIGTERM)
go func() {
podman.Process.Signal(<-exit)
}()
if err := podman.Run(); err != nil {
return fmt.Errorf("%v: %v", podman.Args, err)
}
exit <- os.Interrupt
return nil
}
var numericRe = regexp.MustCompile(`^[0-9]+$`)
func Signal(name string, sig os.Signal) error {
fis, err := ioutil.ReadDir("/proc")
if err != nil {
return err
}
for _, fi := range fis {
if !fi.IsDir() {
continue
}
if !numericRe.MatchString(fi.Name()) {
continue
}
b, err := ioutil.ReadFile(filepath.Join("/proc", fi.Name(), "cmdline"))
if err != nil {
if os.IsNotExist(err) {
continue // process vanished
}
return err
}
if !strings.Contains(string(b), name) {
continue
}
pid, _ := strconv.Atoi(fi.Name()) // already verified to be numeric
p, _ := os.FindProcess(pid)
return p.Signal(sig)
}
return fmt.Errorf("Process not found: %s", name)
}