about summary refs log tree commit diff
path: root/src/include
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-12-05 22:26:11 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-12-05 22:26:11 +0000
commit90b12bd71bb9fc79a4640b9112c13ef529d0196a (patch)
tree523b3f4ee2969e7a729bab2ba749c4b924ae62af /src/include
downloads6-90b12bd71bb9fc79a4640b9112c13ef529d0196a.tar.gz
s6-90b12bd71bb9fc79a4640b9112c13ef529d0196a.tar.xz
s6-90b12bd71bb9fc79a4640b9112c13ef529d0196a.zip
Initial commit
Diffstat (limited to 'src/include')
-rw-r--r--src/include/s6/ftrigr.h94
-rw-r--r--src/include/s6/ftrigw.h11
-rw-r--r--src/include/s6/s6-supervise.h40
-rw-r--r--src/include/s6/s6.h11
-rw-r--r--src/include/s6/s6lock.h75
5 files changed, 231 insertions, 0 deletions
diff --git a/src/include/s6/ftrigr.h b/src/include/s6/ftrigr.h
new file mode 100644
index 0000000..e7c8b0c
--- /dev/null
+++ b/src/include/s6/ftrigr.h
@@ -0,0 +1,94 @@
+/* ISC license. */
+
+#ifndef FTRIGR_H
+#define FTRIGR_H
+
+#include <skalibs/config.h>
+#include <skalibs/uint16.h>
+#include <skalibs/uint32.h>
+#include <skalibs/tai.h>
+#include <skalibs/genalloc.h>
+#include <skalibs/gensetdyn.h>
+#include <skalibs/skaclient.h>
+#include <s6/config.h>
+
+
+ /* Constants */
+
+#define FTRIGR_IPCPATH SKALIBS_SPROOT "/service/ftrigrd/s"
+
+#define FTRIGRD_PROG S6_BINPREFIX "/s6-ftrigrd"
+#define FTRIGR_BANNER1 "ftrigr v1.0 (b)\n"
+#define FTRIGR_BANNER1_LEN (sizeof FTRIGR_BANNER1 - 1)
+#define FTRIGR_BANNER2 "ftrigr v1.0 (a)\n"
+#define FTRIGR_BANNER2_LEN (sizeof FTRIGR_BANNER2 - 1)
+
+
+ /* Internals of the ftrigr_t */
+
+typedef enum fr1state_e fr1state_t, *fr1state_t_ref ;
+enum fr1state_e
+{
+  FR1STATE_WAITACK,
+  FR1STATE_WAITACKDATA,
+  FR1STATE_LISTENING,
+  FR1STATE_ERROR
+} ;
+      
+typedef struct ftrigr1_s ftrigr1_t, *ftrigr1_t_ref ;
+struct ftrigr1_s
+{
+  uint32 options ;
+  unsigned int count ;
+  fr1state_t state ;
+  char what ;
+} ;
+#define FTRIGR1_ZERO { 0, 0, FR1STATE_ERROR, 0 }
+extern ftrigr1_t const ftrigr1_zero ;
+
+
+ /* The ftrigr_t itself */
+
+typedef struct ftrigr_s ftrigr, ftrigr_t, *ftrigr_ref, *ftrigr_t_ref ;
+struct ftrigr_s
+{
+  skaclient_t connection ;
+  genalloc list ; /* array of uint16 */
+  gensetdyn data ; /* set of ftrigr1_t */
+  skaclient_buffer_t buffers ;
+} ;
+#define FTRIGR_ZERO { .connection = SKACLIENT_ZERO, .list = GENALLOC_ZERO, .data = GENSETDYN_INIT(ftrigr1_t, 2, 0, 1) }
+extern ftrigr_t const ftrigr_zero ;
+
+
+ /* Starting and ending a session */
+
+extern int ftrigr_start (ftrigr_t *, char const *, tain_t const *, tain_t *) ;
+#define ftrigr_start_g(a, path, deadline) ftrigr_start(a, path, (deadline), &STAMP)
+extern int ftrigr_startf (ftrigr_t *, tain_t const *, tain_t *) ;
+#define ftrigr_startf_g(a, deadline) ftrigr_startf(a, (deadline), &STAMP)
+extern void ftrigr_end (ftrigr_t *) ;
+                    
+
+ /* Instant primitives for async programming */
+
+#define ftrigr_fd(a) skaclient_fd(&(a)->connection)
+extern int ftrigr_update (ftrigr_t *) ;
+extern int ftrigr_check (ftrigr_t *, uint16, char *) ;
+
+
+ /* Synchronous functions with timeouts */
+
+#define FTRIGR_REPEAT 0x0001
+
+extern uint16 ftrigr_subscribe (ftrigr_t *, char const *, char const *, uint32, tain_t const *, tain_t *) ;
+#define ftrigr_subscribe_g(a, path, re, options, deadline) ftrigr_subscribe(a, path, re, options, (deadline), &STAMP)
+extern int ftrigr_unsubscribe (ftrigr_t *, uint16, tain_t const *, tain_t *) ;
+#define ftrigr_unsubscribe_g(a, id, deadline) ftrigr_unsubscribe(a, id, (deadline), &STAMP)
+
+extern int ftrigr_wait_and (ftrigr_t *, uint16 const *, unsigned int, tain_t const *, tain_t *) ;
+#define ftrigr_wait_and_g(a, list, len, deadline) ftrigr_wait_and(a, list, len, (deadline), &STAMP)
+extern int ftrigr_wait_or  (ftrigr_t *, uint16 const *, unsigned int, tain_t const *, tain_t *, char *) ;
+#define ftrigr_wait_or_g(a, list, len, deadline, what) ftrigr_wait_or(a, list, len, deadline, &STAMP, what)
+
+#endif
diff --git a/src/include/s6/ftrigw.h b/src/include/s6/ftrigw.h
new file mode 100644
index 0000000..ccaf078
--- /dev/null
+++ b/src/include/s6/ftrigw.h
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#ifndef FTRIGW_H
+#define FTRIGW_H
+
+extern int ftrigw_fifodir_make (char const *, int, int) ;
+extern int ftrigw_notify (char const *, char) ;
+extern int ftrigw_notifyb (char const *, char const *, unsigned int) ;
+extern int ftrigw_clean (char const *) ;
+
+#endif
diff --git a/src/include/s6/s6-supervise.h b/src/include/s6/s6-supervise.h
new file mode 100644
index 0000000..2a39393
--- /dev/null
+++ b/src/include/s6/s6-supervise.h
@@ -0,0 +1,40 @@
+/* ISC license. */
+
+#ifndef S6_SUPERVISE_H
+#define S6_SUPERVISE_H
+
+#include <skalibs/tai.h>
+
+#define S6_SUPERVISE_CTLDIR "supervise"
+#define S6_SUPERVISE_EVENTDIR "event"
+#define S6_SVSCAN_CTLDIR ".s6-svscan"
+#define S6_SVSTATUS_FILENAME S6_SUPERVISE_CTLDIR "/status"
+#define S6_SVSTATUS_SIZE 18
+
+extern int s6_svc_write (char const *, char const *, unsigned int) ;
+extern int s6_svc_main (int, char const *const *, char const *, char const *, char const *) ;
+
+typedef struct s6_svstatus_s s6_svstatus_t, *s6_svstatus_t_ref ;
+struct s6_svstatus_s
+{
+  tain_t stamp ;
+  unsigned int pid ;
+  unsigned int flagwant : 1 ;
+  unsigned int flagwantup : 1 ;
+  unsigned int flagpaused : 1 ;
+  unsigned int flagfinishing : 1 ;
+} ;
+
+#define S6_SVSTATUS_ZERO { .stamp = TAIN_ZERO, .pid = 0, .flagwant = 0, .flagwantup = 0, .flagpaused = 0, .flagfinishing = 0 }
+
+
+extern void s6_svstatus_pack (char *, s6_svstatus_t const *) ;
+extern void s6_svstatus_unpack (char const *, s6_svstatus_t_ref) ;
+extern int s6_svstatus_read (char const *, s6_svstatus_t_ref) ;
+extern int s6_svstatus_write (char const *, s6_svstatus_t const *) ;
+
+/* These functions leak a fd, that's intended */
+extern int s6_supervise_lock (char const *) ;
+extern int s6_supervise_lock_mode (char const *, unsigned int, unsigned int) ;
+
+#endif
diff --git a/src/include/s6/s6.h b/src/include/s6/s6.h
new file mode 100644
index 0000000..84c552d
--- /dev/null
+++ b/src/include/s6/s6.h
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#ifndef S6_H
+#define S6_H
+
+#include <s6/s6-supervise.h>
+#include <s6/ftrigr.h>
+#include <s6/ftrigw.h>
+#include <s6/s6lock.h>
+
+#endif
diff --git a/src/include/s6/s6lock.h b/src/include/s6/s6lock.h
new file mode 100644
index 0000000..a44d80a
--- /dev/null
+++ b/src/include/s6/s6lock.h
@@ -0,0 +1,75 @@
+/* ISC license. */
+
+#ifndef S6LOCK_H
+#define S6LOCK_H
+
+#include <errno.h>
+#include <skalibs/uint16.h>
+#include <skalibs/tai.h>
+#include <skalibs/genalloc.h>
+#include <skalibs/gensetdyn.h>
+#include <skalibs/skaclient.h>
+#include <s6/config.h>
+
+
+ /* Constants */
+
+#define S6LOCKD_PROG S6_BINPREFIX "/s6lockd"
+#define S6LOCKD_HELPER_PROG S6_BINPREFIX "/s6lockd-helper"
+
+#define S6LOCK_BANNER1 "s6lock v1.0 (b)\n"
+#define S6LOCK_BANNER1_LEN (sizeof S6LOCK_BANNER1 - 1)
+#define S6LOCK_BANNER2 "s6lock v1.0 (a)\n"
+#define S6LOCK_BANNER2_LEN (sizeof S6LOCK_BANNER2 - 1)
+
+
+ /* The client handle */
+
+typedef struct s6lock_s s6lock_t, *s6lock_t_ref ;
+struct s6lock_s
+{
+  skaclient_t connection ;
+  genalloc list ; /* array of uint16 */
+  gensetdyn data ; /* set of char */
+  skaclient_buffer_t buffers ;
+} ;
+#define S6LOCK_ZERO { .connection = SKACLIENT_ZERO, .list = GENALLOC_ZERO, .data = GENSETDYN_INIT(int, 2, 0, 1) }
+extern s6lock_t const s6lock_zero ;
+
+
+ /* Starting and ending a session */
+
+extern int s6lock_start (s6lock_t *, char const *, tain_t const *, tain_t *) ;
+#define s6lock_start_g(a, ipcpath, deadline) s6lock_start(a, ipcpath, (deadline), &STAMP)
+extern int s6lock_startf (s6lock_t *, char const *, tain_t const *, tain_t *) ;
+#define s6lock_startf_g(a, lockdir, deadline) s6lock_startf(a, lockdir, (deadline), &STAMP)
+extern void s6lock_end (s6lock_t *) ;
+                    
+
+ /* Asynchronous primitives */
+
+#define s6lock_fd(a) skaclient_fd(&(a)->connection)
+extern int s6lock_update (s6lock_t *) ;
+extern int s6lock_check (s6lock_t *, uint16) ;
+
+
+ /* Synchronous functions */
+
+#define S6LOCK_OPTIONS_SH 0x0000U
+#define S6LOCK_OPTIONS_EX 0x0001U
+
+extern int s6lock_acquire (s6lock_t *, uint16 *, char const *, uint32, tain_t const *, tain_t const *, tain_t *) ;
+#define s6lock_acquire_g(a, id, path, options, limit, deadline) s6lock_acquire(a, id, path, options, limit, (deadline), &STAMP)
+#define s6lock_acquire_sh(a, id, path, limit, deadline, stamp) s6lock_aquire(a, id, path, S6LOCK_OPTIONS_SH, limit, deadline, stamp)
+#define s6lock_acquire_ex(a, id, path, limit, deadline, stamp) s6lock_aquire(a, id, path, S6LOCK_OPTIONS_EX, limit, deadline, stamp)
+#define s6lock_acquire_sh_g(a, id, path, limit, deadline) s6lock_acquire_sh(a, id, path, limit, (deadline), &STAMP)
+#define s6lock_acquire_ex_g(a, id, path, limit, deadline) s6lock_acquire_ex(a, id, path, limit, (deadline), &STAMP)
+extern int s6lock_release (s6lock_t *, uint16, tain_t const *, tain_t *) ;
+#define s6lock_release_g(a, id, deadline) s6lock_release(a, id, (deadline), &STAMP)
+
+extern int s6lock_wait_and (s6lock_t *, uint16 const *, unsigned int, tain_t const *, tain_t *) ;
+#define s6lock_wait_and_g(a, list, len, deadline) s6lock_wait_and(a, list, len, (deadline), &STAMP)
+extern int s6lock_wait_or  (s6lock_t *, uint16 const *, unsigned int, tain_t const *, tain_t *) ;
+#define s6lock_wait_or_g(a, list, len, deadline) s6lock_wait_or(a, list, len, (deadline), &STAMP)
+
+#endif