about summary refs log tree commit diff
path: root/src/libs6
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs6')
-rw-r--r--src/libs6/ftrig1.h3
-rw-r--r--src/libs6/ftrig1_make.c54
-rw-r--r--src/libs6/ftrigw_notifyb_nosig.c15
-rw-r--r--src/libs6/s6-ftrigrd.c1
4 files changed, 25 insertions, 48 deletions
diff --git a/src/libs6/ftrig1.h b/src/libs6/ftrig1.h
index aa06b57..89f11ba 100644
--- a/src/libs6/ftrig1.h
+++ b/src/libs6/ftrig1.h
@@ -3,6 +3,7 @@
 #ifndef FTRIG1_H
 #define FTRIG1_H
 
+#include <skalibs/gccattributes.h>
 #include <skalibs/stralloc.h>
 
 #define FTRIG1_PREFIX "ftrig1"
@@ -17,7 +18,7 @@ struct ftrig1_s
 } ;
 #define FTRIG1_ZERO { .fd = -1, .fdw = -1, .name = STRALLOC_ZERO }
 
-extern void ftrig1_init (void) ;
+extern void ftrig1_init (void) gccattr_deprecated ;
 extern int ftrig1_make (ftrig1_t *, char const *) ;
 extern void ftrig1_free (ftrig1_t *) ;
 
diff --git a/src/libs6/ftrig1_make.c b/src/libs6/ftrig1_make.c
index 8f6d985..2c224e5 100644
--- a/src/libs6/ftrig1_make.c
+++ b/src/libs6/ftrig1_make.c
@@ -1,75 +1,49 @@
 /* ISC license. */
 
 #include <string.h>
-#include <sys/stat.h>
-#include <unistd.h>
 #include <stdio.h>
+
 #include <skalibs/posixplz.h>
 #include <skalibs/tai.h>
 #include <skalibs/stralloc.h>
 #include <skalibs/djbunix.h>
-#include <skalibs/surf.h>
-#include <skalibs/random.h>
-#include "ftrig1.h"
 
