TUN-1158: Windows: use process arguments rather than trivial service arguments

TUN-1158: Fix segfault when carrier test case fails
This commit is contained in:
Nick Vollmar 2018-10-26 15:58:43 -05:00
parent f6014cb2b4
commit 9a48fe959d
2 changed files with 21 additions and 3 deletions

View File

@ -66,11 +66,16 @@ func TestStartServer(t *testing.T) {
defer ts.Close()
go func() {
StartServer(logger, listenerAddress, "http://"+ts.Listener.Addr().String(), shutdownC)
err := StartServer(logger, listenerAddress, "http://"+ts.Listener.Addr().String(), shutdownC)
if err != nil {
t.Fatalf("Error starting server: %v", err)
}
}()
conn, err := net.Dial("tcp", listenerAddress)
assert.NoError(t, err)
if err != nil {
t.Fatalf("Error connecting to server: %v", err)
}
conn.Write([]byte(message))
readBuffer := make([]byte, len(message))

View File

@ -87,7 +87,20 @@ type windowsService struct {
}
// called by the package code at the start of the service
func (s *windowsService) Execute(args []string, r <-chan svc.ChangeRequest, statusChan chan<- svc.Status) (ssec bool, errno uint32) {
func (s *windowsService) Execute(serviceArgs []string, r <-chan svc.ChangeRequest, statusChan chan<- svc.Status) (ssec bool, errno uint32) {
// the arguments passed here are only meaningful if they were manually
// specified by the user, e.g. using the Services console or `sc start`.
// https://docs.microsoft.com/en-us/windows/desktop/services/service-entry-point
// https://stackoverflow.com/a/6235139
var args []string
if len(serviceArgs) > 1 {
args = serviceArgs
} else {
// fall back to the arguments from ImagePath (or, as sc calls it, binPath)
args = os.Args
}
s.elog.Info(1, fmt.Sprintf("%s service arguments: %v", windowsServiceName, args))
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
statusChan <- svc.Status{State: svc.StartPending}
errC := make(chan error)