diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-07-03 18:57:42 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-07-03 18:57:42 +0000 |
commit | 5dc54a39e47148803d950d2facb42500e08f4769 (patch) | |
tree | 7875d1088c002ae64b7fc962ba013e948515f1c1 /src/utilities | |
parent | a02a1c5608a47211b3e672c8834a8e8a2f917ce6 (diff) | |
download | s6-dns-5dc54a39e47148803d950d2facb42500e08f4769.tar.xz |
Add s6-dns-hosts-compile, prepare for 2.3.6.0
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/utilities')
-rw-r--r-- | src/utilities/deps-exe/s6-dns-hosts-compile | 2 | ||||
-rw-r--r-- | src/utilities/s6-dns-hosts-compile.c | 54 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/utilities/deps-exe/s6-dns-hosts-compile b/src/utilities/deps-exe/s6-dns-hosts-compile new file mode 100644 index 0000000..833e88d --- /dev/null +++ b/src/utilities/deps-exe/s6-dns-hosts-compile @@ -0,0 +1,2 @@ +${LIBS6DNS} +-lskarnet diff --git a/src/utilities/s6-dns-hosts-compile.c b/src/utilities/s6-dns-hosts-compile.c new file mode 100644 index 0000000..4a38955 --- /dev/null +++ b/src/utilities/s6-dns-hosts-compile.c @@ -0,0 +1,54 @@ +/* ISC license. */ + +#include <string.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +#include <skalibs/sgetopt.h> +#include <skalibs/strerr.h> +#include <skalibs/djbunix.h> + +#include <s6-dns/hosts.h> + +#define USAGE "s6-dns-hosts-compile [ -i ifile ] [ -o ofile ]" +#define dieusage() strerr_dieusage(100, USAGE) + +int main (int argc, char const *const *argv) +{ + char const *ifile = "/etc/hosts" ; + char const *ofile = "/etc/hosts.cdb" ; + PROG = "s6-dns-hosts-compile" ; + { + subgetopt l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "i:o:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'i' : ifile = l.arg ; break ; + case 'o' : ofile = l.arg ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + } + + { + int fdr, fdw ; + size_t len = strlen(ofile) ; + char tmp[len + 29] ; + memcpy(tmp, ofile, len) ; + memcpy(tmp + len, ":s6-dns-hosts-compile:XXXXXX", 29) ; + fdr = openc_read(ifile) ; + if (fdr == -1) strerr_diefu2sys(111, "open ", ifile) ; + fdw = mkstemp(tmp) ; + if (fdw == -1) strerr_diefu2sys(111, "create ", tmp) ; + if (!s6dns_hosts_compile(fdr, fdw)) + strerr_diefu4sys(111, "compile ", ifile, " to ", tmp) ; + if (fsync(fdw) == -1) strerr_diefu2sys(111, "fsync ", tmp) ; + if (rename(tmp, ofile) == -1) strerr_diefu4sys(111, "rename ", tmp, " to ", ofile) ; + } + return 0 ; +} |