s6-connlimit.c (970B)
1 /* ISC license. */ 2 3 #include <string.h> 4 #include <stdlib.h> 5 6 #include <skalibs/types.h> 7 #include <skalibs/strerr.h> 8 #include <skalibs/exec.h> 9 10 int main (int argc, char const *const *argv) 11 { 12 char const *x ; 13 size_t protolen ; 14 PROG = "s6-connlimit" ; 15 x = getenv("PROTO") ; 16 if (!x) strerr_dienotset(100, "PROTO") ; 17 protolen = strlen(x) ; 18 if (!protolen) strerr_dief1x(100, "empty PROTO") ; 19 { 20 unsigned int num ; 21 char s[protolen + 8] ; 22 memcpy(s, x, protolen) ; 23 memcpy(s + protolen, "CONNNUM", 8) ; 24 x = getenv(s) ; 25 if (!x) strerr_dienotset(100, s) ; 26 if (!uint0_scan(x, &num)) strerr_dief2x(100, "invalid ", s) ; 27 memcpy(s + protolen + 4, "MAX", 4) ; 28 x = getenv(s) ; 29 if (x) 30 { 31 unsigned int max ; 32 if (!uint0_scan(x, &max)) strerr_dief2x(100, "invalid ", s) ; 33 if (num > max) 34 strerr_dief2x(1, "number of connections from this client limited to ", x) ; 35 } 36 } 37 (void)argc ; 38 xexec0(argv+1) ; 39 }