Ensure Win service bits only compile on Windows.
This commit is contained in:
parent
45732c99fb
commit
dfbb9446c4
3 changed files with 15 additions and 5 deletions
6
btcd.go
6
btcd.go
|
@ -19,6 +19,10 @@ var (
|
|||
shutdownChannel = make(chan bool)
|
||||
)
|
||||
|
||||
// winServiceMain is only invoked on Windows. It detect when btcd is running as
|
||||
// a service and reacts accordingly.
|
||||
var winServiceMain func() (bool, error)
|
||||
|
||||
// btcdMain is the real main function for btcd. It is necessary to work around
|
||||
// the fact that deferred functions do not run when os.Exit() is called. The
|
||||
// optional serverChan parameter is mainly used by the service code to be
|
||||
|
@ -126,7 +130,7 @@ func main() {
|
|||
// the return isService flag is true, exit now since we ran as a
|
||||
// service. Otherwise, just fall through to normal operation.
|
||||
if runtime.GOOS == "windows" {
|
||||
isService, err := serviceMain()
|
||||
isService, err := winServiceMain()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
|
|
|
@ -43,6 +43,10 @@ var (
|
|||
defaultLogFile = filepath.Join(btcdHomeDir, "logs", "btcd.log")
|
||||
)
|
||||
|
||||
// runServiceCommand is only set to a real function on Windows. It is used
|
||||
// to parse and execute service commands specified via the -s flag.
|
||||
var runServiceCommand func(string) error
|
||||
|
||||
// config defines the configuration options for btcd.
|
||||
//
|
||||
// See loadConfig for details on the configuration load process.
|
||||
|
@ -271,10 +275,6 @@ func loadConfig() (*config, []string, error) {
|
|||
|
||||
// Service options which are only added on Windows.
|
||||
serviceOpts := serviceOptions{}
|
||||
var runServiceCommand func(string) error
|
||||
if runtime.GOOS == "windows" {
|
||||
runServiceCommand = performServiceCommand
|
||||
}
|
||||
|
||||
// Create the home directory if it doesn't already exist.
|
||||
err := os.MkdirAll(btcdHomeDir, 0700)
|
||||
|
|
|
@ -318,3 +318,9 @@ func serviceMain() (bool, error) {
|
|||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Set windows specific functions to real functions.
|
||||
func init() {
|
||||
runServiceCommand = performServiceCommand
|
||||
winServiceMain = serviceMain
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue