diff options
author | Přemysl Janouch <p@janouch.name> | 2018-08-06 19:50:53 +0200 |
---|---|---|
committer | Přemysl Janouch <p@janouch.name> | 2018-08-06 19:52:39 +0200 |
commit | e2c34afbc6f1193d2538b7d6e766d42c873347b2 (patch) | |
tree | 3f0b2c89dfdefd8957ebf153eb813d22dea3630b /xS | |
parent | e2c8fb6e33f536384985197675c2ef569b9a6fe2 (diff) | |
download | xK-e2c34afbc6f1193d2538b7d6e766d42c873347b2.tar.gz xK-e2c34afbc6f1193d2538b7d6e766d42c873347b2.tar.xz xK-e2c34afbc6f1193d2538b7d6e766d42c873347b2.zip |
hid: move off of the log package
We don't spam with useless messages without -debug any longer.
Diffstat (limited to 'xS')
-rw-r--r-- | xS/main.go | 66 |
1 files changed, 32 insertions, 34 deletions
@@ -27,7 +27,6 @@ import ( "fmt" "io" "io/ioutil" - "log" "log/syslog" "net" "os" @@ -259,9 +258,7 @@ func findTildeHome(username string) string { } else if v, ok := os.LookupEnv("HOME"); ok { return v } - if debugMode { - log.Printf("failed to expand the home directory for %s", username) - } + printDebug("failed to expand the home directory for %s", username) return "~" + username } @@ -396,10 +393,10 @@ func callSimpleConfigWriteDefault(pathHint string, table []simpleConfigItem) { path, err := simpleConfigWriteDefault( pathHint, strings.Join(prologLines, "\n"), table) if err != nil { - log.Fatalln(err) + exitFatal("%s", err) } - log.Printf("configuration written to `%s'\n", path) + printStatus("configuration written to `%s'", path) } // --- Configuration ----------------------------------------------------------- @@ -891,10 +888,10 @@ var ( // Forcefully tear down all connections. func forceQuit(reason string) { if !quitting { - log.Fatalln("forceQuit called without initiateQuit") + exitFatal("forceQuit called without initiateQuit") } - log.Printf("forced shutdown (%s)\n", reason) + printStatus("forced shutdown (%s)", reason) for c := range clients { // initiateQuit has already unregistered the client. c.kill("Shutting down") @@ -903,10 +900,10 @@ func forceQuit(reason string) { // Initiate a clean shutdown of the whole daemon. func initiateQuit() { - log.Println("shutting down") + printStatus("shutting down") for _, ln := range listeners { if err := ln.Close(); err != nil { - log.Println(err) + printError("%s", err) } } for c := range clients { @@ -1057,7 +1054,8 @@ func (c *client) kill(reason string) { c.unregister(reason) // TODO: Log the address; seems like we always have c.address. - log.Println("client destroyed") + // In fact, do it in most debug logs, could be a method of client. + printDebug("client destroyed") // Try to send a "close notify" alert if the TLS object is ready, // otherwise just tear down the transport. @@ -2956,7 +2954,7 @@ func (c *client) onPrepared(host string, isTLS bool) { c.tls = tls.Server(c.transport, tlsConf) c.conn = c.tls } else { - log.Printf("could not initialize TLS for %s: TLS support disabled\n", + printDebug("could not initialize TLS for %s: TLS support disabled", c.address) c.kill("TLS support disabled") return @@ -2990,10 +2988,10 @@ func (c *client) onRead(data []byte, readErr error) { // XXX: And since it accepts LF, we miscalculate receivedBytes within. c.recvQ = c.recvQ[advance:] line := string(token) - log.Printf("-> %s\n", line) + printDebug("-> %s", line) if msg := ircParseMessage(line); msg == nil { - log.Println("error: invalid line") + printDebug("error: invalid line") } else { ircProcessMessage(c, msg, line) } @@ -3003,18 +3001,18 @@ func (c *client) onRead(data []byte, readErr error) { c.reading = false if readErr != io.EOF { - log.Println(readErr) + printDebug("%s", readErr) c.kill(readErr.Error()) } else if c.closing { // Disregarding whether a clean shutdown has happened or not. - log.Println("client finished shutdown") - c.kill("TODO") + printDebug("client finished shutdown") + c.kill("") } else { - log.Println("client EOF") + printDebug("client EOF") c.closeLink("") } } else if len(c.recvQ) > 8192 { - log.Println("client recvQ overrun") + printDebug("client recvQ overrun") c.closeLink("recvQ overrun") // tls.Conn doesn't have the CloseRead method (and it needs to be able @@ -3039,7 +3037,7 @@ func (c *client) onWrite(written int, writeErr error) { c.writing = false if writeErr != nil { - log.Println(writeErr) + printDebug("%s", writeErr) c.kill(writeErr.Error()) } else if len(c.sendQ) > 0 { c.flushSendQ() @@ -3047,7 +3045,7 @@ func (c *client) onWrite(written int, writeErr error) { if c.reading { c.conn.CloseWrite() } else { - c.kill("TODO") + c.kill("") } } } @@ -3066,9 +3064,9 @@ func accept(ln net.Listener) { return } if op, ok := err.(net.Error); !ok || !op.Temporary() { - log.Fatalln(err) + exitFatal("%s", err) } else { - log.Println(err) + printError("%s", err) } } else { // TCP_NODELAY is set by default on TCPConns. @@ -3082,7 +3080,7 @@ func prepare(client *client) { host, _, err := net.SplitHostPort(conn.RemoteAddr().String()) if err != nil { // In effect, we require TCP/UDP, as they have port numbers. - log.Fatalln(err) + exitFatal("%s", err) } // The Cgo resolver doesn't pthread_cancel getnameinfo threads, so not @@ -3091,7 +3089,7 @@ func prepare(client *client) { go func() { defer close(ch) if names, err := net.LookupAddr(host); err != nil { - log.Println(err) + printError("%s", err) } else { ch <- names[0] } @@ -3111,7 +3109,7 @@ func prepare(client *client) { isTLS := false if sysconn, err := conn.(syscall.Conn).SyscallConn(); err != nil { // This is just for the TLS detection and doesn't need to be fatal. - log.Println(err) + printError("%s", err) } else { isTLS = detectTLS(sysconn) } @@ -3160,18 +3158,18 @@ func processOneEvent() { case conn := <-conns: if maxConnections > 0 && len(clients) >= maxConnections { - log.Println("connection limit reached, refusing connection") + printDebug("connection limit reached, refusing connection") conn.Close() break } - log.Println("accepted client connection") + printDebug("accepted client connection") // In effect, we require TCP/UDP, as they have port numbers. address := conn.RemoteAddr().String() host, port, err := net.SplitHostPort(address) if err != nil { - log.Fatalln(err) + exitFatal("%s", err) } c := &client{ @@ -3192,19 +3190,19 @@ func processOneEvent() { c.setKillTimer() case ev := <-prepared: - log.Println("client is ready:", ev.host) + printDebug("client is ready: %s", ev.host) if _, ok := clients[ev.client]; ok { ev.client.onPrepared(ev.host, ev.isTLS) } case ev := <-reads: - log.Println("received data from client") + printDebug("received data from client") if _, ok := clients[ev.client]; ok { ev.client.onRead(ev.data, ev.err) } case ev := <-writes: - log.Println("sent data to client") + printDebug("sent data to client") if _, ok := clients[ev.client]; ok { ev.client.onWrite(ev.written, ev.err) } @@ -3434,7 +3432,7 @@ func main() { config = make(simpleConfig) config.loadDefaults(configTable) if err := config.updateFromFile(); err != nil && !os.IsNotExist(err) { - log.Println("error loading configuration", err) + printError("error loading configuration: %s", err) os.Exit(1) } @@ -3450,7 +3448,7 @@ func main() { ircSetupListenFDs, } { if err := fn(); err != nil { - log.Fatalln(err) + exitFatal("%s", err) } } |