diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2020-06-21 21:09:18 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2020-06-21 21:09:18 +0000 |
commit | 2491528e5542153370122aa6f64424d30610562e (patch) | |
tree | 515184ba8658a1a5ef6811641b86d25279e5fcdc | |
parent | 13a02f2ccc602e8d038a0808b052f2bffc3f5408 (diff) | |
download | s6-portable-utils-2491528e5542153370122aa6f64424d30610562e.tar.xz |
Add s6-tai64ndiff ; prepare for 2.2.3.0
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | doc/index.html | 2 | ||||
-rw-r--r-- | doc/s6-tai64ndiff.html | 60 | ||||
-rw-r--r-- | doc/upgrade.html | 4 | ||||
-rw-r--r-- | package/deps.mak | 3 | ||||
-rw-r--r-- | package/info | 2 | ||||
-rw-r--r-- | package/modes | 1 | ||||
-rw-r--r-- | package/targets.mak | 1 | ||||
-rw-r--r-- | src/skaembutils/deps-exe/s6-tai64ndiff | 1 | ||||
-rw-r--r-- | src/skaembutils/s6-tai64ndiff.c | 74 |
10 files changed, 146 insertions, 5 deletions
@@ -1,11 +1,12 @@ Changelog for s6-portable-utils. -In 2.2.2.5 +In 2.2.3.0 ---------- - Bugfixes that have nothing to do with 2.2.2.4 but that were reported *right after* 2.2.2.4 was released, because things do be like that + - New binary: s6-tai64ndiff In 2.2.2.4 diff --git a/doc/index.html b/doc/index.html index 157400a..f191c4f 100644 --- a/doc/index.html +++ b/doc/index.html @@ -77,7 +77,7 @@ library. </li> <ul> <li> The current released version of s6-portable-utils is -<a href="s6-portable-utils-2.2.2.5.tar.gz">2.2.2.5</a>. </li> +<a href="s6-portable-utils-2.2.3.0.tar.gz">2.2.3.0</a>. </li> <li> Alternatively, you can checkout a copy of the <a href="//git.skarnet.org/cgi-bin/cgit.cgi/s6-portable-utils/">s6-portable-utils git repository</a>: diff --git a/doc/s6-tai64ndiff.html b/doc/s6-tai64ndiff.html new file mode 100644 index 0000000..c1f0440 --- /dev/null +++ b/doc/s6-tai64ndiff.html @@ -0,0 +1,60 @@ +<html> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Language" content="en" /> + <title>s6-portable-utils: the s6-tai64ndiff program</title> + <meta name="Description" content="s6-portable-utils: the s6-tai64ndiff program" /> + <meta name="Keywords" content="s6 command s6-tai64ndiff filter timestamp TAI64 TAI64N diff time difference log line" /> + <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> --> + </head> +<body> + +<p> +<a href="index.html">s6-portable-utils</a><br /> +<a href="//skarnet.org/software/">Software</a><br /> +<a href="//skarnet.org/">skarnet.org</a> +</p> + +<h1> The s6-tai64ndiff program </h1> + +<p> +s6-tai64ndiff acts as a filter, reading from stdin and writing to stdout. +It expects every line of its input to begin with a +<a href="//skarnet.org/software/skalibs/libstddjb/tai.html#timestamp">TAI64N +timestamp</a>. It replaces this timestamp with a prefix showing the time +difference between this line and the previous line. +</p> + +<h2> Interface </h2> + +<pre> + s6-tai64ndiff +</pre> + +<ul> + <li> s6-tai64ndiff exits 0 when it sees the end of stdin. If there's an +unfinished line, s6-tai64ndiff processes it and writes it before exiting. </li> + <li> The prefix it prints is of the form <tt>[ <em>seconds</em>.<em>microseconds</em> ]</tt>, +in decimal. It can be interpreted as a fixed-point decimal number of seconds that +elapsed between the timestamp on the previous line and the timestamp on the +current line. </li> + <li> If the difference isn't defined, <em>seconds</em> and <em>microseconds</em> +are just whitespace. The difference is not defined on the first line of stdin or +on non-timestamped lines. Following non-timestamped lines, the difference may not +be accurate. </li> +</ul> + +<h2> Notes </h2> + +<ul> + <li> The typical use case of s6-tai64ndiff is to read files that have +been filtered through <a href="s6-tai64n.html">s6-tai64n</a>, or log files +that have been produced by <a href="s6-log.html">s6-log</a> with the <tt>t</tt> +directive. </li> + <li> The difference is a signed number. Negative numbers probably indicate +a backwards clock jump, which is a bad thing to have on a system. </li> +</ul> + +</body> +</html> diff --git a/doc/upgrade.html b/doc/upgrade.html index 270cea5..9600316 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -18,10 +18,10 @@ <h1> What has changed in s6-portable-utils </h1> -<h2> in 2.2.2.5 </h2> +<h2> in 2.2.3.0 </h2> <ul> - <li> Bugfix release, no changes. </li> + <li> New binary: <a href="s6-tai64ndiff.html">s6-tai64ndiff</a>. </li> </ul> <h2> in 2.2.2.4 </h2> diff --git a/package/deps.mak b/package/deps.mak index da2b80a..b7f08df 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -36,6 +36,7 @@ src/skaembutils/s6-seq.o src/skaembutils/s6-seq.lo: src/skaembutils/s6-seq.c src/skaembutils/s6-sleep.o src/skaembutils/s6-sleep.lo: src/skaembutils/s6-sleep.c src/skaembutils/s6-sort.o src/skaembutils/s6-sort.lo: src/skaembutils/s6-sort.c src/skaembutils/s6-sync.o src/skaembutils/s6-sync.lo: src/skaembutils/s6-sync.c +src/skaembutils/s6-tai64ndiff.o src/skaembutils/s6-tai64ndiff.lo: src/skaembutils/s6-tai64ndiff.c src/skaembutils/s6-tail.o src/skaembutils/s6-tail.lo: src/skaembutils/s6-tail.c src/skaembutils/s6-test.o src/skaembutils/s6-test.lo: src/skaembutils/s6-test.c src/skaembutils/s6-touch.o src/skaembutils/s6-touch.lo: src/skaembutils/s6-touch.c @@ -114,6 +115,8 @@ s6-sort: EXTRA_LIBS := -lskarnet s6-sort: src/skaembutils/s6-sort.o s6-sync: EXTRA_LIBS := s6-sync: src/skaembutils/s6-sync.o +s6-tai64ndiff: EXTRA_LIBS := -lskarnet +s6-tai64ndiff: src/skaembutils/s6-tai64ndiff.o s6-tail: EXTRA_LIBS := -lskarnet s6-tail: src/skaembutils/s6-tail.o s6-test: EXTRA_LIBS := -lskarnet diff --git a/package/info b/package/info index 259da96..07da201 100644 --- a/package/info +++ b/package/info @@ -1,4 +1,4 @@ package=s6-portable-utils -version=2.2.2.5 +version=2.2.3.0 category=admin package_macro_name=S6_PORTABLE_UTILS diff --git a/package/modes b/package/modes index a14e4bc..6dfaf11 100644 --- a/package/modes +++ b/package/modes @@ -32,6 +32,7 @@ s6-seq 0755 s6-sleep 0755 s6-sort 0755 s6-sync 0755 +s6-tai64ndiff 0755 s6-tail 0755 s6-test 0755 s6-touch 0755 diff --git a/package/targets.mak b/package/targets.mak index 8a56b39..6a413b7 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -33,6 +33,7 @@ s6-seq \ s6-sleep \ s6-sort \ s6-sync \ +s6-tai64ndiff \ s6-tail \ s6-test \ s6-touch \ diff --git a/src/skaembutils/deps-exe/s6-tai64ndiff b/src/skaembutils/deps-exe/s6-tai64ndiff new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/skaembutils/deps-exe/s6-tai64ndiff @@ -0,0 +1 @@ +-lskarnet diff --git a/src/skaembutils/s6-tai64ndiff.c b/src/skaembutils/s6-tai64ndiff.c new file mode 100644 index 0000000..25abea3 --- /dev/null +++ b/src/skaembutils/s6-tai64ndiff.c @@ -0,0 +1,74 @@ +/* ISC license. */ + +#include <stdint.h> +#include <string.h> +#include <errno.h> + +#include <skalibs/uint32.h> +#include <skalibs/uint64.h> +#include <skalibs/buffer.h> +#include <skalibs/strerr2.h> +#include <skalibs/tai.h> +#include <skalibs/stralloc.h> +#include <skalibs/skamisc.h> + +int main (int argc, char const *const *argv) +{ + stralloc sa = STRALLOC_ZERO ; + tain_t prev ; + int defined = 0 ; + PROG = "s6-tai64ndiff" ; + + for (;;) + { + unsigned int p = 0 ; + char prefix[23] = "[ . ]" ; + int r = skagetln(buffer_0f1, &sa, '\n') ; + if (r == -1) + if (errno != EPIPE) + strerr_diefu1sys(111, "read from stdin") ; + else r = 1 ; + else if (!r) break ; + if (sa.len > TIMESTAMP) + { + tain_t cur ; + p = timestamp_scan(sa.s, &cur) ; + if (p) + { + if (defined) + { + tain_t diff ; + int64_t secs ; + size_t len ; + tain_sub(&diff, &cur, &prev) ; + secs = tai_sec(tain_secp(&diff)) ; + len = int64_fmt(0, secs) ; + if (len > 10) + { + char fmtn[9] ; + size_t m = 1 + (len < 20) ; + m += int64_fmt(prefix + m, secs) ; + prefix[m++] = '.' ; + uint320_fmt(fmtn, tain_nano(&diff), 9) ; + memcpy(prefix + m, fmtn, 22 - m) ; + } + else + { + int64_fmt(prefix + 11 - len, secs) ; + uint320_fmt(prefix + 12, tain_nano(&diff), 9) ; + } + } + prev = cur ; + defined = 1 ; + if (buffer_put(buffer_1, prefix, 23) < 23) + strerr_diefu1sys(111, "write to stdout") ; + } + else defined = 0 ; + } + else defined = 0 ; + if (buffer_put(buffer_1, sa.s + p, sa.len - p) < (ssize_t)(sa.len - p)) + strerr_diefu1sys(111, "write to stdout") ; + sa.len = 0 ; + } + return 0 ; +} |