diff --git a/apps/virtuerl/src/virtuerl_net.erl b/apps/virtuerl/src/virtuerl_net.erl index 868133b..0f264f7 100644 --- a/apps/virtuerl/src/virtuerl_net.erl +++ b/apps/virtuerl/src/virtuerl_net.erl @@ -379,11 +379,6 @@ run_helper(Command, Contents) -> {ok, Val} -> Val; undefined -> "virtuerl_helper" end, - Path = iolist_to_binary(["/tmp/virtuerl/", "helper_", virtuerl_util:uuid4()]), - ok = filelib:ensure_dir(Path), - ok = file:write_file(Path, Contents), - - {ok, HelperOut} = virtuerl_util:cmd(iolist_to_binary([HelperPath, " ", Command, " -f ", Path])), + {ok, HelperOut} = virtuerl_util:cmd(iolist_to_binary([HelperPath, " ", Command, " -f -"]), Contents), ?LOG_DEBUG(#{helper_out => HelperOut}), - file:delete(Path), ok. diff --git a/helper/main.go b/helper/main.go index 39e040a..e0b5738 100644 --- a/helper/main.go +++ b/helper/main.go @@ -24,23 +24,29 @@ func main() { case "ip": ipCmd.Parse(os.Args[2:]) fmt.Printf("ip / %s\n", *ipBatchFile) - cmd := exec.Command("/usr/bin/ip", "-b", *ipBatchFile) - ipOutput, err := cmd.CombinedOutput() - if err != nil { - fmt.Println(string(ipOutput)) - log.Fatal(err) - } + cmd := exec.Command("/usr/bin/ip", "-b", *ipBatchFile) + if *ipBatchFile == "-" { + cmd.Stdin = os.Stdin + } + ipOutput, err := cmd.CombinedOutput() + if err != nil { + fmt.Println(string(ipOutput)) + log.Fatal(err) + } case "nft": nftCmd.Parse(os.Args[2:]) fmt.Printf("nft / %s\n", *nftFile) - cmd := exec.Command("/usr/sbin/nft", "-f", *nftFile) - cmd.SysProcAttr = &syscall.SysProcAttr{} - cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(0), Gid: uint32(0)} - nftOutput, err := cmd.CombinedOutput() - if err != nil { - fmt.Println(string(nftOutput)) - log.Fatal(err) - } + cmd := exec.Command("/usr/sbin/nft", "-f", *nftFile) + if *nftFile == "-" { + cmd.Stdin = os.Stdin + } + cmd.SysProcAttr = &syscall.SysProcAttr{} + cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(0), Gid: uint32(0)} + nftOutput, err := cmd.CombinedOutput() + if err != nil { + fmt.Println(string(nftOutput)) + log.Fatal(err) + } default: fmt.Println(`Expected "ip" or "nft" subcommand`) os.Exit(2)