]> Cypherpunks.ru repositories - nncp.git/commitdiff
Ability to override spool directory and logfile
authorSergey Matveev <stargrave@stargrave.org>
Wed, 29 Nov 2017 19:16:47 +0000 (22:16 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 29 Nov 2017 19:20:35 +0000 (22:20 +0300)
21 files changed:
doc/cmds.texi
doc/news.ru.texi
doc/news.texi
src/cypherpunks.ru/nncp/cfg.go
src/cypherpunks.ru/nncp/cmd/nncp-bundle/main.go
src/cypherpunks.ru/nncp/cmd/nncp-call/main.go
src/cypherpunks.ru/nncp/cmd/nncp-caller/main.go
src/cypherpunks.ru/nncp/cmd/nncp-cfgmin/main.go
src/cypherpunks.ru/nncp/cmd/nncp-check/main.go
src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go
src/cypherpunks.ru/nncp/cmd/nncp-file/main.go
src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go
src/cypherpunks.ru/nncp/cmd/nncp-log/main.go
src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go
src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go
src/cypherpunks.ru/nncp/cmd/nncp-reass/main.go
src/cypherpunks.ru/nncp/cmd/nncp-rm/main.go
src/cypherpunks.ru/nncp/cmd/nncp-stat/main.go
src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go
src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go
src/cypherpunks.ru/nncp/ctx.go

index 253c01d0eaae7e99fe3c64b776d2233cf37f70e1..6113aebd62fd5416f05f086c25ac71185a1b525f 100644 (file)
@@ -20,6 +20,12 @@ Nearly all commands have the following common options:
     1-255 values are allowed.
 @item -node
     Process only single specified node.
+@item -spool
+    Override path to spool directory. May be specified by
+    @env{NNCPSPOOL} environment variable.
+@item -log
+    Override path to logfile. May be specified by @env{NNCPLOG}
+    environment variable.
 @item -quiet
     Print only errors, omit simple informational messages. In any case
     those messages are logged, so you can reread them using
index dd3e0a8f5ec5d65e55e32fa9f77bff39704342f1..a8600ade1617493fb48d93528f57d5a06a98d8ae 100644 (file)
@@ -19,6 +19,9 @@
 В команде @command{nncp-call} разрешается иметь только одного
 обработчика контрольной суммы в фоне. Это полезно когда тысячи маленьких
 входящих пакетов могут создать много горутин.
+@item
+Возможность переопределить путь до spool директории и файла журнала
+через аргумент командной строки или переменную окружения.
 @end itemize
 
 @node Релиз 0.12
index 219126968bc2c0ec3a13908a7f55869f14b6d68e..eae13ba609231a31dfc6de3d4421b8be55b43fa6 100644 (file)
@@ -21,6 +21,9 @@ duplicate packets receiving.
 Single background checksum verifier worker is allowed in
 @command{nncp-call}. This is helpful when thousands of small inbound
 packets could create many goroutines.
+@item
+Ability to override path to spool directory and logfile through either
+command line argument, or environment variable.
 @end itemize
 
 @node Release 0.12
index 3a642f68567ff4487630dab5e3b96b676d5cba34..0a1b1d8a0a86d73874e221b8087f5d82ac4734c6 100644 (file)
@@ -32,7 +32,9 @@ import (
 )
 
 const (
-       CfgPathEnv = "NNCPCFG"
+       CfgPathEnv  = "NNCPCFG"
+       CfgSpoolEnv = "NNCPSPOOL"
+       CfgLogEnv   = "NNCPLOG"
 )
 
 var (
@@ -414,11 +416,3 @@ func CfgParse(data []byte) (*Ctx, error) {
        }
        return &ctx, nil
 }
-
-func CfgPathFromEnv(cmdlineFlag *string) (p string) {
-       p = os.Getenv(CfgPathEnv)
-       if p == "" {
-               p = *cmdlineFlag
-       }
-       return
-}
index e228f2ffa14a0076ce62a4d2c522be8586b536e4..163feb49926f06e01a2fb091c0131f2bf105ccd1 100644 (file)
@@ -54,17 +54,19 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               niceRaw  = flag.Int("nice", 255, "Minimal required niceness")
-               doRx     = flag.Bool("rx", false, "Receive packets")
-               doTx     = flag.Bool("tx", false, "Transfer packets")
-               doDelete = flag.Bool("delete", false, "Delete transferred packets")
-               doCheck  = flag.Bool("check", false, "Check integrity while receiving")
-               dryRun   = flag.Bool("dryrun", false, "Do not writings")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               niceRaw   = flag.Int("nice", 255, "Minimal required niceness")
+               doRx      = flag.Bool("rx", false, "Receive packets")
+               doTx      = flag.Bool("tx", false, "Transfer packets")
+               doDelete  = flag.Bool("delete", false, "Delete transferred packets")
+               doCheck   = flag.Bool("check", false, "Check integrity while receiving")
+               dryRun    = flag.Bool("dryrun", false, "Do not writings")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -87,16 +89,10 @@ func main() {
                log.Fatalln("At least one of -rx and -tx must be specified")
        }
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
-       }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        nodeIds := make(map[nncp.NodeId]struct{}, flag.NArg())
        for i := 0; i < flag.NArg(); i++ {
index 42f761faa10c9952964a4f96857d61b1b4869132..062593e6301ecd1f88d8cafc8721d68c623fe6bc 100644 (file)
@@ -22,7 +22,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
        "strings"
@@ -40,14 +39,16 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               niceRaw  = flag.Int("nice", 255, "Minimal required niceness")
-               rxOnly   = flag.Bool("rx", false, "Only receive packets")
-               txOnly   = flag.Bool("tx", false, "Only transfer packets")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               niceRaw   = flag.Int("nice", 255, "Minimal required niceness")
+               rxOnly    = flag.Bool("rx", false, "Only receive packets")
+               txOnly    = flag.Bool("tx", false, "Only transfer packets")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
 
                onlineDeadline = flag.Uint("onlinedeadline", 0, "Override onlinedeadline option")
                maxOnlineTime  = flag.Uint("maxonlinetime", 0, "Override maxonlinetime option")
@@ -74,19 +75,13 @@ func main() {
                log.Fatalln("-rx and -tx can not be set simultaneously")
        }
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
-       }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
        if ctx.Self == nil {
                log.Fatalln("Config lacks private keys")
        }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        splitted := strings.SplitN(flag.Arg(0), ":", 2)
        node, err := ctx.FindNode(splitted[0])
