Browse Source

cmd/dockerd: replace deprecated windows.IsAnInteractiveSession()

The `IsAnInteractiveSession` was deprecated, and `IsWindowsService` is marked
as the recommended replacement.

For details, see https://github.com/golang/sys/commit/280f808b4a5303f80a30dd9dc62f9a042d992ad0

> CL 244958 includes isWindowsService function that determines if a
> process is running as a service. The code of the function is based on
> public .Net implementation.
>
> IsAnInteractiveSession function implements similar functionality, but
> is based on an old Stackoverflow post., which is not as authoritative
> as code written by Microsoft for their official product.
>
> This change copies CL 244958 isWindowsService function into svc package
> and makes it public. The intention is that future users will prefer
> IsWindowsService to IsAnInteractiveSession.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit ffcddc908e3861b59c3f24b85cf8bb1dd5b4e6c3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 years ago
parent
commit
0c66bc948a
1 changed files with 6 additions and 5 deletions
  1. 6 5
      cmd/dockerd/service_windows.go

+ 6 - 5
cmd/dockerd/service_windows.go

@@ -264,7 +264,8 @@ func initService(daemonCli *DaemonCli) (bool, bool, error) {
 		return false, false, nil
 	}
 
-	interactive, err := svc.IsAnInteractiveSession()
+	// Check if we're running as a Windows service or interactively.
+	isService, err := svc.IsWindowsService()
 	if err != nil {
 		return false, false, err
 	}
@@ -276,7 +277,7 @@ func initService(daemonCli *DaemonCli) (bool, bool, error) {
 	}
 
 	var log *eventlog.Log
-	if !interactive {
+	if isService {
 		log, err = eventlog.Open(*flServiceName)
 		if err != nil {
 			return false, false, err
@@ -288,10 +289,10 @@ func initService(daemonCli *DaemonCli) (bool, bool, error) {
 
 	service = h
 	go func() {
-		if interactive {
-			err = debug.Run(*flServiceName, h)
-		} else {
+		if isService {
 			err = svc.Run(*flServiceName, h)
+		} else {
+			err = debug.Run(*flServiceName, h)
 		}
 
 		h.fromsvc <- err