about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-06-13 22:33:51 +0000
committerLaurent Bercot <ska@appnovation.com>2023-06-13 22:33:51 +0000
commitb6a35ea862340125ed29457c9bb7e6a1295104c0 (patch)
treed51b883257b7e6521d336afe6f26aacc1422fb02
parent5088f7f28b132f07fb3e03982c5f0ace09bf65b5 (diff)
downloads6-dns-b6a35ea862340125ed29457c9bb7e6a1295104c0.tar.gz
s6-dns-b6a35ea862340125ed29457c9bb7e6a1295104c0.tar.xz
s6-dns-b6a35ea862340125ed29457c9bb7e6a1295104c0.zip
Adapt to iter_func fix
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r--src/caches/dcache_save.c25
-rw-r--r--src/skadns/skadns_end.c4
2 files changed, 14 insertions, 15 deletions
diff --git a/src/caches/dcache_save.c b/src/caches/dcache_save.c
index 04d1dac..f7ae6a4 100644
--- a/src/caches/dcache_save.c
+++ b/src/caches/dcache_save.c
@@ -1,14 +1,15 @@
 /* ISC license. */
 
 #include <stdint.h>
+#include <string.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <stdio.h>
 
 #include <skalibs/posixplz.h>
 #include <skalibs/uint16.h>
 #include <skalibs/uint64.h>
 #include <skalibs/buffer.h>
-#include <skalibs/stralloc.h>
 #include <skalibs/tai.h>
 #include <skalibs/djbunix.h>
 #include <skalibs/skamisc.h>
@@ -16,9 +17,9 @@
 
 #include <s6-dns/dcache.h>
 
-static int write_node_iter (char *data, void *aux)
+static int write_node_iter (void *data, void *aux)
 {
-  dcache_node_t *y = (dcache_node_t *)data ;
+  dcache_node_t *y = data ;
   buffer *b = aux ;
   char pack[TAI_PACK * 2 + 4] ;
   tai_pack(pack, tain_secp(&y->entry)) ;
@@ -49,26 +50,24 @@ static inline int dcache_save_to_buffer (dcache_t const *z, buffer *b)
 
 int dcache_save (dcache_t const *z, char const *file)
 {
-  stralloc sa = STRALLOC_ZERO ;
+  size_t len = strlen(file) ;
   int fd ;
   buffer b ;
   char buf[N] ;
-  if (!stralloc_cats(&sa, file)) return 0 ;
-  if (!sauniquename(&sa) || !stralloc_0(&sa)) goto err0 ;
-  fd = open_excl(sa.s) ;
-  if (fd == -1) goto err0 ;
+  char tmp[len + 20] ;
+  memcpy(tmp, file, len) ;
+  memcpy(tmp + len, ":dcache_save:XXXXXX", 20) ;
+  fd = mkstemp(tmp) ;
+  if (fd == -1) return 0 ;
   buffer_init(&b, &buffer_write, fd, buf, N) ;
   if (!dcache_save_to_buffer(z, &b) || fsync(fd) < 0) goto err2 ;
   fd_close(fd) ;
-  if (rename(sa.s, file) == -1) goto err1 ;
-  stralloc_free(&sa) ;
+  if (rename(tmp, file) == -1) goto err1 ;
   return 1 ;
 
  err2:
   fd_close(fd) ;
  err1:
-  unlink_void(sa.s) ;
- err0:
-  stralloc_free(&sa) ;
+  unlink_void(tmp) ;
   return 0 ;
 }
diff --git a/src/skadns/skadns_end.c b/src/skadns/skadns_end.c
index afcab58..c6298fa 100644
--- a/src/skadns/skadns_end.c
+++ b/src/skadns/skadns_end.c
@@ -7,9 +7,9 @@
 #include <skalibs/textclient.h>
 #include <s6-dns/skadns.h>
 
-static int skadnsanswer_free (char *p, void *stuff)
+static int skadnsanswer_free (void *p, void *stuff)
 {
-  skadnsanswer_t *q = (skadnsanswer_t_ref)p ;
+  skadnsanswer_t *q = p ;
   alloc_free(q->data) ;
   (void)stuff ;
   return 1 ;