summaryrefslogtreecommitdiffhomepage
path: root/gobgpd
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2017-01-23 11:12:21 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-01-25 06:11:16 -0800
commit671b067a57a9199b0155ad1741b4ebab88a925f8 (patch)
tree749c25ea2b7b218d207773f55965decdf331ba98 /gobgpd
parent1ff6a7300b11519584a545e50216daa346602670 (diff)
fix compile failure on freebsd and windows
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'gobgpd')
-rw-r--r--gobgpd/main.go76
-rw-r--r--gobgpd/util.go103
-rw-r--r--gobgpd/util_windows.go24
3 files changed, 132 insertions, 71 deletions
diff --git a/gobgpd/main.go b/gobgpd/main.go
index 4ee76bd7..68afcb23 100644
--- a/gobgpd/main.go
+++ b/gobgpd/main.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2016 Nippon Telegraph and Telephone Corporation.
+// Copyright (C) 2014-2017 Nippon Telegraph and Telephone Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@ package main
import (
log "github.com/Sirupsen/logrus"
- "github.com/Sirupsen/logrus/hooks/syslog"
"github.com/jessevdk/go-flags"
p "github.com/kr/pretty"
api "github.com/osrg/gobgp/api"
@@ -26,20 +25,17 @@ import (
"github.com/osrg/gobgp/server"
"github.com/osrg/gobgp/table"
"io/ioutil"
- "log/syslog"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
- "runtime/debug"
- "strings"
"syscall"
)
func main() {
sigCh := make(chan os.Signal, 1)
- signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGUSR1)
+ signal.Notify(sigCh, syscall.SIGTERM)
var opts struct {
ConfigFile string `short:"f" long:"config-file" description:"specifying a config file"`
@@ -93,64 +89,8 @@ func main() {
}
if opts.UseSyslog != "" {
- dst := strings.SplitN(opts.UseSyslog, ":", 2)
- network := ""
- addr := ""
- if len(dst) == 2 {
- network = dst[0]
- addr = dst[1]
- }
-
- facility := syslog.Priority(0)
- switch opts.Facility {
- case "kern":
- facility = syslog.LOG_KERN
- case "user":
- facility = syslog.LOG_USER
- case "mail":
- facility = syslog.LOG_MAIL
- case "daemon":
- facility = syslog.LOG_DAEMON
- case "auth":
- facility = syslog.LOG_AUTH
- case "syslog":
- facility = syslog.LOG_SYSLOG
- case "lpr":
- facility = syslog.LOG_LPR
- case "news":
- facility = syslog.LOG_NEWS
- case "uucp":
- facility = syslog.LOG_UUCP
- case "cron":
- facility = syslog.LOG_CRON
- case "authpriv":
- facility = syslog.LOG_AUTHPRIV
- case "ftp":
- facility = syslog.LOG_FTP
- case "local0":
- facility = syslog.LOG_LOCAL0
- case "local1":
- facility = syslog.LOG_LOCAL1
- case "local2":
- facility = syslog.LOG_LOCAL2
- case "local3":
- facility = syslog.LOG_LOCAL3
- case "local4":
- facility = syslog.LOG_LOCAL4
- case "local5":
- facility = syslog.LOG_LOCAL5
- case "local6":
- facility = syslog.LOG_LOCAL6
- case "local7":
- facility = syslog.LOG_LOCAL7
- }
-
- hook, err := logrus_syslog.NewSyslogHook(network, addr, syslog.LOG_INFO|facility, "bgpd")
- if err != nil {
+ if err := addSyslogHook(opts.UseSyslog, opts.Facility); err != nil {
log.Error("Unable to connect to syslog daemon, ", opts.UseSyslog)
- os.Exit(1)
- } else {
- log.AddHook(hook)
}
}
@@ -312,14 +252,8 @@ func main() {
if updatePolicy {
bgpServer.SoftResetIn("", bgp.RouteFamily(0))
}
- case sig := <-sigCh:
- switch sig {
- case syscall.SIGKILL, syscall.SIGTERM:
- bgpServer.Shutdown()
- case syscall.SIGUSR1:
- runtime.GC()
- debug.FreeOSMemory()
- }
+ case <-sigCh:
+ bgpServer.Shutdown()
}
}
}
diff --git a/gobgpd/util.go b/gobgpd/util.go
new file mode 100644
index 00000000..577363d3
--- /dev/null
+++ b/gobgpd/util.go
@@ -0,0 +1,103 @@
+// Copyright (C) 2017 Nippon Telegraph and Telephone Corporation.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// +build !windows
+
+package main
+
+import (
+ "log/syslog"
+ "os"
+ "os/signal"
+ "runtime"
+ "runtime/debug"
+ "strings"
+ "syscall"
+
+ log "github.com/Sirupsen/logrus"
+ "github.com/Sirupsen/logrus/hooks/syslog"
+)
+
+func init() {
+ go func() {
+ sigCh := make(chan os.Signal, 1)
+ signal.Notify(sigCh, syscall.SIGUSR1)
+ for range sigCh {
+ runtime.GC()
+ debug.FreeOSMemory()
+ }
+ }()
+}
+
+func addSyslogHook(host, facility string) error {
+ dst := strings.SplitN(host, ":", 2)
+ network := ""
+ addr := ""
+ if len(dst) == 2 {
+ network = dst[0]
+ addr = dst[1]
+ }
+
+ priority := syslog.Priority(0)
+ switch facility {
+ case "kern":
+ priority = syslog.LOG_KERN
+ case "user":
+ priority = syslog.LOG_USER
+ case "mail":
+ priority = syslog.LOG_MAIL
+ case "daemon":
+ priority = syslog.LOG_DAEMON
+ case "auth":
+ priority = syslog.LOG_AUTH
+ case "syslog":
+ priority = syslog.LOG_SYSLOG
+ case "lpr":
+ priority = syslog.LOG_LPR
+ case "news":
+ priority = syslog.LOG_NEWS
+ case "uucp":
+ priority = syslog.LOG_UUCP
+ case "cron":
+ priority = syslog.LOG_CRON
+ case "authpriv":
+ priority = syslog.LOG_AUTHPRIV
+ case "ftp":
+ priority = syslog.LOG_FTP
+ case "local0":
+ priority = syslog.LOG_LOCAL0
+ case "local1":
+ priority = syslog.LOG_LOCAL1
+ case "local2":
+ priority = syslog.LOG_LOCAL2
+ case "local3":
+ priority = syslog.LOG_LOCAL3
+ case "local4":
+ priority = syslog.LOG_LOCAL4
+ case "local5":
+ priority = syslog.LOG_LOCAL5
+ case "local6":
+ priority = syslog.LOG_LOCAL6
+ case "local7":
+ priority = syslog.LOG_LOCAL7
+ }
+
+ hook, err := logrus_syslog.NewSyslogHook(network, addr, syslog.LOG_INFO|priority, "bgpd")
+ if err != nil {
+ return err
+ }
+ log.AddHook(hook)
+ return nil
+}
diff --git a/gobgpd/util_windows.go b/gobgpd/util_windows.go
new file mode 100644
index 00000000..56c5bc2f
--- /dev/null
+++ b/gobgpd/util_windows.go
@@ -0,0 +1,24 @@
+// Copyright (C) 2017 Nippon Telegraph and Telephone Corporation.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "errors"
+)
+
+func addSyslogHook(_, _ string) error {
+ return errors.New("syslog is not supported on this OS")
+}