mirror of
https://github.com/golang/sys.git
synced 2026-02-09 04:06:04 +03:00
These were apparently overlooked in CL 357329, CL 294490, CL 296889, and other various updates to this module. (I noticed them via gopls while investigating golang/go#49466.) Updates golang/go#41184 Change-Id: Id042bb6fe5282e6d528e9315acf2ad29d0df58ba Reviewed-on: https://go-review.googlesource.com/c/sys/+/362577 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
// Copyright 2012 The Go Authors. All rights reserved.
|
|
// 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 debug provides facilities to execute svc.Handler on console.
|
|
//
|
|
package debug
|
|
|
|
import (
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/windows/svc"
|
|
)
|
|
|
|
// Run executes service name by calling appropriate handler function.
|
|
// The process is running on console, unlike real service. Use Ctrl+C to
|
|
// send "Stop" command to your service.
|
|
func Run(name string, handler svc.Handler) error {
|
|
cmds := make(chan svc.ChangeRequest)
|
|
changes := make(chan svc.Status)
|
|
|
|
sig := make(chan os.Signal)
|
|
signal.Notify(sig)
|
|
|
|
go func() {
|
|
status := svc.Status{State: svc.Stopped}
|
|
for {
|
|
select {
|
|
case <-sig:
|
|
cmds <- svc.ChangeRequest{Cmd: svc.Stop, CurrentStatus: status}
|
|
case status = <-changes:
|
|
}
|
|
}
|
|
}()
|
|
|
|
_, errno := handler.Execute([]string{name}, cmds, changes)
|
|
if errno != 0 {
|
|
return syscall.Errno(errno)
|
|
}
|
|
return nil
|
|
}
|