Skip to content

Commit

Permalink
Replace deprecated IsAnInteractiveSession() call (#344)
Browse files Browse the repository at this point in the history
Using the service manager from an remote ssh command promt fails
with
`The service process could not connect to the service controller`

Thanks to the detailed analysis from @kelseyma the fix was very straight
forward.
Using IsWindowsService() solved this problem for me.

The mentioned issue at golang/go#44921
has also been fixed in the meantime, so there is no reason not to
use IsWindowsService() instead.

Fixes #300
  • Loading branch information
mpfz0r authored Oct 10, 2022
1 parent 6547573 commit 380dcf8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions service_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ func (l WindowsLogger) NInfof(eventID uint32, format string, a ...interface{}) e
var interactive = false

func init() {
var err error
interactive, err = svc.IsAnInteractiveSession()
isService, err := svc.IsWindowsService()
if err != nil {
panic(err)
}
interactive = !isService
}

func (ws *windowsService) String() string {
Expand Down

1 comment on commit 380dcf8

@adam-mateen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing a regression.
My windows service starts process A.
Process A calls exec.Command() to start process B.
process B does what:
https://github.com/kardianos/service/blob/master/example/simple/main.go
does.

	svcConfig := &service.Config{
		Name:        "GoServiceExampleSimple",
		DisplayName: "Go Service Example",
		Description: "This is an example Go service.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	logger, err = s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}

process B IS NOT an interactive session so the v1.2.1 of this library works fine.
process B IS NOT a windows service, at least not according to this new logic, so v1.2.2 times out starting the service.

I will open an issue for this.

Please sign in to comment.