[PATCH 2/2] dumpleases: add -d (decimal) mode.
Isaac Dunham
ibid.ag at gmail.com
Sun Oct 18 05:54:59 UTC 2015
Get lease expiration time in seconds, for tools that care.
This is meant to feed into a script to generate TinyDNS configuration,
where a host can have a 'timestamp' that marks its expiration.
function old new delta
dumpleases_main 569 612 +43
static.dumpleases_longopts 31 41 +10
packed_usage 27117 27105 -12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 53/-12) Total: 41 bytes
text data bss dec hex filename
893020 6844 7288 907152 dd790 busybox_old
893063 6844 7288 907195 dd7bb busybox_unstripped
---
networking/udhcp/dumpleases.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c
index 64cd73e..ef6ca6d 100644
--- a/networking/udhcp/dumpleases.c
+++ b/networking/udhcp/dumpleases.c
@@ -11,11 +11,13 @@
//usage: "\n -f,--file=FILE Lease file"
//usage: "\n -r,--remaining Show remaining time"
//usage: "\n -a,--absolute Show expiration time"
+//usage: "\n -d,--decimal Show time in seconds"
//usage: )
//usage: IF_NOT_LONG_OPTS(
//usage: "\n -f FILE Lease file"
//usage: "\n -r Show remaining time"
//usage: "\n -a Show expiration time"
+//usage: "\n -d Show time in seconds"
//usage: )
#include "common.h"
@@ -37,12 +39,14 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv)
OPT_a = 0x1, // -a
OPT_r = 0x2, // -r
OPT_f = 0x4, // -f
+ OPT_d = 0x8, // -d
};
#if ENABLE_LONG_OPTS
static const char dumpleases_longopts[] ALIGN1 =
"absolute\0" No_argument "a"
"remaining\0" No_argument "r"
"file\0" Required_argument "f"
+ "decimal\0" No_argument "d"
;
applet_long_options = dumpleases_longopts;
@@ -50,7 +54,7 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv)
init_unicode();
opt_complementary = "=0:a--r:r--a";
- opt = getopt32(argv, "arf:", &file);
+ opt = getopt32(argv, "arf:d", &file);
fd = xopen(file, O_RDONLY);
@@ -87,6 +91,11 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv)
puts("expired");
continue;
}
+ if (opt & OPT_d) {
+ /* decimal time - "expired" is permitted, so you can grep -v */
+ printf("%u\n", (opt & OPT_a) ? expires_abs : expires_abs - curr);
+ continue;
+ }
if (!(opt & OPT_a)) { /* no -a */
unsigned d, h, m;
unsigned expires = expires_abs - curr;
--
2.6.1
More information about the busybox
mailing list