Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add direct run mode #81

Merged
merged 3 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cmd/wsl2host/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import (
"strings"

"github.com/shayne/go-wsl2-host/cmd/wsl2host/internal"
"github.com/shayne/go-wsl2-host/cmd/wsl2host/pkg/service"
"golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/eventlog"
)

func usage(errmsg string) {
fmt.Fprintf(os.Stderr,
"%s\n\n"+
"usage: %s <command>\n"+
" where <command> is one of\n"+
" install, remove, debug, start, stop, pause or continue.\n",
" install, remove, debug, start, stop, pause or continue.\n"+
" run: One-time run and update.\n",
errmsg, os.Args[0])
os.Exit(2)
}
Expand Down Expand Up @@ -53,6 +56,12 @@ func main() {
err = internal.ControlService(svcName, svc.Pause, svc.Paused)
case "continue":
err = internal.ControlService(svcName, svc.Continue, svc.Running)
case "run":
elog, err := eventlog.Open(svcName)
if err != nil {
return
}
err = service.Run(elog)
default:
usage(fmt.Sprintf("invalid command %s", cmd))
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/hostsapi/hostsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ func GetHostIP() (string, error) {
}
// If system language not english, the output not "IP Address". such as in chinese it's "IP 地址".
// And the output no have other such as "IP", so we can only match the "IP".
ipRegex := regexp.MustCompile("IP.*:?\040*(.*)\r\n")
// If need change reglar, make sure the other language is work OK.
// In chinese language os, the output is:
// "\r\n\xbdӿ\xda \"vEthernet (WSL)\" \xb5\xc4\xc5\xe4\xd6\xc3\r\n DHCP \xd2\xd1\xc6\xf4\xd3\xc3: \xb7\xf1\r\n IP \xb5\xd8ַ: 172.18.144.1\r\n \xd7\xd3\xcd\xf8ǰ\u05fa: 172.18.144.0/20 (\xd1\xda\xc2\xeb 255.255.240.0)\r\n InterfaceMetric: 15\r\n\r\n"
ipRegex := regexp.MustCompile("IP.*:? \040*(.*)\r\n")
ipString := ipRegex.FindStringSubmatch(string(out))
if len(ipString) != 2 {
return "", errors.New(`netsh interface ip show address "vEthernet (WSL)"`)
Expand Down