windows/svc: do not close service handle

The documentation [1] says "The service status handle does not have to
be closed." That makes it seem like it's optional. But actually, closing
it raises a user exception, because it's not a legitimate handle to
close.

This commit also adds the right go build comments with a `go fmt` pass.

[1] https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-registerservicectrlhandlerexa

Change-Id: Ibf67c0e8d94c87068720472009b24cecdfda6519
Reviewed-on: https://go-review.googlesource.com/c/sys/+/357250
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Jason A. Donenfeld
2021-10-20 00:41:20 -06:00
parent 0ec99a608a
commit 25fac919d9
2 changed files with 2 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build windows
// +build windows
package svc

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build windows
// +build windows
// Package svc provides everything required to build Windows service.
@@ -201,7 +202,6 @@ func serviceMain(argc uint32, argv **uint16) uintptr {
theService.h = handle
defer func() {
theService.h = 0
windows.CloseHandle(handle)
}()
var args16 []*uint16
hdr := (*unsafeheader.Slice)(unsafe.Pointer(&args16))