]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/ctx.go
Logging to opened file descriptor
[nncp.git] / src / ctx.go
index 4d762d290cadfb83fde02a36e5bd74b8850a50d2..58dba44df6156381216ee90e5043587d9b538039 100644 (file)
@@ -21,13 +21,12 @@ import (
        "errors"
        "fmt"
        "io/ioutil"
-       "log"
        "os"
        "path/filepath"
+       "strconv"
+       "strings"
 
        "syscall"
-
-       "golang.org/x/sys/unix"
 )
 
 type Ctx struct {
@@ -138,6 +137,18 @@ func CtxFromCmdline(
        } else {
                ctx.LogPath = logPath
        }
+       if strings.HasPrefix(ctx.LogPath, LogFdPrefix) {
+               ptr, err := strconv.ParseUint(
+                       strings.TrimPrefix(ctx.LogPath, LogFdPrefix), 10, 64,
+               )
+               if err != nil {
+                       return nil, err
+               }
+               LogFd = os.NewFile(uintptr(ptr), CfgLogEnv)
+               if LogFd == nil {
+                       return nil, errors.New("can not open:" + ctx.LogPath)
+               }
+       }
        if showPrgrs {
                ctx.ShowPrgrs = true
        }
@@ -149,14 +160,6 @@ func CtxFromCmdline(
        return ctx, nil
 }
 
-func (ctx *Ctx) IsEnoughSpace(want int64) bool {
-       var s unix.Statfs_t
-       if err := unix.Statfs(ctx.Spool, &s); err != nil {
-               log.Fatalln("Can not stat spool:", err)
-       }
-       return int64(s.Bavail)*int64(s.Bsize) > want
-}
-
 func (ctx *Ctx) Umask() {
        if ctx.UmaskForce != nil {
                syscall.Umask(*ctx.UmaskForce)