From: Steffen Nurpmeso Subject: Re: ifconfig wg: "humanify" last handshake To: "Theo de Raadt" Cc: "Omar Polo" , tech@openbsd.org Date: Wed, 06 Aug 2025 21:45:48 +0200 Theo de Raadt wrote in <89622.1754491219@cvs.openbsd.org>: |I disagree. | |The problem with creating timestamps which are easier for humans to read, |is that they become more difficult for scripts to handle. this is the difference in between "wg show wgppp" and "wg show wgppp dump" in the wg(8) variant If dump is specified, then several lines are printed; the first contains in order separated by tab: private‐key, public‐key, listen‐port, fw‐ mark. Subsequent lines are printed for each peer and contain in order separated by tab: public‐key, preshared‐key, endpoint, al‐ lowed‐ips, latest‐handshake, transfer‐rx, transfer‐tx, persis‐ tent‐keepalive. ... |> + if (delta > 60 * 60 * 24 * 2) |> + r = snprintf(buf, sizeof(buf), "%lld days ago", |> + delta / (60 * 60 * 24)); |> + else if (delta > 60 * 60 * 2) |> + r = snprintf(buf, sizeof(buf), "%lld hours ago", |> + delta / (60 * 60)); |> + else if (delta > 60 * 2) |> + r = snprintf(buf, sizeof(buf), "%lld minutes ago", |> + delta / 60); |> + else |> + r = snprintf(buf, sizeof(buf), "%lld seconds ago", |> + delta); but you all do this, all the time. Wouldn't if(delta > ...){ delta = ...; tcp = "days"; /* or even x==y ? "day" : "days", you know */ } ... r = snprintf(.., "%lld %s ago", delta); result in smaller and more readable code, with the "danger" at only one line. --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt) | |During summer's humble, here's David Leonard's grumble | |The black bear, The black bear, |blithely holds his own holds himself at leisure |beating it, up and down tossing over his ups and downs with pleasure | |Farewell, dear collar bear