summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-01-26 22:26:57 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-01-26 22:26:57 +0000
commit8bffa1c19fd05f4f04dad4b5b98f85b94f23113c (patch)
treef4e25c3cdb7118db02a06c85b7862107a2074ba4 /src
parent49cb17940e403431566dc7b5a312624f14eb25d0 (diff)
downloads6-8bffa1c19fd05f4f04dad4b5b98f85b94f23113c.tar.xz
- added s6-fdholder-delete(c)
- small s6-fdholder-* fixes - s6-fdholder documentation (in review) - s6_svstatus_* bugfix (thanks Olivier Brunel)
Diffstat (limited to 'src')
-rw-r--r--src/fdholder/deps-exe/s6-fdholder-delete1
-rw-r--r--src/fdholder/deps-exe/s6-fdholder-deletec4
-rw-r--r--src/fdholder/s6-fdholder-delete.c51
-rw-r--r--src/fdholder/s6-fdholder-deletec.c42
-rw-r--r--src/fdholder/s6-fdholder-getdumpc.c8
-rw-r--r--src/fdholder/s6-fdholder-listc.c2
-rw-r--r--src/fdholder/s6-fdholder-retrievec.c2
-rw-r--r--src/fdholder/s6-fdholder-setdumpc.c2
-rw-r--r--src/fdholder/s6-fdholder-storec.c2
-rw-r--r--src/fdholder/s6-fdholder-transferdumpc.c4
-rw-r--r--src/fdholder/s6-fdholderd.c8
-rw-r--r--src/include/s6/s6-fdholder.h2
-rw-r--r--src/libs6/s6_svstatus_read.c4
-rw-r--r--src/libs6/s6_svstatus_write.c4
14 files changed, 117 insertions, 19 deletions
diff --git a/src/fdholder/deps-exe/s6-fdholder-delete b/src/fdholder/deps-exe/s6-fdholder-delete
new file mode 100644
index 0000000..e7187fe
--- /dev/null
+++ b/src/fdholder/deps-exe/s6-fdholder-delete
@@ -0,0 +1 @@
+-lskarnet
diff --git a/src/fdholder/deps-exe/s6-fdholder-deletec b/src/fdholder/deps-exe/s6-fdholder-deletec
new file mode 100644
index 0000000..f3a3143
--- /dev/null
+++ b/src/fdholder/deps-exe/s6-fdholder-deletec
@@ -0,0 +1,4 @@
+${LIBS6}
+-lskarnet
+${SOCKET_LIB}
+${TAINNOW_LIB}
diff --git a/src/fdholder/s6-fdholder-delete.c b/src/fdholder/s6-fdholder-delete.c
new file mode 100644
index 0000000..7742148
--- /dev/null
+++ b/src/fdholder/s6-fdholder-delete.c
@@ -0,0 +1,51 @@
+/* ISC license. */
+
+#include <skalibs/uint.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/djbunix.h>
+#include <s6/config.h>
+
+#define USAGE "s6-fdholder-delete [ -t timeout ] socket id"
+#define dieusage() strerr_dieusage(100, USAGE)
+
+int main (int argc, char const *const *argv, char const *const *envp)
+{
+ char const *newargv[10] ;
+ unsigned int timeout = 0 ;
+ unsigned int m = 0 ;
+ char fmtt[UINT_FMT] ;
+ PROG = "s6-fdholder-delete" ;
+ {
+ subgetopt_t l = SUBGETOPT_ZERO ;
+ for (;;)
+ {
+ register int opt = subgetopt_r(argc, argv, "t:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 't' : if (!uint0_scan(l.arg, &timeout)) dieusage() ; break ;
+ default : dieusage() ;
+ }
+ }
+ argc -= l.ind ; argv += l.ind ;
+ }
+ if (argc < 2) dieusage() ;
+
+ newargv[m++] = S6_BINPREFIX "s6-ipcclient" ;
+ newargv[m++] = "-l0" ;
+ newargv[m++] = "--" ;
+ newargv[m++] = argv[0] ;
+ newargv[m++] = S6_BINPREFIX "s6-fdholder-deletec" ;
+ if (timeout)
+ {
+ fmtt[uint_fmt(fmtt, timeout)] = 0 ;
+ newargv[m++] = "-t" ;
+ newargv[m++] = fmtt ;
+ }
+ newargv[m++] = "--" ;
+ newargv[m++] = argv[1] ;
+ newargv[m++] = 0 ;
+ pathexec_run(newargv[0], newargv, envp) ;
+ strerr_dieexec(111, newargv[0]) ;
+}
diff --git a/src/fdholder/s6-fdholder-deletec.c b/src/fdholder/s6-fdholder-deletec.c
new file mode 100644
index 0000000..ce26635
--- /dev/null
+++ b/src/fdholder/s6-fdholder-deletec.c
@@ -0,0 +1,42 @@
+/* ISC license. */
+
+#include <skalibs/uint.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/tai.h>
+#include <s6/s6-fdholder.h>
+
+#define USAGE "s6-fdholder-deletec [ -t timeout ] id"
+#define dieusage() strerr_dieusage(100, USAGE)
+
+int main (int argc, char const *const *argv, char const *const *envp)
+{
+ s6_fdholder_t a = S6_FDHOLDER_ZERO ;
+ tain_t deadline ;
+ PROG = "s6-fdholder-deletec" ;
+ {
+ unsigned int t = 0 ;
+ subgetopt_t l = SUBGETOPT_ZERO ;
+ for (;;)
+ {
+ register int opt = subgetopt_r(argc, argv, "t:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ default : dieusage() ;
+ }
+ }
+ argc -= l.ind ; argv += l.ind ;
+ if (t) tain_from_millisecs(&deadline, t) ;
+ else deadline = tain_infinite_relative ;
+ }
+ if (!argc) dieusage() ;
+
+ s6_fdholder_init(&a, 6) ;
+ tain_now_g() ;
+ tain_add_g(&deadline, &deadline) ;
+ if (!s6_fdholder_delete_g(&a, argv[0], &deadline))
+ strerr_diefu1sys(1, "delete fd") ;
+ return 0 ;
+}
diff --git a/src/fdholder/s6-fdholder-getdumpc.c b/src/fdholder/s6-fdholder-getdumpc.c
index ff7fd9d..85c288c 100644
--- a/src/fdholder/s6-fdholder-getdumpc.c
+++ b/src/fdholder/s6-fdholder-getdumpc.c
@@ -41,7 +41,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
tain_now_g() ;
tain_add_g(&deadline, &deadline) ;
if (!s6_fdholder_getdump_g(&a, &dump, &deadline))
- strerr_diefu1sys(111, "get dump") ;
+ strerr_diefu1sys(1, "get dump") ;
s6_fdholder_free(&a) ;
tain_half(&halfinfinite, &tain_infinite_relative) ;
tain_add_g(&halfinfinite, &halfinfinite) ;
@@ -67,14 +67,14 @@ int main (int argc, char const *const *argv, char const *const *envp)
modifs[pos++] = '=' ;
byte_copy(modifs + pos, len, p->id) ;
pos += len ;
+ byte_copy(modifs + pos, 11, "S6_FDLIMIT_") ; pos += 11 ;
+ pos += uint_fmt(modifs + pos, i) ;
if (tain_less(&p->limit, &halfinfinite))
{
- byte_copy(modifs + pos, 11, "S6_FDLIMIT_") ; pos += 11 ;
- pos += uint_fmt(modifs + pos, i) ;
modifs[pos++] = '=' ;
pos += timestamp_fmt(modifs + pos, &p->limit) ;
- modifs[pos++] = 0 ;
}
+ modifs[pos++] = 0 ;
}
pathexec_r(argv, envp, env_len(envp), modifs, pos) ;
}
diff --git a/src/fdholder/s6-fdholder-listc.c b/src/fdholder/s6-fdholder-listc.c
index fefb676..6bd2104 100644
--- a/src/fdholder/s6-fdholder-listc.c
+++ b/src/fdholder/s6-fdholder-listc.c
@@ -43,7 +43,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
tain_now_g() ;
tain_add_g(&deadline, &deadline) ;
n = s6_fdholder_list_g(&a, &sa, &deadline) ;
- if (n < 0) strerr_diefu1sys(111, "get fd list") ;
+ if (n < 0) strerr_diefu1sys(1, "get fd list") ;
while (n--)
{
register unsigned int len = str_len(sa.s + pos) ;
diff --git a/src/fdholder/s6-fdholder-retrievec.c b/src/fdholder/s6-fdholder-retrievec.c
index 2aea31e..8b86bc4 100644
--- a/src/fdholder/s6-fdholder-retrievec.c
+++ b/src/fdholder/s6-fdholder-retrievec.c
@@ -41,7 +41,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
tain_now_g() ;
tain_add_g(&deadline, &deadline) ;
fd = s6_fdholder_retrieve_maybe_delete_g(&a, argv[0], dodelete, &deadline) ;
- if (fd < 0) strerr_diefu2sys(111, "retrieve fd for id ", argv[0]) ;
+ if (fd < 0) strerr_diefu2sys(1, "retrieve fd for id ", argv[0]) ;
else if (!fd)
{
if (uncoe(0) < 0) strerr_diefu1sys(111, "uncoe stdin") ;
diff --git a/src/fdholder/s6-fdholder-setdumpc.c b/src/fdholder/s6-fdholder-setdumpc.c
index 8a74dba..9e253d9 100644
--- a/src/fdholder/s6-fdholder-setdumpc.c
+++ b/src/fdholder/s6-fdholder-setdumpc.c
@@ -70,7 +70,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
else if (!timestamp_scan(x, &dump[i].limit)) strerr_dieinvalid(100, s) ;
}
if (!s6_fdholder_setdump_g(&a, dump, dumplen, &deadline))
- strerr_diefu1sys(111, "set dump") ;
+ strerr_diefu1sys(1, "set dump") ;
}
return 0 ;
}
diff --git a/src/fdholder/s6-fdholder-storec.c b/src/fdholder/s6-fdholder-storec.c
index 57257da..eeb0ed8 100644
--- a/src/fdholder/s6-fdholder-storec.c
+++ b/src/fdholder/s6-fdholder-storec.c
@@ -41,6 +41,6 @@ int main (int argc, char const *const *argv, char const *const *envp)
tain_add_g(&deadline, &deadline) ;
tain_add_g(&limit, &limit) ;
if (!s6_fdholder_store_g(&a, 0, argv[0], &limit, &deadline))
- strerr_diefu1sys(111, "store fd") ;
+ strerr_diefu1sys(1, "store fd") ;
return 0 ;
}
diff --git a/src/fdholder/s6-fdholder-transferdumpc.c b/src/fdholder/s6-fdholder-transferdumpc.c
index e0ed069..b5be170 100644
--- a/src/fdholder/s6-fdholder-transferdumpc.c
+++ b/src/fdholder/s6-fdholder-transferdumpc.c
@@ -41,11 +41,11 @@ int main (int argc, char const *const *argv, char const *const *envp)
tain_now_g() ;
tain_add_g(&deadline, &deadline) ;
if (!s6_fdholder_getdump_g(&a, &dump, &deadline))
- strerr_diefu1sys(111, "get dump") ;
+ strerr_diefu1sys(1, "get dump") ;
s6_fdholder_free(&a) ;
s6_fdholder_init(&a, 1) ;
tain_add_g(&deadline, &totto) ;
if (!s6_fdholder_setdump_g(&a, genalloc_s(s6_fdholder_fd_t, &dump), genalloc_len(s6_fdholder_fd_t, &dump), &deadline))
- strerr_diefu1sys(111, "set dump") ;
+ strerr_diefu1sys(1, "set dump") ;
return 0 ;
}
diff --git a/src/fdholder/s6-fdholderd.c b/src/fdholder/s6-fdholderd.c
index 0404165..218e338 100644
--- a/src/fdholder/s6-fdholderd.c
+++ b/src/fdholder/s6-fdholderd.c
@@ -243,7 +243,7 @@ static int do_store (unsigned int cc, unixmessage_t const *m)
if (numfds >= maxfds)
{
unixmessage_drop(m) ;
- return answer(c, ENOSPC) ;
+ return answer(c, ENFILE) ;
}
if (avltreen_search(fds_by_id, m->s + TAIN_PACK + 1, &pp))
{
@@ -639,7 +639,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
{
int spfd ;
int flag1 = 0 ;
- unsigned int maxconn = 40 ;
+ unsigned int maxconn = 16 ;
PROG = "s6-fdholderd" ;
{
@@ -760,7 +760,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
if (!r)
{
- if (!cont && !tain_future(&lameduckdeadline)) return 1 ;
+ if (!cont && !tain_future(&lameduckdeadline)) break ;
for (;;)
{
if (!avltreeb_min(&fdmap_deadline, &i)) break ;
@@ -793,6 +793,6 @@ int main (int argc, char const *const *argv, char const *const *envp)
else client_add(&i, fd, &rre, &wre, flags) ;
}
}
+ return (~!numfds | (!!numconn << 1)) ;
}
- return 0 ;
}
diff --git a/src/include/s6/s6-fdholder.h b/src/include/s6/s6-fdholder.h
index d15b869..af0f6c5 100644
--- a/src/include/s6/s6-fdholder.h
+++ b/src/include/s6/s6-fdholder.h
@@ -10,7 +10,7 @@
#include <skalibs/unixconnection.h>
#define S6_FDHOLDER_ID_SIZE 255
-#define S6_FDHOLDER_MAX 16
+#define S6_FDHOLDER_MAX 256
typedef struct s6_fdholder_s s6_fdholder_t, *s6_fdholder_t_ref ;
struct s6_fdholder_s
diff --git a/src/libs6/s6_svstatus_read.c b/src/libs6/s6_svstatus_read.c
index 59a31a5..334dc47 100644
--- a/src/libs6/s6_svstatus_read.c
+++ b/src/libs6/s6_svstatus_read.c
@@ -8,9 +8,9 @@ int s6_svstatus_read (char const *dir, s6_svstatus_t *status)
{
unsigned int n = str_len(dir) ;
char pack[S6_SVSTATUS_SIZE] ;
- char tmp[n + 2 + sizeof(S6_SVSTATUS_FILENAME)] ;
+ char tmp[n + 1 + sizeof(S6_SVSTATUS_FILENAME)] ;
byte_copy(tmp, n, dir) ;
- byte_copy(tmp + n, 2 + sizeof(S6_SVSTATUS_FILENAME), "/" S6_SVSTATUS_FILENAME) ;
+ byte_copy(tmp + n, 1 + sizeof(S6_SVSTATUS_FILENAME), "/" S6_SVSTATUS_FILENAME) ;
if (openreadnclose(tmp, pack, S6_SVSTATUS_SIZE) < S6_SVSTATUS_SIZE) return 0 ;
s6_svstatus_unpack(pack, status) ;
return 1 ;
diff --git a/src/libs6/s6_svstatus_write.c b/src/libs6/s6_svstatus_write.c
index 2cc8a7b..e07d744 100644
--- a/src/libs6/s6_svstatus_write.c
+++ b/src/libs6/s6_svstatus_write.c
@@ -8,9 +8,9 @@ int s6_svstatus_write (char const *dir, s6_svstatus_t const *status)
{
unsigned int n = str_len(dir) ;
char pack[S6_SVSTATUS_SIZE] ;
- char tmp[n + 2 + sizeof(S6_SVSTATUS_FILENAME)] ;
+ char tmp[n + 1 + sizeof(S6_SVSTATUS_FILENAME)] ;
byte_copy(tmp, n, dir) ;
- byte_copy(tmp + n, 2 + sizeof(S6_SVSTATUS_FILENAME), "/" S6_SVSTATUS_FILENAME) ;
+ byte_copy(tmp + n, 1 + sizeof(S6_SVSTATUS_FILENAME), "/" S6_SVSTATUS_FILENAME) ;
s6_svstatus_pack(pack, status) ;
return openwritenclose_suffix(tmp, pack, S6_SVSTATUS_SIZE, ".new") ;
}