index 3cbbe8f19d05ca8b9797139a2450e6f98773d82d..459a623858c7d117d04fc1abc0a5c380c1dc4b5a 100644 (file)
@@ -22,7 +22,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
        "strconv"
@@ -42,11 +41,13 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -59,19 +60,13 @@ func main() {
                return
        }
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
-       }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
        if ctx.Self == nil {
                log.Fatalln("Config lacks private keys")
        }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        var nodes []*nncp.Node
        if flag.NArg() > 0 {
index 48df34e0284f45e8a655bc7457c94ca430d7510f..7de3247e466ac1f839a55807f6be5006aa9600f2 100644 (file)
@@ -22,7 +22,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
 
@@ -54,13 +53,9 @@ func main() {
                return
        }
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, "", "", false, false)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
-       }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
 
        cfg := nncp.CfgYAML{
index 2c06b1425e93169989e0b2dac2c427c6ccc6b802..a10c8cfd2f0417f749b661ef3c13b5a23b9d7018 100644 (file)
@@ -22,7 +22,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
 
@@ -38,12 +37,14 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               nodeRaw  = flag.String("node", "", "Process only that node")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               nodeRaw   = flag.String("node", "", "Process only that node")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -56,16 +57,10 @@ func main() {
                return
        }
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
-       }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        var nodeOnly *nncp.Node
        if *nodeRaw != "" {
index e6ec2d385648ae1c84c8e959cc381addbc3d8e92..de0a0b3bf62b10cd6b5a0e43e0bcd3a0d489240d 100644 (file)
@@ -22,7 +22,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "net"
        "os"
@@ -41,14 +40,16 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               niceRaw  = flag.Int("nice", 255, "Minimal required niceness")
-               bind     = flag.String("bind", "[::]:5400", "Address to bind to")
-               maxConn  = flag.Int("maxconn", 128, "Maximal number of simultaneous connections")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               niceRaw   = flag.Int("nice", 255, "Minimal required niceness")
+               bind      = flag.String("bind", "[::]:5400", "Address to bind to")
+               maxConn   = flag.Int("maxconn", 128, "Maximal number of simultaneous connections")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -65,19 +66,13 @@ func main() {
        }
        nice := uint8(*niceRaw)
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
-       }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
        if ctx.Self == nil {
                log.Fatalln("Config lacks private keys")
        }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        ln, err := net.Listen("tcp", *bind)
        if err != nil {
index d922882fec7a3a301e9c793cddfc378ee122de61..3c35ab9081799429d12dcd6edcabb997a5759440 100644 (file)
@@ -22,7 +22,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
        "strings"
@@ -46,6 +45,8 @@ func main() {
                niceRaw   = flag.Int("nice", nncp.DefaultNiceFile, "Outbound packet niceness")
                minSize   = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
                chunkSize = flag.Uint64("chunked", 0, "Split file on specified size chunks, in KiB")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
                quiet     = flag.Bool("quiet", false, "Print only errors")
                debug     = flag.Bool("debug", false, "Print debug messages")
                version   = flag.Bool("version", false, "Print version information")
@@ -70,19 +71,13 @@ func main() {
        }
        nice := uint8(*niceRaw)
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
-       }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
        if ctx.Self == nil {
                log.Fatalln("Config lacks private keys")
        }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        splitted := strings.SplitN(flag.Arg(1), ":", 2)
        if len(splitted) != 2 {
index da5268fbda69d63ac8f803ece6e73364d7802014..c089abc102c88a9c8e6d6fb8ed649f9d1c000eb0 100644 (file)
@@ -22,7 +22,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
        "path/filepath"
@@ -40,13 +39,15 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               niceRaw  = flag.Int("nice", nncp.DefaultNiceFreq, "Outbound packet niceness")
-               minSize  = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               niceRaw   = flag.Int("nice", nncp.DefaultNiceFreq, "Outbound packet niceness")
+               minSize   = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -67,19 +68,13 @@ func main() {
        }
        nice := uint8(*niceRaw)
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
-       }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
        if ctx.Self == nil {
                log.Fatalln("Config lacks private keys")
        }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        splitted := strings.SplitN(flag.Arg(0), ":", 2)
        if len(splitted) != 2 {
index 653f213b7977049d1985fc99d9d172c97c435de2..c045715447ee36bb72e7c0815bbbadb7145ebc70 100644 (file)
@@ -23,7 +23,6 @@ import (
        "bufio"
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
 
@@ -40,6 +39,7 @@ func usage() {
 func main() {
        var (
                cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               logPath  = flag.String("log", "", "Override path to logfile")
                debug    = flag.Bool("debug", false, "Print debug messages")
                version  = flag.Bool("version", false, "Print version information")
                warranty = flag.Bool("warranty", false, "Print warranty information")
@@ -55,13 +55,9 @@ func main() {
                return
        }
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, "", *logPath, false, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
-       }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
 
        fd, err := os.Open(ctx.LogPath)
index f5f4de791d1e8023d75f8b34a6eaeaed018896e4..f9d346f4f27cb5f206ec1b6192cfdcf635b9dbf6 100644 (file)
@@ -40,13 +40,15 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               niceRaw  = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness")
-               minSize  = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               niceRaw   = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness")
+               minSize   = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -67,19 +69,13 @@ func main() {
        }
        nice := uint8(*niceRaw)
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
-       }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
        if ctx.Self == nil {
                log.Fatalln("Config lacks private keys")
        }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        node, err := ctx.FindNode(flag.Arg(0))
        if err != nil {
index 170b9e1990c81934254760cff1fe7ad7521cdccc..a7b346f4042d1b938f9d9e06c3b137895fdd7fef 100644 (file)
@@ -26,7 +26,6 @@ import (
        "flag"
        "fmt"
        "io"
-       "io/ioutil"
        "log"
        "os"
 
@@ -114,13 +113,9 @@ func main() {
        _, err = xdr.Unmarshal(bytes.NewReader(beginning), &pktEnc)
        if err == nil && pktEnc.Magic == nncp.MagicNNCPEv2 {
                if *dump {
-                       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+                       ctx, err := nncp.CtxFromCmdline(*cfgPath, "", "", false, false)
                        if err != nil {
-                               log.Fatalln("Can not read config:", err)
-                       }
-                       ctx, err := nncp.CfgParse(cfgRaw)
-                       if err != nil {
-                               log.Fatalln("Can not parse config:", err)
+                               log.Fatalln("Error during initialization:", err)
                        }
                        if ctx.Self == nil {
                                log.Fatalln("Config lacks private keys")
index 45354d73e1eb3b6b1f09eb6e2b2d704399e6207d..9c6cae2af1fe4dd1ab3358548eaecfaf11f9eaa2 100644 (file)
@@ -264,17 +264,19 @@ func findMetas(ctx *nncp.Ctx, dirPath string) []string {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               allNodes = flag.Bool("all", false, "Process all found chunked files for all nodes")
-               nodeRaw  = flag.String("node", "", "Process all found chunked files for that node")
-               keep     = flag.Bool("keep", false, "Do not remove chunks while assembling")
-               dryRun   = flag.Bool("dryrun", false, "Do not assemble whole file")
-               dumpMeta = flag.Bool("dump", false, "Print decoded human-readable FILE.nncp.meta")
-               stdout   = flag.Bool("stdout", false, "Output reassembled FILE to stdout")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               allNodes  = flag.Bool("all", false, "Process all found chunked files for all nodes")
+               nodeRaw   = flag.String("node", "", "Process all found chunked files for that node")
+               keep      = flag.Bool("keep", false, "Do not remove chunks while assembling")
+               dryRun    = flag.Bool("dryrun", false, "Do not assemble whole file")
+               dumpMeta  = flag.Bool("dump", false, "Print decoded human-readable FILE.nncp.meta")
+               stdout    = flag.Bool("stdout", false, "Output reassembled FILE to stdout")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -287,16 +289,10 @@ func main() {
                return
        }
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
-       }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        var nodeOnly *nncp.Node
        if *nodeRaw != "" {
index 00a13a4fd2652ea13bb3f56a7180fbf13a5df307..cfe4bbbc64328dcb19cba3276bd92f902eb89c83 100644 (file)
@@ -22,7 +22,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
        "path/filepath"
@@ -39,11 +38,13 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -60,16 +61,10 @@ func main() {
                os.Exit(1)
        }
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
-       }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        node, err := ctx.FindNode(flag.Arg(0))
        if err != nil {
index 0c27b1b8d27f4ae0940d806cf539c29e0d139a39..fd20e620a6a51954c22c08e2a8adaadb66588f60 100644 (file)
@@ -22,7 +22,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
        "sort"
@@ -40,11 +39,12 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               nodeRaw  = flag.String("node", "", "Process only that node")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               nodeRaw   = flag.String("node", "", "Process only that node")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -57,15 +57,10 @@ func main() {
                return
        }
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, "", false, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
-       }
-       ctx.Debug = *debug
 
        var nodeOnly *nncp.Node
        if *nodeRaw != "" {
index 12dc214d8a4b7e77029dcfb6034640ae8edbaffe..eb2158c9c67d17b2a1ddfa6dd4eac52a05f8c03f 100644 (file)
@@ -22,7 +22,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
        "time"
@@ -39,16 +38,18 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               nodeRaw  = flag.String("node", "", "Process only that node")
-               niceRaw  = flag.Int("nice", 255, "Minimal required niceness")
-               dryRun   = flag.Bool("dryrun", false, "Do not actually write any tossed data")
-               doSeen   = flag.Bool("seen", false, "Create .seen files")
-               cycle    = flag.Uint("cycle", 0, "Repeat tossing after N seconds in infinite loop")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               nodeRaw   = flag.String("node", "", "Process only that node")
+               niceRaw   = flag.Int("nice", 255, "Minimal required niceness")
+               dryRun    = flag.Bool("dryrun", false, "Do not actually write any tossed data")
+               doSeen    = flag.Bool("seen", false, "Create .seen files")
+               cycle     = flag.Uint("cycle", 0, "Repeat tossing after N seconds in infinite loop")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -65,19 +66,13 @@ func main() {
        }
        nice := uint8(*niceRaw)
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
-       }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
        if ctx.Self == nil {
                log.Fatalln("Config lacks private keys")
        }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        var nodeOnly *nncp.Node
        if *nodeRaw != "" {
index 05a37489b8299a5de76e47b52e422d96661cf28e..f500cc919ffe965caac6cf215867eaffcf5c9e47 100644 (file)
@@ -43,17 +43,19 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               nodeRaw  = flag.String("node", "", "Process only that node")
-               niceRaw  = flag.Int("nice", 255, "Minimal required niceness")
-               rxOnly   = flag.Bool("rx", false, "Only receive packets")
-               txOnly   = flag.Bool("tx", false, "Only transfer packets")
-               mkdir    = flag.Bool("mkdir", false, "Create necessary outbound directories")
-               keep     = flag.Bool("keep", false, "Do not delete transferred packets")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               nodeRaw   = flag.String("node", "", "Process only that node")
+               niceRaw   = flag.Int("nice", 255, "Minimal required niceness")
+               rxOnly    = flag.Bool("rx", false, "Only receive packets")
+               txOnly    = flag.Bool("tx", false, "Only transfer packets")
+               mkdir     = flag.Bool("mkdir", false, "Create necessary outbound directories")
+               keep      = flag.Bool("keep", false, "Do not delete transferred packets")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -77,16 +79,10 @@ func main() {
                log.Fatalln("-rx and -tx can not be set simultaneously")
        }
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
-       }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        var nodeOnly *nncp.Node
        if *nodeRaw != "" {
index 21b3d6fd8e8efe76e146b02e1d47af38d0df675a..8e550fb94e8c1bb3d18d166e9bf1da1c37e0cbb4 100644 (file)
@@ -20,6 +20,7 @@ package nncp
 
 import (
        "errors"
+       "io/ioutil"
        "os"
        "path/filepath"
 )
@@ -68,3 +69,37 @@ func (ctx *Ctx) ensureRxDir(nodeId *NodeId) error {
        fd.Close()
        return nil
 }
+
+func CtxFromCmdline(cfgPath, spoolPath, logPath string, quiet, debug bool) (*Ctx, error) {
+       env := os.Getenv(CfgPathEnv)
+       if env != "" {
+               cfgPath = env
+       }
+       cfgRaw, err := ioutil.ReadFile(cfgPath)
+       if err != nil {
+               return nil, err
+       }
+       ctx, err := CfgParse(cfgRaw)
+       if err != nil {
+               return nil, err
+       }
+       if spoolPath == "" {
+               env = os.Getenv(CfgSpoolEnv)
+               if env != "" {
+                       ctx.Spool = env
+               }
+       } else {
+               ctx.Spool = spoolPath
+       }
+       if logPath == "" {
+               env = os.Getenv(CfgLogEnv)
+               if env != "" {
+                       ctx.LogPath = env
+               }
+       } else {
+               ctx.LogPath = logPath
+       }
+       ctx.Quiet = quiet
+       ctx.Debug = debug
+       return ctx, nil
+}