mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +00:00
Ensure Win service bits only compile on Windows.
This commit is contained in:
parent
45732c99fb
commit
dfbb9446c4
6
btcd.go
6
btcd.go
@ -19,6 +19,10 @@ var (
|
|||||||
shutdownChannel = make(chan bool)
|
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
|
// 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
|
// 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
|
// 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
|
// the return isService flag is true, exit now since we ran as a
|
||||||
// service. Otherwise, just fall through to normal operation.
|
// service. Otherwise, just fall through to normal operation.
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
isService, err := serviceMain()
|
isService, err := winServiceMain()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -43,6 +43,10 @@ var (
|
|||||||
defaultLogFile = filepath.Join(btcdHomeDir, "logs", "btcd.log")
|
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.
|
// config defines the configuration options for btcd.
|
||||||
//
|
//
|
||||||
// See loadConfig for details on the configuration load process.
|
// 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.
|
// Service options which are only added on Windows.
|
||||||
serviceOpts := serviceOptions{}
|
serviceOpts := serviceOptions{}
|
||||||
var runServiceCommand func(string) error
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
runServiceCommand = performServiceCommand
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the home directory if it doesn't already exist.
|
// Create the home directory if it doesn't already exist.
|
||||||
err := os.MkdirAll(btcdHomeDir, 0700)
|
err := os.MkdirAll(btcdHomeDir, 0700)
|
||||||
|
@ -318,3 +318,9 @@ func serviceMain() (bool, error) {
|
|||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set windows specific functions to real functions.
|
||||||
|
func init() {
|
||||||
|
runServiceCommand = performServiceCommand
|
||||||
|
winServiceMain = serviceMain
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user