From 8bffa1c19fd05f4f04dad4b5b98f85b94f23113c Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 26 Jan 2015 22:26:57 +0000 Subject: - added s6-fdholder-delete(c) - small s6-fdholder-* fixes - s6-fdholder documentation (in review) - s6_svstatus_* bugfix (thanks Olivier Brunel) --- doc/index.html | 104 ++++++++-- doc/libs6/ftrigr.html | 3 +- doc/libs6/index.html | 6 +- doc/libs6/s6-fdholder.html | 207 +++++++++++++++++++ doc/s6-fdholder-daemon.html | 147 ++++++++++++++ doc/s6-fdholder-delete.html | 71 +++++++ doc/s6-fdholder-deletec.html | 63 ++++++ doc/s6-fdholder-errorcodes.html | 72 +++++++ doc/s6-fdholder-getdump.html | 92 +++++++++ doc/s6-fdholder-getdumpc.html | 91 +++++++++ doc/s6-fdholder-list.html | 51 +++++ doc/s6-fdholder-listc.html | 68 +++++++ doc/s6-fdholder-retrieve.html | 98 +++++++++ doc/s6-fdholder-retrievec.html | 68 +++++++ doc/s6-fdholder-setdump.html | 66 +++++++ doc/s6-fdholder-setdumpc.html | 62 ++++++ doc/s6-fdholder-store.html | 80 ++++++++ doc/s6-fdholder-storec.html | 68 +++++++ doc/s6-fdholder-transferdump.html | 58 ++++++ doc/s6-fdholder-transferdumpc.html | 82 ++++++++ doc/s6-fdholderd.html | 318 ++++++++++++++++++++++++++++++ doc/s6-ipcserver.html | 25 --- doc/s6-notifywhenup.html | 4 +- doc/s6-svlisten.html | 4 +- doc/s6-svlisten1.html | 2 +- package/deps.mak | 4 + package/modes | 2 + package/targets.mak | 2 + src/fdholder/deps-exe/s6-fdholder-delete | 1 + src/fdholder/deps-exe/s6-fdholder-deletec | 4 + src/fdholder/s6-fdholder-delete.c | 51 +++++ src/fdholder/s6-fdholder-deletec.c | 42 ++++ src/fdholder/s6-fdholder-getdumpc.c | 8 +- src/fdholder/s6-fdholder-listc.c | 2 +- src/fdholder/s6-fdholder-retrievec.c | 2 +- src/fdholder/s6-fdholder-setdumpc.c | 2 +- src/fdholder/s6-fdholder-storec.c | 2 +- src/fdholder/s6-fdholder-transferdumpc.c | 4 +- src/fdholder/s6-fdholderd.c | 8 +- src/include/s6/s6-fdholder.h | 2 +- src/libs6/s6_svstatus_read.c | 4 +- src/libs6/s6_svstatus_write.c | 4 +- 42 files changed, 1987 insertions(+), 67 deletions(-) create mode 100644 doc/libs6/s6-fdholder.html create mode 100644 doc/s6-fdholder-daemon.html create mode 100644 doc/s6-fdholder-delete.html create mode 100644 doc/s6-fdholder-deletec.html create mode 100644 doc/s6-fdholder-errorcodes.html create mode 100644 doc/s6-fdholder-getdump.html create mode 100644 doc/s6-fdholder-getdumpc.html create mode 100644 doc/s6-fdholder-list.html create mode 100644 doc/s6-fdholder-listc.html create mode 100644 doc/s6-fdholder-retrieve.html create mode 100644 doc/s6-fdholder-retrievec.html create mode 100644 doc/s6-fdholder-setdump.html create mode 100644 doc/s6-fdholder-setdumpc.html create mode 100644 doc/s6-fdholder-store.html create mode 100644 doc/s6-fdholder-storec.html create mode 100644 doc/s6-fdholder-transferdump.html create mode 100644 doc/s6-fdholder-transferdumpc.html create mode 100644 doc/s6-fdholderd.html create mode 100644 src/fdholder/deps-exe/s6-fdholder-delete create mode 100644 src/fdholder/deps-exe/s6-fdholder-deletec create mode 100644 src/fdholder/s6-fdholder-delete.c create mode 100644 src/fdholder/s6-fdholder-deletec.c diff --git a/doc/index.html b/doc/index.html index 57d1ef1..7fcf79a 100644 --- a/doc/index.html +++ b/doc/index.html @@ -22,9 +22,35 @@ s6 is a small suite of programs for UNIX, designed to allow process supervision (a.k.a service supervision), in the line of daemontools -and runit. +and runit, as well as various +operations on processes and daemons. It is meant to be a toolbox for +low-level process and service administration, providing different sets of +independent tools that can be used within or without the framework, and +that can be assembled together to achieve powerful functionality with +a very small amount of code.

