]> Cypherpunks.ru repositories - nncp.git/commitdiff
Logging to opened file descriptor
authorSergey Matveev <stargrave@stargrave.org>
Sun, 8 Aug 2021 08:00:32 +0000 (11:00 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 8 Aug 2021 12:26:37 +0000 (15:26 +0300)
doc/admin.texi
doc/cfg/general.texi
doc/log.texi
doc/news.ru.texi
doc/news.texi
ports/nncp/Makefile
src/ctx.go
src/log.go
src/nncp.go

index 9a4c8e8df6fcee4453cf5120c7350dc6e5807bb4..86caeb9264f0c76ff5293845f97c51639e7d5966 100644 (file)
@@ -100,7 +100,8 @@ uucp        stream  tcp6    nowait  nncpuser        /usr/local/bin/nncp-daemon      nncp-daemon -quiet -
 
 @item
     Or it can be also run as a @command{daemontools} daemon under
-    @url{http://cr.yp.to/ucspi-tcp.html, UCSPI-TCP}:
+    @url{http://cr.yp.to/ucspi-tcp.html, UCSPI-TCP}. In the example
+    below it uses native daemontools's logging capability:
 
 @example
 # mkdir -p /var/service/.nncp-daemon/log
@@ -108,13 +109,13 @@ uucp      stream  tcp6    nowait  nncpuser        /usr/local/bin/nncp-daemon      nncp-daemon -quiet -
 
 # cat > run <<EOF
 #!/bin/sh -e
-exec envuidgid nncpuser tcpserver -DHRU -l 0 ::0 uucp \
-       /usr/local/bin/nncp-daemon -quiet -ucspi
+NNCPLOG=FD:4 exec envuidgid nncpuser tcpserver -DHRU -l 0 ::0 uucp \
+       /usr/local/bin/nncp-daemon -quiet -ucspi 4>&1
 EOF
 
 # cat > log/run <<EOF
 #!/bin/sh -e
-exec setuidgid uucp multilog ./main
+exec setuidgid uucp multilog ./main
 EOF
 
 # chmod -R 755 /var/service/.nncp-daemon
index 63d0757692af0fb347684426567be94ad68c2f92..971b585025ead47d384a1ed60f6aff2f270c62e4 100644 (file)
@@ -21,7 +21,12 @@ mcd-send: {em0: 60, igb1: 5}
 @item spool
 Absolute path to the @ref{Spool, spool} directory.
 @item log
-Absolute path to the @ref{Log, log} file.
+Either:
+    @itemize
+    @item absolute path to the @ref{Log, log} file
+    @item @code{FD:XXX}, where @code{XXX} is a decimal file descriptor
+        to write records too
+    @end itemize
 @item umask
 Will force all invoked commands to override their umask to specified
 octal mask. Useful for using with @ref{Shared spool, shared spool directories}.
index 3c91f61454e2fb3b96756f5ce8996c052b649149..74a8c6d562ca9fd09b99c0b93aba6b32eec0a4f6 100644 (file)
@@ -6,3 +6,28 @@ Log is a plaintext file consisting of
 read by human, but it is better to use either @ref{nncp-log}, or
 @command{recutils} utilities for selecting and formatting the required
 fields.
+
+Two example records from it:
+
+@verbatim
+When: 2021-08-07T20:30:49.042460622Z
+Who: sp-file-done
+Node: BYRRQUULEHINPKEFN7CHMSHR5I5CK7PMX5HQNCYERTBAR4BOCG6Q
+Nice: 255
+Type: file
+XX: rx
+Pkt: VQFR6KXC5N4UGL3HKKJKPXE4TN3G4UQGFXQTEYFZ7ZZIKWUVKOGA
+Size: 5229
+FullSize: 5229
+Msg: Got packet VQFR6KXC5N4UGL3HKKJKPXE4TN3G4UQGFXQTEYFZ7ZZIKWUVKOGA 100% (5.1 KiB / 5.1 KiB): done
+
+When: 2021-08-07T20:30:49.131766306Z
+Who: rx
+Node: BYRRQUULEHINPKEFN7CHMSHR5I5CK7PMX5HQNCYERTBAR4BOCG6Q
+Pkt: VQFR6KXC5N4UGL3HKKJKPXE4TN3G4UQGFXQTEYFZ7ZZIKWUVKOGA
+Nice: 96
+Size: 4741
+Type: exec
+Dst: sendmail stargrave@stargrave.org
+Msg: Got exec from gw to sendmail stargrave@stargrave.org (4.6 KiB)
+@end verbatim
index 8218c805bf1f6678d857c47cca430e85e8de74d1..d2c5f832f9b3de906ae88573a12b33c6d5accec7 100644 (file)
@@ -1,6 +1,17 @@
 @node Новости
 @section Новости
 
+@node Релиз 7.6.0
+@subsection Релиз 7.6.0
+@itemize
+
+@item
+Журналирование может производиться в назначенный открытый файловый
+дескриптор (@env{$NNCPLOG=FD:5} например).
+Что дружелюбно к использованию под @command{daemontools}.
+
+@end itemize
+
 @node Релиз 7.5.1
 @subsection Релиз 7.5.1
 @itemize
index 85c7acdc1ed3bc13f09e30633da85f33b1071cde..48f5ec0dedbdf1877fee59ee19c91d73d535a3cc 100644 (file)
@@ -3,6 +3,17 @@
 
 See also this page @ref{Новости, on russian}.
 
+@node Release 7_6_0
+@section Release 7.6.0
+@itemize
+
+@item
+Logging may be done to specified opened file descriptor
+(@env{$NNCPLOG=FD:5} for example).
+That is friendly to use under @command{daemontools}.
+
+@end itemize
+
 @node Release 7_5_1
 @section Release 7.5.1
 @itemize
index 70b6311792ce8f43b267f56dc762cfb9ab99ad0f..6ff741a63b4370ff472432d0bf6505a552ae0d74 100644 (file)
@@ -1,5 +1,5 @@
 PORTNAME=      nncp
-DISTVERSION=   7.4.0
+DISTVERSION=   7.6.0
 CATEGORIES=    net
 MASTER_SITES=  http://www.nncpgo.org/download/
 
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
        }
index 7bb59a3b97cf798e5c35c01d0c76c19154445ba6..9a8d2e7505b7fc4b5eecdeb77d4d2b49dbab12dd 100644 (file)
@@ -27,6 +27,10 @@ import (
        "golang.org/x/sys/unix"
 )
 
+const LogFdPrefix = "FD:"
+
+var LogFd *os.File
+
 type LE struct {
        K string
        V interface{}
@@ -64,6 +68,10 @@ func (les LEs) Rec() string {
 }
 
 func (ctx *Ctx) Log(rec string) {
+       if LogFd != nil {
+               LogFd.WriteString(rec)
+               return
+       }
        fdLock, err := os.OpenFile(
                ctx.LogPath+".lock",
                os.O_CREATE|os.O_WRONLY,
index 8e04f041316b694be2d9e7eebfe53cb67946d4b2..c641668d62b181b3b813bec8862919d5218bfa3b 100644 (file)
@@ -40,7 +40,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.`
 const Base32Encoded32Len = 52
 
 var (
-       Version string = "7.5.1"
+       Version string = "7.6.0"
 
        Base32Codec *base32.Encoding = base32.StdEncoding.WithPadding(base32.NoPadding)
 )