]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/ctx.go
Logging to opened file descriptor
[nncp.git] / src / ctx.go
index 7e4d726751f149963fb189dfa5df46bc03727581..58dba44df6156381216ee90e5043587d9b538039 100644 (file)
@@ -23,6 +23,8 @@ import (
        "io/ioutil"
        "os"
        "path/filepath"
+       "strconv"
+       "strings"
 
        "syscall"
 )
@@ -135,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
        }