+

+ Examples of things you can do by assembling together several programs +provided by s6: +

+ + +

The s6 documentation tries to be complete and self-contained; however, if you have never heard of process supervision before, you might be @@ -51,11 +77,14 @@ supervision that might help you understand the basics.

Licensing

@@ -120,32 +149,24 @@ a user interface to control those processes and monitor service states.
  • The s6-notifywhenup program
  • -

    Other daemontools-like utilities

    +

    Daemontools-like utilities

    These programs are a rewrite of the corresponding utilities from daemontools, with -a few extras. The -s6-log program is important in itself: it's -a powerful, scriptable, general-purpose filtering and logging tool -that can be used to entirely replace syslogd. It has many more -features than its multilog -counterpart. +a few extras.

    Fifodir management, notification and subscription

    @@ -174,6 +195,11 @@ synchronization.
  • The s6-ftrig-listen1 program
  • The s6-ftrig-listen program
  • +

    +

    +

    Local service management and access control

    @@ -203,14 +229,44 @@ synchronization.
  • The s6-sudod program
  • -

    Internal commands

    +

    Logging

    + +

    Timed lock acquisition

    + + +

    fd-holding, a.k.a. the sensible part of socket activation

    + + +

    +

    Libraries

    @@ -220,6 +276,7 @@ synchronization.
  • The ftrigr library interface
  • The s6lock library interface
  • The accessrules library interface
  • +
  • The s6-fdholder library interface
  • Definitions

    @@ -259,6 +316,10 @@ daemontools.) approach to process supervision, with the same goals.
  • perp, yet another slightly different approach to process supervision, also with the same goals.
  • +
  • nosh +is another suite of system-level utilities with similarities in the design +and approach. It is written in C++, though, and is coded in quite a +different way than the previous items on this list.
  • Other init systems

    @@ -302,5 +363,14 @@ software, and it's short. Expect more use of s6- in future skarnet.org software releases. And please avoid using that prefix for your own projects.

    +

    Footnotes

    + +
    +

    [1] + Take everything you read on that link with two or three salt shakers. +(This is true for anything written by the author of that document.) +

    +
    + diff --git a/doc/libs6/ftrigr.html b/doc/libs6/ftrigr.html index 2c9bf88..0a83534 100644 --- a/doc/libs6/ftrigr.html +++ b/doc/libs6/ftrigr.html @@ -55,8 +55,9 @@ children, consider using a ftrigrd service. for instance, illustrate how to use the ftrigr library.

    - +

    Synchronous functions with a specified maximum execution time

    +
    diff --git a/doc/libs6/s6-fdholder.html b/doc/libs6/s6-fdholder.html new file mode 100644 index 0000000..79c4725 --- /dev/null +++ b/doc/libs6/s6-fdholder.html @@ -0,0 +1,207 @@ + + + + + s6: the s6-fdholder library interface + + + + + + +

    +libs6
    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder library interface

    + +

    + The s6-fdholder library provides an API for clients +wanting to communicate with a +s6-fdholderd daemon. +

    + +

    Programming

    + +

    + Check the s6/s6-fdholder.h header for the +exact function prototypes. +

    + +

    A programming example

    + +

    + The src/fdholder/s6-fdholder-*c.c files in the s6 package, +for instance, illustrate how to use the s6-fdholder library. +

    + + +

    Synchronous functions with a specified maximum execution time

    + +

    + The explanation given +there applies here too: the +functions documented in this page are synchronous, but can return +early if the deadline is reached, in which case the connection to the +server should be closed immediately because no protocol consistency is +guaranteed. +

    + +

    + The s6-fdholderd server should be +very quick to answer queries, so this mechanism is provided as a simple +security against programming errors - for instance, connecting to the +wrong daemon. +

    + +

    Starting and ending a session

    + +
    +s6_fdholder_t a = S6_FDHOLDER_ZERO ;
    +int fd = 6 ;
    +
    +tain_now_g() ;
    +
    +s6_fdholder_init(&a, fd) ;
    +(...)
    +s6_fdholder_free(&a) ;
    +
    + +

    +s6_fdholder_init assumes that fd is a socket already +connected to a s6-fdholderd daemon. The a structure must be +initialized to S6_FDHOLDER_ZERO before use. +

    + +

    +tain_now_g() +initializes a global variable that keeps track of the current time, for +use with later functions. +

    + +

    +s6_fdholder_free frees the resources occupied by a. +It does not, however, close fd. You should manually close it +to end the connection to the server. Note that if your program has been +started by s6-ipcclient, both fds 6 +and 7 are open (and refer to the same socket), so you should close both. +

    + +

    Storing a fd

    + +
    +int r ;
    +int fd ;
    +tain_t limit = TAIN_INFINITE ;
    +char const *id = "my_identifier" ;
    +r = s6_fdholder_store_g(&a, fd, id, &limit, &deadline) ;
    +
    + +

    +s6_fdholder_store (and its variant s6_fdholder_store_g +that uses the global timestamp variable) attempts to store a copy of +descriptor fd into s6-fdholderd, using identifier id, +with an expiration date of limit. In this example, limit +is TAIN_INFINITE, which means no expiration date. The operation should +return before deadline, else it will automatically return +0 ETIMEDOUT. The result is 1 on success and 0 on failure, with an +appropriate errno code. +

    + +

    Deleting a fd

    + +
    +fd = s6_fdholder_delete_g(&a, id, &deadline) ;
    +
    + +

    +s6_fdholder_delete attempts to delete the file descriptor +identified by id. It returns 1 on success and 0 on failure, +with an +appropriate errno code. +

    + +

    Retrieving a fd

    + +
    +fd = s6_fdholder_retrieve_g(&a, id, &deadline) ;
    +
    + +

    +s6_fdholder_retrieve attempts to retrieve the file descriptor +identified by id. It returns a valid fd number on success, and +-1 on failure, with an +appropriate errno code. +

    + +

    + s6_fdholder_retrieve_delete() performs a retrieval and a +deletion at the same time, if the client is authorized to do so. +

    + +

    Listing the identifiers held by the server

    + +
    +stralloc list = STRALLOC_ZERO ;
    +int n ;
    +n = s6_fdholder_list_g(&a, &list, &deadline) ;
    +
    + +

    +s6_fdholder_list gets the list of all identifiers currently +held by the server. It stores it into the +stralloc +list, as a series of null-terminated strings, one after the other. +There are n such strings. The function returns n on +success, or -1 on failure, with an +appropriate errno code. +

    + + +

    Reading a dump

    + +
    +genalloc dump = GENALLOC_ZERO ;
    +r = s6_fdholder_getdump_g(&a, &dump, &deadline) ;
    +
    + +

    +s6_fdholder_getdump attempts to retrieve the whole set of +descriptors from the server. +It returns 1 on success, and 0 on failure, with an +appropriate errno code. +The set is stored into the +genalloc +dump, which is to be interpreted as a stralloc containing an array +of s6_fdholder_fd_t. +

    + +

    +genalloc_s(s6_fdholder_fd_t, &dump) is a pointer to this array, and +genalloc_len(s6_fdholder_fd_t, &dump) is the number of elements +in the array. A s6_fdholder_fd_t contains at least a descriptor +number, an identifier, and an expiration date, see the +s6/s6-fdholder.h header file. +

    + +

    Writing a dump

    + +
    +unsigned int dumplen ;
    +s6_fdholder_fd_t const *dumparray ;
    +r = s6_fdholder_setdump_g(&a, &dumparray, dumplen, &deadline) ;
    +
    + +

    +s6_fdholder_setdump attempts to send a set of descriptors to the +server. The descriptors are contained in the array dumparray of +length dumplen. The function +returns 1 on success, and 0 on failure, with an +appropriate errno code. +

    + + + diff --git a/doc/s6-fdholder-daemon.html b/doc/s6-fdholder-daemon.html new file mode 100644 index 0000000..90adea0 --- /dev/null +++ b/doc/s6-fdholder-daemon.html @@ -0,0 +1,147 @@ + + + + + s6: the s6-fdholder-daemon program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-daemon program

    + +

    +s6-fdholder-daemon is a fd-holding daemon, i.e. a +long-lived program. +It listens on a Unix domain socket, then +accepts client connections; +it stores file descriptors on behalf of clients, along with an identifier +for every file descriptor stored, and possibly an expiration date (after +which the file descriptor will be forgotten). It also allows clients to +retrieve a file descriptor by its identifier. +

    + +

    Interface

    + +
    +     s6-fdholder-daemon [ -1 ] [ -v verbosity ] [ -d | -D ] [ -c maxconn ] [ -n maxfds ] [ -b backlog ] [ -G gidlist ] [ -g gid ] [ -u uid ] [ -U ] [ -t clienttimeout ] [ -T lameducktimeout ] [ -i rulesdir | -x rulesfile ] path
    +
    + + + + +

    Options

    + + + +

    Notes

    + + + + + diff --git a/doc/s6-fdholder-delete.html b/doc/s6-fdholder-delete.html new file mode 100644 index 0000000..a0fa6dd --- /dev/null +++ b/doc/s6-fdholder-delete.html @@ -0,0 +1,71 @@ + + + + + s6: the s6-fdholder-delete program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-delete program

    + +

    +s6-fdholder-delete connects to a +fd-holding daemon listening on a +Unix domain socket, and deletes a file descriptor from the +daemon storage. +

    + +

    Interface

    + +
    +     s6-fdholder-delete [ -t timeout ] path id
    +
    + + + +

    Options

    + + + +

    Usage example

    + +
    +   s6-fdholder-delete /service/fdholderd/s MYSOCKET
    +
    + +

    + will tell a +s6-fdholderd daemon listening on the /service/fdholderd/s +socket to close the filedescriptor identified as MYSOCKET. +

    + + + diff --git a/doc/s6-fdholder-deletec.html b/doc/s6-fdholder-deletec.html new file mode 100644 index 0000000..526de30 --- /dev/null +++ b/doc/s6-fdholder-deletec.html @@ -0,0 +1,63 @@ + + + + + s6: the s6-fdholder-deletec program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-deletec program

    + +

    +s6-fdholder-deletec talks to a +fd-holding daemon on its open +descriptors 6 and 7, and tells it to close a file descriptor +it's currently holding. +

    + +

    Interface

    + +
    +     s6-fdholder-deletec [ -t timeout ] id
    +
    + + + +

    Options

    + + + +

    Notes

    + + + + + diff --git a/doc/s6-fdholder-errorcodes.html b/doc/s6-fdholder-errorcodes.html new file mode 100644 index 0000000..8e41365 --- /dev/null +++ b/doc/s6-fdholder-errorcodes.html @@ -0,0 +1,72 @@ + + + + + s6: the s6-fdholder error codes + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder error codes

    + +

    + The following error messages (and corresponding +errno codes) +can be returned by the +s6-fdholderd daemon to its various clients. +This page explains why they occur. +

    + + + + + diff --git a/doc/s6-fdholder-getdump.html b/doc/s6-fdholder-getdump.html new file mode 100644 index 0000000..a339b71 --- /dev/null +++ b/doc/s6-fdholder-getdump.html @@ -0,0 +1,92 @@ + + + + + s6: the s6-fdholder-getdump program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-getdump program

    + +

    +s6-fdholder-getdump connects to a +fd-holding daemon listening on a +Unix domain socket, and retrieves its entire state: file descriptors with +their identifiers and expiration dates. It then executes a program with +those file descriptors still open, and the state stored in the +environment. +

    + +

    Interface

    + +
    +     s6-fdholder-getdump [ -t timeout ] path prog...
    +
    + + + +

    Options

    + + + +

    Usage example

    + +
    +   s6-fdholder-getdump /service/fdholderd/s s6-fdholder-setdump /service/fdholderd-2/s
    +
    + +

    +will get the state of the s6-fdholderd daemon listening on the /service/fdholderd/s +socket, and transmit it to the other s6-fdholderd daemon listening on the +/service/fdholderd-2/s socket. Note that in this precise case, +the s6-fdholder-transferdump +program does the same thing more efficiently. +

    + +

    Notes

    + + + + + diff --git a/doc/s6-fdholder-getdumpc.html b/doc/s6-fdholder-getdumpc.html new file mode 100644 index 0000000..acaf31a --- /dev/null +++ b/doc/s6-fdholder-getdumpc.html @@ -0,0 +1,91 @@ + + + + + s6: the s6-fdholder-getdumpc program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-getdumpc program

    + +

    +s6-fdholder-getdumpc talks to a +fd-holding daemon on its open +descriptors 6 and 7, and retrieves its whole state, +then executes a program with as many more file descriptors open +as were given by the daemon, plus a modified environment to +describe the retrieved state. +

    + +

    Interface

    + +
    +     s6-fdholder-retrievec [ -t timeout ] prog...
    +
    + + + +

    Options

    + + + +

    Environment format

    + +

    + prog... is executed with the following environment variables +set: +

    + + + +

    Notes

    + + + + + diff --git a/doc/s6-fdholder-list.html b/doc/s6-fdholder-list.html new file mode 100644 index 0000000..8b92506 --- /dev/null +++ b/doc/s6-fdholder-list.html @@ -0,0 +1,51 @@ + + + + + s6: the s6-fdholder-list program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-list program

    + +

    +s6-fdholder-list lists the descriptors currently held by a +fd-holding daemon. +

    + +

    Interface

    + +
    +     s6-fdholder-list [ -t timeout ] path
    +
    + + + +

    Options

    + + + + + diff --git a/doc/s6-fdholder-listc.html b/doc/s6-fdholder-listc.html new file mode 100644 index 0000000..47a2ec8 --- /dev/null +++ b/doc/s6-fdholder-listc.html @@ -0,0 +1,68 @@ + + + + + s6: the s6-fdholder-listc program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-listc program

    + +

    +s6-fdholder-listc talks to a +fd-holding daemon on its open +descriptors 6 and 7. It prints on stdout the list of identifiers +of all the fd currently held by the daemon, one per line. +

    + +

    Interface

    + +
    +     s6-fdholder-listc [ -t timeout ]
    +
    + + + +

    Options

    + + + +

    Notes

    + + + + + diff --git a/doc/s6-fdholder-retrieve.html b/doc/s6-fdholder-retrieve.html new file mode 100644 index 0000000..5231051 --- /dev/null +++ b/doc/s6-fdholder-retrieve.html @@ -0,0 +1,98 @@ + + + + + s6: the s6-fdholder-retrieve program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-retrieve program

    + +

    +s6-fdholder-retrieve connects to a +fd-holding daemon listening on a +Unix domain socket, and retrieves a file descriptor from that +daemon, then executes a program with that file descriptor as the +program's standard input. +

    + +

    Interface

    + +
    +     s6-fdholder-retrieve [ -D ] [ -t timeout ] path id prog...
    +
    + + + +

    Options

    + + + +

    Usage example

    + +
    +   s6-fdholder-store /service/fdholderd/s MYSOCKET s6-ipcserverd cat
    +
    + +

    + will retrieve a file descriptor stored under the MYSOCKET identifier in +the s6-fdholderd daemon listening on the /service/fdholderd/s +socket, and execute into s6-ipcserverd cat with that file +descriptor as stdin. In this case, if MYSOCKET referred to a Unix domain +socket, s6-ipcserverd will then accept +client connections on it and spawn a cat program for every +connection. +

    + +

    Notes

    + + + + + diff --git a/doc/s6-fdholder-retrievec.html b/doc/s6-fdholder-retrievec.html new file mode 100644 index 0000000..5724ee0 --- /dev/null +++ b/doc/s6-fdholder-retrievec.html @@ -0,0 +1,68 @@ + + + + + s6: the s6-fdholder-retrievec program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-retrievec program

    + +

    +s6-fdholder-retrievec talks to a +fd-holding daemon on its open +descriptors 6 and 7, and retrieves a file descriptor from it, +then executes a program. +

    + +

    Interface

    + +
    +     s6-fdholder-retrievec [ -D ] [ -t timeout ] id prog...
    +
    + + + +

    Options

    + + + +

    Notes

    + + + + + diff --git a/doc/s6-fdholder-setdump.html b/doc/s6-fdholder-setdump.html new file mode 100644 index 0000000..b5661e2 --- /dev/null +++ b/doc/s6-fdholder-setdump.html @@ -0,0 +1,66 @@ + + + + + s6: the s6-fdholder-setdump program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-setdump program

    + +

    +s6-fdholder-setdump connects to a +fd-holding daemon listening on a +Unix domain socket, and dumps a set of file descriptors into +that daemon. +

    + +

    Interface

    + +
    +     s6-fdholder-setdump [ -t timeout ] path
    +
    + + + +

    Options

    + + + +

    Notes

    + + + + + diff --git a/doc/s6-fdholder-setdumpc.html b/doc/s6-fdholder-setdumpc.html new file mode 100644 index 0000000..126dcf0 --- /dev/null +++ b/doc/s6-fdholder-setdumpc.html @@ -0,0 +1,62 @@ + + + + + s6: the s6-fdholder-setdumpc program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-setdumpc program

    + +

    +s6-fdholder-setdumpc talks to a +fd-holding daemon on its open +descriptors 6 and 7, and transmits it a set of file descriptors +together with a list of identifiers and expiration dates found +in its environment. +

    + +

    Interface

    + +
    +     s6-fdholder-setdumpc [ -t timeout ]
    +
    + + + +

    Options

    + + + +

    Notes

    + + + + + diff --git a/doc/s6-fdholder-store.html b/doc/s6-fdholder-store.html new file mode 100644 index 0000000..c67927d --- /dev/null +++ b/doc/s6-fdholder-store.html @@ -0,0 +1,80 @@ + + + + + s6: the s6-fdholder-store program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-store program

    + +

    +s6-fdholder-store connects to a +fd-holding daemon listening on a +Unix domain socket, and gives it a copy of one of its open file +descriptors for the daemon to hold. +

    + +

    Interface

    + +
    +     s6-fdholder-store [ -d fd ] [ -T fdtimeout ] [ -t timeout ] path id
    +
    + + + +

    Options

    + + + +

    Usage example

    + +
    +   s6-ipcserver-socketbinder /tmp/mysocket s6-fdholder-store /service/fdholderd/s MYSOCKET
    +
    + +

    + will open a Unix domain socket, bind it to /tmp/mysocket and +listen to incoming connections, then give it to a +s6-fdholderd instance listening on +/service/fdholderd/s, with no expiration date, with the +"MYSOCKET" identifier. Another program will be able to retrieve the +socket later, using s6-fdholder-retrieve. +

    + + + diff --git a/doc/s6-fdholder-storec.html b/doc/s6-fdholder-storec.html new file mode 100644 index 0000000..08180e4 --- /dev/null +++ b/doc/s6-fdholder-storec.html @@ -0,0 +1,68 @@ + + + + + s6: the s6-fdholder-storec program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-storec program

    + +

    +s6-fdholder-storec talks to a +fd-holding daemon on its open +descriptors 6 and 7, and passes it a copy of its standard +input. +

    + +

    Interface

    + +
    +     s6-fdholder-storec [ -T fdtimeout ] [ -t timeout ] id
    +
    + + + +

    Options

    + + + +

    Notes

    + + + + + diff --git a/doc/s6-fdholder-transferdump.html b/doc/s6-fdholder-transferdump.html new file mode 100644 index 0000000..714ea03 --- /dev/null +++ b/doc/s6-fdholder-transferdump.html @@ -0,0 +1,58 @@ + + + + + s6: the s6-fdholder-transferdump program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-transferdump program

    + +

    +s6-fdholder-transferdump connects to two separate +fd-holding daemons and +transfers the content of the first one to the second one. +

    + +

    Interface

    + +
    +     s6-fdholder-transferdump [ -t timeoutfrom:timeoutto ] pathfrom pathto
    +
    + + + +

    Options

    + + + + + diff --git a/doc/s6-fdholder-transferdumpc.html b/doc/s6-fdholder-transferdumpc.html new file mode 100644 index 0000000..7bd6aa0 --- /dev/null +++ b/doc/s6-fdholder-transferdumpc.html @@ -0,0 +1,82 @@ + + + + + s6: the s6-fdholder-transferdumpc program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholder-transferdumpc program

    + +

    +s6-fdholder-transferdumpc talks to two +fd-holding daemons: the source of the +transfer on its +standard input, and the destination of the transfer on its standard output, +both being +open Unix domain sockets. It retrieves the entire storage state of +the source daemon and dumps it into the destination daemon. +

    + +

    Interface

    + +
    +     s6-fdholder-transferdumpc [ -t timeoutfrom ] [ -T timeoutto ]
    +
    + + + +

    Options

    + + + +

    Notes

    + + + + + diff --git a/doc/s6-fdholderd.html b/doc/s6-fdholderd.html new file mode 100644 index 0000000..0977101 --- /dev/null +++ b/doc/s6-fdholderd.html @@ -0,0 +1,318 @@ + + + + + s6: the s6-fdholderd program + + + + + + +

    +s6
    +Software
    +skarnet.org +

    + +

    The s6-fdholderd program

    + +

    +s6-fdholderd is the serving part of the +s6-fdholder-daemon +fd-holding server. +It assumes that its stdin is a bound and listening Unix +domain socket, and +it accepts connections from clients connecting to it, and stores and +retrieves file descriptors on their behalf. +

    + +

    Interface

    + +
    +     s6-fdholderd [ -1 ] [ -v verbosity ] [ -c maxconn ] [ -n maxfds ] [ -i rulesdir | -x rulesfile ]
    +
    + + + +

    Options

    + + + +

    Signals

    + + + +

    Identifiers

    + + + + +

    Configuration

    +
    + +

    + Before running s6-fdholderd (or its wrapper +s6-fdholder-daemon), it is necessary +to configure it. This is done by a series of rules, or ruleset, +stored in either a rulesfile in the +CDB format, +or in a rulesdir, i.e. a directory in the filesystem following a +certain format. s6-fdholderd will refuse to run if neither the -i +nor the -x option have been provided. +

    + +

    + Rulesets can be converted between the rulesdir and +rulesfile formats with the +s6-accessrules-cdb-from-fs and +s6-accessrules-fs-from-cdb +conversion tools. +

    + +

    Rules format

    + +

    + The rules file, or rules directory, follows the +s6 accessrules format for uid and +gid checking. For every connecting client, s6-fdholderd matches the uid +and gid of the client against the provided ruleset, and determines what +the client is authorized to do. +

    + +

    + By default, no client is allowed to do anything - not even +connect to the server. Even root, the super-user, will be denied +access. That's why +it is essential to create a sensible ruleset prior to running the server +in order to do anything useful. +

    + +

    + The various rights that a client can have are the following (using a +rulesdir as an example, but a rulesfile works the same way): +

    + + + +

    + The other rights are defined in the "environment" part of the ruleset: +

    + + + +

    Configuration examples

    + +

    + Assuming you want to run a s6-fdholderd daemon in the +/service/fdholder directory with the -i rules option, +you should: +

    + + + +

    + Depending on your policy, you should now give certain rights to +certain users or groups. For instance: +

    + + + +

    Notes

    + + + + + diff --git a/doc/s6-ipcserver.html b/doc/s6-ipcserver.html index 855fe4b..54fe040 100644 --- a/doc/s6-ipcserver.html +++ b/doc/s6-ipcserver.html @@ -128,31 +128,6 @@ program to easily script a service that binds to a privileged socket then drops its privileges to those of a named non-root account. -

    Implementation

    - - -

    Notes

    Options

    @@ -91,7 +91,7 @@ sequentially. For that, it uses an encoding provided by execline, so it's best to only use it in execline scripts (only the execline syntax is guaranteed -to not change). There is a variant of s6-svlisten that does not use execline +not to change). There is a variant of s6-svlisten that does not use execline syntax, but only handles one service directory: s6-svlisten1. diff --git a/doc/s6-svlisten1.html b/doc/s6-svlisten1.html index f6565ed..77eda9a 100644 --- a/doc/s6-svlisten1.html +++ b/doc/s6-svlisten1.html @@ -39,7 +39,7 @@ state changes.
  • It spawns prog... as a child right after getting the initial state of the service.
  • It then blocks until the wanted state happens, then exits 0.
  • -

    +

    Options

    diff --git a/package/deps.mak b/package/deps.mak index b7163fa..d93bfb3 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -169,6 +169,10 @@ ucspilogd: private EXTRA_LIBS := ucspilogd: src/daemontools-extras/ucspilogd.o -lskarnet s6-fdholder-daemon: private EXTRA_LIBS := s6-fdholder-daemon: src/fdholder/s6-fdholder-daemon.o -lskarnet +s6-fdholder-delete: private EXTRA_LIBS := +s6-fdholder-delete: src/fdholder/s6-fdholder-delete.o -lskarnet +s6-fdholder-deletec: private EXTRA_LIBS := ${SOCKET_LIB} ${TAINNOW_LIB} +s6-fdholder-deletec: src/fdholder/s6-fdholder-deletec.o ${LIBS6} -lskarnet s6-fdholder-getdump: private EXTRA_LIBS := s6-fdholder-getdump: src/fdholder/s6-fdholder-getdump.o -lskarnet s6-fdholder-getdumpc: private EXTRA_LIBS := ${SOCKET_LIB} ${TAINNOW_LIB} diff --git a/package/modes b/package/modes index a635703..9692b1a 100644 --- a/package/modes +++ b/package/modes @@ -43,6 +43,8 @@ s6-sudoc 0755 s6-sudod 0755 s6-fdholder-daemon 0755 s6-fdholderd 0755 +s6-fdholder-delete 0755 +s6-fdholder-deletec 0755 s6-fdholder-store 0755 s6-fdholder-storec 0755 s6-fdholder-retrieve 0755 diff --git a/package/targets.mak b/package/targets.mak index ecd6fe4..277617a 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -41,6 +41,8 @@ s6-sudoc \ s6-sudod \ s6-fdholder-daemon \ s6-fdholderd \ +s6-fdholder-delete \ +s6-fdholder-deletec \ s6-fdholder-store \ s6-fdholder-storec \ s6-fdholder-retrieve \ 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 +#include +#include +#include +#include + +#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 +#include +#include +#include +#include + +#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 #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") ; } -- cgit v1.2.3