-static SURFSchedule surf_ctx = SURFSCHEDULE_ZERO ;
+#include "ftrig1.h"
 
 void ftrig1_init (void)
 {
-  char seed[160] ;
-  random_makeseed(seed) ;
-  surf_init(&surf_ctx, seed) ;
-}
-
-static inline void surfname (char *s, size_t n)
-{
-  static char const oklist[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZghijklmnopqrstuvwxyz-_0123456789abcdef" ;
-  surf(&surf_ctx, s, n) ;
-  while (n--) s[n] = oklist[s[n] & 63] ;
+  /* deprecated */
 }
 
 int ftrig1_make (ftrig1_t *f, char const *path)
 {
   ftrig1_t ff = FTRIG1_ZERO ;
   size_t pathlen = strlen(path) ;
-  char tmp[pathlen + 46 + FTRIG1_PREFIXLEN] ;
+  char tmp[pathlen + FTRIG1_PREFIXLEN + 36] ;
   
   memcpy(tmp, path, pathlen) ;
   tmp[pathlen] = '/' ; tmp[pathlen+1] = '.' ;
   memcpy(tmp + pathlen + 2, FTRIG1_PREFIX, FTRIG1_PREFIXLEN) ;
   tmp[pathlen + 2 + FTRIG1_PREFIXLEN] = ':' ;
   if (!timestamp(tmp + pathlen + 3 + FTRIG1_PREFIXLEN)) return 0 ;
-  tmp[pathlen + 28 + FTRIG1_PREFIXLEN] = ':' ;
-  surfname(tmp + pathlen + 29 + FTRIG1_PREFIXLEN, 16) ;
-  tmp[pathlen + 45 + FTRIG1_PREFIXLEN] = 0 ;
-  
-  {
-    mode_t m = umask(0) ;
-    if (mkfifo(tmp, S_IRUSR|S_IWUSR|S_IWGRP|S_IWOTH) == -1)
-    {
-      umask(m) ;
-      return 0 ;
-    }
-    umask(m) ;
-  }
-
-  if (!stralloc_catb(&ff.name, tmp, pathlen+1)) goto err0 ;
-  if (!stralloc_catb(&ff.name, tmp + pathlen + 2, FTRIG1_PREFIXLEN + 44)) goto err1 ;
-  ff.fd = open_read(tmp) ;
-  if (ff.fd == -1) goto err1 ;
+  memcpy(tmp + pathlen + FTRIG1_PREFIXLEN + 28, ":XXXXXX", 8) ;
+  ff.fd = mkptemp(tmp) ;
+  if (ff.fd == -1) return 0 ;
   ff.fdw = open_write(tmp) ;
-  if (ff.fdw == -1) goto err2 ;
+  if (ff.fdw == -1) goto err1 ;
+  if (!stralloc_ready(&ff.name, pathlen + FTRIG1_PREFIXLEN + 36)) goto err2 ;
+  stralloc_copyb(&ff.name, tmp, pathlen + 1) ;
+  stralloc_catb(&ff.name, tmp + pathlen + 2, FTRIG1_PREFIXLEN + 34) ;
   if (rename(tmp, ff.name.s) == -1) goto err3 ;
   *f = ff ;
   return 1 ;
 
  err3:
-  fd_close(ff.fdw) ;
+  stralloc_free(&ff.name) ;
  err2:
-  fd_close(ff.fd) ;
+  fd_close(ff.fdw) ;
  err1:
-  stralloc_free(&ff.name) ;
- err0:
+  fd_close(ff.fd) ;
   unlink_void(tmp) ;
   return 0 ;
 }
diff --git a/src/libs6/ftrigw_notifyb_nosig.c b/src/libs6/ftrigw_notifyb_nosig.c
index 38110f2..6564396 100644
--- a/src/libs6/ftrigw_notifyb_nosig.c
+++ b/src/libs6/ftrigw_notifyb_nosig.c
@@ -3,12 +3,14 @@
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
+
 #include <skalibs/posixplz.h>
 #include <skalibs/direntry.h>
 #include <skalibs/allreadwrite.h>
 #include <skalibs/djbunix.h>
-#include "ftrig1.h"
+
 #include <s6/ftrigw.h>
+#include "ftrig1.h"
 
 int ftrigw_notifyb_nosig (char const *path, char const *s, size_t len)
 {
@@ -17,9 +19,10 @@ int ftrigw_notifyb_nosig (char const *path, char const *s, size_t len)
   if (!dir) return -1 ;
   {
     size_t pathlen = strlen(path) ;
-    char tmp[pathlen + FTRIG1_PREFIXLEN + 45] ;
+    char tmp[pathlen + FTRIG1_PREFIXLEN + 35] ;
     memcpy(tmp, path, pathlen) ;
-    tmp[pathlen] = '/' ; tmp[pathlen + FTRIG1_PREFIXLEN + 44] = 0 ;
+    tmp[pathlen] = '/' ;
+    tmp[pathlen + FTRIG1_PREFIXLEN + 34] = 0 ;
     for (;;)
     {
       direntry *d ;
@@ -27,9 +30,9 @@ int ftrigw_notifyb_nosig (char const *path, char const *s, size_t len)
       errno = 0 ;
       d = readdir(dir) ;
       if (!d) break ;
-      if (strncmp(d->d_name, FTRIG1_PREFIX, FTRIG1_PREFIXLEN)) continue ;
-      if (strlen(d->d_name) != FTRIG1_PREFIXLEN + 43) continue ;
-      memcpy(tmp + pathlen + 1, d->d_name, FTRIG1_PREFIXLEN + 43) ;
+      if (strncmp(d->d_name, FTRIG1_PREFIX ":@", FTRIG1_PREFIXLEN + 2)) continue ;
+      if (strlen(d->d_name) != FTRIG1_PREFIXLEN + 33) continue ;
+      memcpy(tmp + pathlen + 1, d->d_name, FTRIG1_PREFIXLEN + 33) ;
       fd = open_write(tmp) ;
       if (fd == -1)
       {
diff --git a/src/libs6/s6-ftrigrd.c b/src/libs6/s6-ftrigrd.c
index dd04548..e9ac252 100644
--- a/src/libs6/s6-ftrigrd.c
+++ b/src/libs6/s6-ftrigrd.c
@@ -194,7 +194,6 @@ int main (void)
   if (ndelay_on(0) < 0) strerr_diefu2sys(111, "ndelay_on ", "0") ;
   if (ndelay_on(1) < 0) strerr_diefu2sys(111, "ndelay_on ", "1") ;
   if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "ignore SIGPIPE") ;
-  ftrig1_init() ;
 
   {
     tain_t deadline ;