diff --git a/doc/66-all.html b/doc/66-all.html new file mode 100644 index 0000000000000000000000000000000000000000..04e93b6bb405263a8203cee3e839c1f091261774 --- /dev/null +++ b/doc/66-all.html @@ -0,0 +1,74 @@ +<html> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Language" content="en" /> + <title>The 66 Suite: 66-all</title> + <meta name="Description" content="Detailed documentation for the 66-all command which is part of the 66 software suite" /> + <meta name="Keywords" content="66 command 66-all service supervision supervise handles database service tree" /> + <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> --> + </head> +<body> + +<p> +<a href="index.html">66</a><br /> +<a href="//obarun.org/">www.obarun.org</a> +</p> + +<h1>66-all</h1> + + <p> + This command handles all <em>services</em> for any <em>tree</em> defined for the current user of the proccess at once. + </p> + +<h2> Interface </h2> + <pre> + 66-all [ -h help ] [ -v <em>verbosity</em> ] [ -l <em>live</em> ] [ -t <em>tree</em> ] [ -T timeout ] <em>up/down</em> + </pre> + + <p> + Any enabled <em>tree</em>—see <a href="66-tree.html"><tt>66-tree -E</tt></a>—or a specific one passed with the <tt>-t</tt> option, + and an already running <em>scandir</em> will be processed. + It is a safe wrapper around <tt><a href="66-start.html">66-start</a></tt> and <tt><a href="66-stop.html">66-stop</a></tt>. + </p> + + +<h2> Options </h2> + + <ul> + <li> <tt>-h </tt> : prints this help. </li> + + <li> + <tt>-v <em>verbosity</em> </tt>: increases/decreases + the verbosity of the command. <tt>1(Default)</tt>: Only print + error messages. <tt>2</tt>: Also print warning messages. + <tt>3</tt>: Also print debugging messages. + </li> + + <li> + <tt>-l <em>live</em></tt> : changes the supervision directory of <em>service</em> to <em>live</em>. By default this will be <tt>/run/66</tt>. The default can + also be changed at compile time by passing the <tt>--livedir=<em>live</em></tt> + option to <tt>./configure</tt>. An existing absolute path is expected and + should be within a writable filesystem - likely a RAM filesystem—see <tt><a href="66-scandir.html">66-scandir</a></tt>. + </li> + <li> + <tt>-t <em>tree</em></tt> : only handles <em>service(s)</em> for <em>tree</em>. + </li> + + <li> + <tt>-T <em>timeout</em></tt></tt> : specifies a general timeout (in milliseconds) + passed to <tt>66-start</tt> or <tt>66-stop</tt>. + By default the timeout is set to 0 (infinite). + </li> + <li> + <tt>up </tt> : sends an <em>up</em> signal to every <em>service</em> inside any <em>tree</em> processed by the command. + </li> + <li> + <tt>down </tt> : sends a <em>down</em> signal to every <em>service</em> inside any <em>tree</em> processed by the command. + </li> + </ul> + +<h2> Initialization phase </h2> +<p>In case <tt>up</tt> was passed as option, <tt>66-all</tt> will automatically launch <tt><a href="66-init.html">66-init</a></tt> to initiate all <em>services</em> of the <em>trees</em> processed by the command. As described above this means either any enabled tree for the user currently launching the process or just the tree passed with the -t option.</p> +</body> +</html> diff --git a/doc/66-dbctl.html b/doc/66-dbctl.html new file mode 100644 index 0000000000000000000000000000000000000000..718f91a71b79ed3a58f13ba7849aa0e23d68defb --- /dev/null +++ b/doc/66-dbctl.html @@ -0,0 +1,76 @@ +<html> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Language" content="en" /> + <title>The 66 Suite: 66-dbctl</title> + <meta name="Description" content="Detailed documentation for the 66-dbctl command which is part of the 66 software suite" /> + <meta name="Keywords" content="66 command 66-dbctl service supervision supervise handles database service" /> + <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> --> + </head> +<body> + +<p> +<a href="index.html">66</a><br /> +<a href="//obarun.org/">www.obarun.org</a> +</p> + +<h1>66-dbctl</h1> + + <p> + This command is used to control an already supervised <em>service</em> in <em>live</em> defined in <em>tree</em>. + </p> + +<h2> Interface </h2> + <pre> + 66-dbctl [ -h help ] [ -v <em>verbosity</em> ] [ -l <em>live</em> ] [ -t <em>tree</em> ] [ -T <em>timeout</em> ] [ -u up ] [ -d down ] <em>service(s)</em> + </pre> + + <p> + 66-dbctl expects to find an already supervised <em>service</em> in <em>live</em> defined in the given <em>tree</em> and an already running <em>scandir</em>. + <br><b>(!)</b> This tool <b>only</b> deals with <b><em>'bundle'</em></b>, <b><em>'longrun'</em></b> and <b><em>'oneshot'</em></b> services—for <em>'classic'</em> services see <a href="66-svctl.html"><tt>66-svctl</tt></a>. + </p> + <p>Multiple <em>services</em> can be handled by separating their names with a space. <tt>66-dbctl</tt> gathers the services passed as argument in a list called <em>selection</em>.</p> + +<h2> Options </h2> + + <ul> + <li> <tt>-h </tt> : prints this help. </li> + + <li> + <tt>-v <em>verbosity</em> </tt>: increases/decreases + the verbosity of the command. <tt>1(Default)</tt>: Only print + error messages. <tt>2</tt>: Also print warning messages. + <tt>3</tt>: Also print debugging messages. + </li> + + <li> + <tt>-l <em>live</em></tt> : changes the supervision directory of <em>service</em> to <em>live</em>. By default this will be <tt>/run/66</tt>. The default can + also be changed at compile time by passing the <tt>--livedir=<em>live</em></tt> + option to <tt>./configure</tt>. An existing absolute path is expected and + should be within a writable filesystem - likely a RAM filesystem—see <tt><a href="66-scandir.html">66-scandir</a></tt>. + </li> + <li> + <tt>-t <em>tree</em></tt> : handles the <em>selection</em> of + the given <em>tree</em>. This option is mandatory + except if a tree was marked as 'current'—see <a href="66-tree.html"><tt>66-tree</tt></a>. + </li> + + <li> + <tt>-T <em>timeout</em></tt></tt> : specifies a general timeout (in milliseconds) + after which <tt>66-dbctl</tt> will exit 111 with an error message if the <em>selection</em> still hasn't reached the desired state for each <em>service</em>; + default is 0 (blocks indefinitely). + </li> + <li> + <tt>-u </tt> : sends an <em>up</em> signal to the <em>service</em>. + </li> + <li> + <tt>-d </tt> : sends a <em>down</em> signal to the <em>service</em>. + </li> + </ul> + +<h2> Note </h2> +<p>This tool is a safe wrapper around <tt><a href="https://skarnet.org/software/s6-rc/s6-rc.html">s6-rc</a></tt>. It exclusively handles files that form part of the <tt>66</tt> ecosystem before sending the <em>selection</em> list to +<tt>s6-rc</tt>.</p> +</body> +</html> diff --git a/doc/66-disable.html b/doc/66-disable.html index c53bf0a6bca1d7a8cc84b189ec00853f2f6fa843..6020a2621388bc6b6230a5a860b8524fb86f64a1 100644 --- a/doc/66-disable.html +++ b/doc/66-disable.html @@ -23,7 +23,7 @@ <h2> Interface </h2> <pre> - 66-disable [ -h help ] [ -v <em>verbosity</em> ] [ -l <em>live</em> ] [ -t <em>tree</em> ] [ -S stop ] <em>service(s)</em>" + 66-disable [ -h help ] [ -v <em>verbosity</em> ] [ -l <em>live</em> ] [ -t <em>tree</em> ] [ -S stop ] <em>service(s)</em> </pre> <p> diff --git a/doc/66-enable.html b/doc/66-enable.html index e68fb7e53183dbd8276b7bad1446460cc45e706e..f0e20eb3c869ea0d8a016ae05d5e1d1c1dacd1f4 100644 --- a/doc/66-enable.html +++ b/doc/66-enable.html @@ -23,11 +23,11 @@ <h2> Interface </h2> <pre> - 66-enable [ -h help ] [ -v <em>verbosity</em> ] [ -l <em>live</em> ] [ -t <em>tree</em> ] [ -f force ] [ -d <em>directory</em> ] [ -I <em>instance</em> ] [ -S start ] <em>service(s)</em>" + 66-enable [ -h help ] [ -v <em>verbosity</em> ] [ -l <em>live</em> ] [ -t <em>tree</em> ] [ -f force ] [ -S start ] <em>service(s)</em>" </pre> <p> - This tool expects to find a corresponding <a href="frontend.html">frontend service file</a>, by default at <tt>/etc/66/service</tt>. The default path can be changed at compile time + This tool expects to find a corresponding <a href="frontend.html">frontend service file</a>, a directory name (see <a href="#directory">below</a>) or a <em>service</em> instance (see <a href="#instance">below</a>), by default at <tt>/etc/66/service</tt>. The default path can be changed at compile time by passing the <tt>--with-service-path=<em>DIR</em></tt> option to <tt>./configure.</tt> It will run a parser on the frontend service file and write the result to the directory of the given <em>tree</em>—see <a href="66-tree.html">66-tree</a>. The <em>service</em> will then be available in the given <em>tree</em> for the next boot depending on the state of the @@ -63,44 +63,32 @@ <tt>-f </tt> : reenables an already enabled <em>service</em> with the given options. </li> - <li> - <tt>-d <em>directory</em></tt> : enables all service files - found at <em>directory</em> where <em>service</em> is the first one - to start—see <a href="#directory">below</a>. Can be a relative or an absolute path. If relative, <em>directory</em> - must exist by default at <tt>/etc/66/service</tt> depending on - the option given at compile time. If absolute, the current - user of the process needs to have sufficient permissions to read <em>directory</em>. - In any case <tt>66-enable</tt> expects to find at least one valid service file inside the given <em>directory</em>. - </li> - - <li> - <tt>-I <em>instance</em></tt> : creates an instanced - service named <em>instance</em> from a service template where the name of <em>service</em> must end with a '@' (commercial at).—see <a href="frontend.html#instance"><tt>frontend service file</tt></a>. - </li> - - <li> + <li> <tt>-S </tt> : starts the <em>service</em> on the fly directly after enabling it. If the state of the <em>service</em> is already up, this option will have no effect unless the <tt>-f</tt> option is used to reload it. </li> </ul> -<h2 id="dependencies">Dependencies handling</h2> -<p>In case of <tt><em>'bundle'</em></tt>, <tt><em>'longrun'</em></tt> or <tt><em>'oneshot'</em></tt> services, the dependencies chain will be automatically resolves except in use of <tt><a href="#directory">-d</a></tt> option. -It is unnecessary to manually define chained sets of dependencies. If FooA have a declared dependency FooB, FooB will be automatically added to the chain at FooA enabling process. -This is done recursively.</p> +<h2 id="dependencies">Dependency handling</h2> +<p>For <em>services</em> of type <tt><em>'bundle'</em></tt>, <tt><em>'longrun'</em></tt> or <tt><em>'oneshot'</em></tt> any existing dependency chain will be automatically resolved. +It is unnecessary to manually define chained sets of dependencies. If FooA has a declared dependency on another service with the name FooB then FooB will be automatically enabled too when enabling FooA. +This works recursively until all necessary dependencies are enabled.</p> -<h2 id="directory">The directory option</h2> +<h2 id="directory">Directory name as <em>service</em></h2> - <p>The directory option <tt>-d</tt> should only be used in specific use cases like a mixed set of <tt><em>bundle</em></tt>, <tt><em>longrun</em></tt> and <tt><em>oneshot</em></tt> + <p>When choosing to make a directory be recognised as service the path of the directory must exist by default at <tt>/etc/66/service</tt> depending on the option given at compile time. All <em>service</em> files found in this directory will be enabled. The directory can contain a mixed set of <tt><em>bundle</em></tt>, <tt><em>longrun</em></tt> and <tt><em>oneshot</em></tt> services where some of those depend on each other. The directory option is not limited to these types though. Any available service type can be part of the set.</p> <p>A good example is a set of services for the boot process. To achieve this specific task a large number of <tt><em>oneshot</em></tt> services is used along with some <tt><em>classic</em></tt> services.</p> - <p>For the parser it can be rather difficult to know which service to start first in a complex set with lots of services depending on others. - To help out on this problem it is - neccessary to tell the command which service to start before any other when using <tt>-d</tt> by passing it as the <em>service</em> argument. In most cases, the root node - of any dependency chain is a <em>bundle</em>.</p> - <p>This option and its mechanics can be subject to change in future releases of the 66-enable tool.</p> + <p>The parser automatically resolves any existing dependency chain for the processed <em>services</em> just as it would for any regular service.</p> + <p>(!) This option and its mechanics can be subject to change in future releases of the 66-enable tool.</p> +<h2 id="instance">Instanced <em>service</em></h2> + <p>An instanced <em>service</em> name from a service template can be passed as argument where the name of the <em>service</em> must end with a '@' (commercial at). + —see <a href="frontend.html#instance"><tt>frontend service file</tt></a>.</p> + <p>(!) The name of the template must be declared first immediately followed by the instance name as shown in the following example : + <pre> 66-enable tty@tty1</pre></p> + </body> </html> diff --git a/doc/66-info.html b/doc/66-info.html new file mode 100644 index 0000000000000000000000000000000000000000..9b817f16f594ba20af0ca66453545f11135b80ee --- /dev/null +++ b/doc/66-info.html @@ -0,0 +1,192 @@ +<html> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Language" content="en" /> + <title>The 66 Suite: 66-info</title> + <meta name="Description" content="Detailed documentation for the 66-info command which is part of the 66 software suite" /> + <meta name="Keywords" content="66 command 66-info scandir supervision supervise set service information" /> + <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> --> + </head> +<body> + +<p> +<a href="index.html">66</a><br /> +<a href="//obarun.org/">www.obarun.org</a> +</p> + +<h1>66-info</h1> + + <p> + This command displays information about trees and services. + </p> + +<h2>Interface </h2> +<h3>Main interface</h3> + <pre> + 66-info [ -h help ] [ -T tree ] [ -S service ] + </pre> +<h3>Tree sub interface</h3> + <pre> + 66-info [ -T ] [ -h help ] [ -v <em>verbosity</em> ] [ -r recurse ] [ -d <em>depth</em> ] <em>tree</em> + </pre> +<h3>Service sub interface</h3> + <pre> + 66-info [ -S ] [ -h help ] [ -v <em>verbosity</em> ] [ -l live ] [ -p n lines ] [ -r recurse ] [ -d <em>depth</em> ] <em>service</em> + </pre> + <p> + 66-info displays detailed information about a <em>tree</em> or a specific <em>service</em> depending on the options passed. + </p> + +<h2>Main Options </h2> + + <ul> + <li> + <tt>-h </tt> : prints this help. + </li> + <li> + <tt>-T </tt> : asks for <em>tree</em> information. + </li> + <li> + <tt>-S </tt> : asks for <em>service</em> information. + </li> + </ul> +<h2>Tree sub options </h2> + <ul> + <li> + <tt>-h </tt> : prints this help. + </li> + <li> + <tt>-v <em>verbosity</em> </tt> : increases/decreases + the verbosity of the command. <tt>1(Default)</tt>: Only print + error messages. <tt>2</tt>: Also print warning messages. + <tt>3</tt>: Also print debugging messages. + </li> + + <li> + <tt>-r </tt> : shows the dependency graph of <em>tree</em>. + </li> + + <li> + <tt>-d <em>depth</em> </tt> : limits the depth of the dependency graph visualisation; defaults to 1. + </li> + + <p>(!) If <em>tree</em> is not specified <tt>66-info</tt> will display information about all available trees for the current owner of the process.</p> + </ul> + +<h2>Service sub options </h2> + <ul> + <li> + <tt>-h </tt> : prints this help. + </li> + <li> + <tt>-v <em>verbosity</em> </tt> : increases/decreases + the verbosity of the command. <tt>1(Default)</tt>: Only print + error messages. <tt>2</tt>: Also print warning messages. + <tt>3</tt>: Also print debugging messages. + </li> + <li> + <tt>-l <em>live</em> </tt> : changes the supervision directory of <em>service</em> to <em>live</em>. By default this will be <tt>/run/66</tt>. The default can + also be changed at compile time by passing the <tt>--livedir=<em>live</em></tt> + option to <tt>./configure</tt>. An existing absolute path is expected and + should be within a writable filesystem - likely a RAM filesystem—see <tt><a href="66-scandir.html">66-scandir</a></tt>. + </li> + <li> + <tt>-p <em>n lines</em> </tt> : prints the <em>n</em> last lines from the associated log file of the <em>service</em>. + </li> + <li> + <tt>-r </tt> : shows the dependency graph of <em>service</em>. + </li> + <li> + <tt>-d <em>depth</em> </tt> : limits the depth of the dependency graph visualisation; defaults to 1. + </li> + </ul> + +<h2>Tree output display example</h2> + + <p>The command <tt>66-info -T boot</tt> as root user on the <em>Obarun</em> default system displays the following where <em>boot</em> + is the tree used to properly boot the machine: + <pre> + [Name:boot,Current:no,Enabled:no] + ├─All :bundle + ├─boot-extra :oneshot + ├─all-Rwfs :bundle + ├─rwfs-tmpfiles :oneshot + ├─rwfs-66local :oneshot + ├─rwfs-dmesglog :oneshot + ├─rwfs-end :oneshot + ├─rwfs-logfiles :oneshot + ├─rwfs-random :oneshot + ├─rwfs-localtime :oneshot + ├─rwfs-nofilesystem :oneshot + ├─rwfs-loopback :oneshot + ├─rwfs-ip6tables :oneshot + ├─rwfs-iptables :oneshot + ├─rwfs-tmpdir :oneshot + ├─rwfs-fsrw :oneshot + ├─all-Rofs :bundle + ├─rofs-kernruntime :oneshot + ├─rofs-swap :oneshot + ├─rofs-modules :oneshot + ├─rofs-Checkfs :bundle + ├─checkfs-fscheck :oneshot + |─checkfs-lvm :oneshot + ├─checkfs-btrfs :oneshot + ├─checkfs-dmraid :oneshot + ├─rofs-hardclock :oneshot + ├─rofs-console :oneshot + ├─rofs-Udevd :bundle + ├─udevd-udevadm :oneshot + ├─udevd-udev :longrun + ├─rofs-kernmod :oneshot + ├─rofs-cgroups :oneshot + ├─00 :bundle + ├─hostname :oneshot + ├─conf :oneshot + ├─filesystem :oneshot + └─tty12 :classic + </pre> + </p> + <p>The first line gives you useful information about the <em>tree</em> itself where <tt><em>Name</em></tt> is the name of the tree, + <tt><em>Current</em></tt> tells if the <em>tree</em> is the current one or not—see <tt><a href="66-tree.html">66-tree -c</a></tt> and + <tt><em>Enabled</em></tt> reveals the state of the tree—see <tt><a href="66-tree.html">66-tree -E</a></tt>. + In addition to the name of each service the type of the service is shown next to it. + </p> + <p> + By default the dependency graph is rendered in order of execution. In this example the <em>'bundle' All</em> is the last finished + service and <em>'classic' tty12</em> is the first one executed. + </p> + +<h2>Service output display example</h2> + + <p>The command <tt>sudo 66-info -S -d3 00</tt> displays the following where <em>00</em> + is the name of the service: + <pre> [00] + tree : boot + status : nothing to display + type : bundle + description : mount filesystem, parse the 66.conf file, set the hostname + contents : + └─00 :bundle + ├─filesystem :oneshot + ├─conf :oneshot + │ └─filesystem :oneshot + └─hostname :oneshot + └─conf :oneshot + </pre> + </p> + <p>Let's take another example, the command sudo <tt>66-info -S -p5 ntpd</tt> displays the following: + <pre> [ntpd] + tree : root + status : up (pid 11458) 30 seconds + type : classic + description : ntpd daemon + logger at : /var/log/66/ntpd + 2018-12-14 17:56:11.876483500 peer 43.245.48.27 now valid + 2018-12-14 17:56:11.876508500 reply from 43.245.48.27: offset -0.000546 delay 0.035899, next query 5s + 2018-12-14 17:56:12.946922500 reply from 103.106.66.123: offset 0.018069 delay 0.069026, next query 8s + 2018-12-14 17:56:12.947754500 reply from 103.239.8.22: offset 0.001671 delay 0.069848, next query 6s + </pre> + </p> +</body> +</html> diff --git a/doc/66-start.html b/doc/66-start.html index 65f2044f9e4b3404fcac92833b7d94e7092e1520..81cba6277181f532936704035a1bc3c7c93a61ed 100644 --- a/doc/66-start.html +++ b/doc/66-start.html @@ -23,7 +23,7 @@ <h2> Interface </h2> <pre> - 66-start [ -h help ] [ -v <em>verbosity</em> ] [ -l <em>live</em> ] [ -t <em>tree</em> ] [ -T <em>timeout</em> ] [ -r reload ] <em>service(s)</em>" + 66-start [ -h help ] [ -v <em>verbosity</em> ] [ -l <em>live</em> ] [ -t <em>tree</em> ] [ -T <em>timeout</em> ] [ -r reload ] <em>service(s)</em> </pre> <p> diff --git a/doc/66-stop.html b/doc/66-stop.html new file mode 100644 index 0000000000000000000000000000000000000000..6151a9d6a08f02413ab3087200bc679af40c1b0a --- /dev/null +++ b/doc/66-stop.html @@ -0,0 +1,116 @@ +<html> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Language" content="en" /> + <title>The 66 Suite: 66-stop</title> + <meta name="Description" content="Detailed documentation for the 66-stop command which is part of the 66 software suite" /> + <meta name="Keywords" content="66 command 66-stop service supervision supervise stop service" /> + <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> --> + </head> +<body> + +<p> +<a href="index.html">66</a><br /> +<a href="//obarun.org/">www.obarun.org</a> +</p> + +<h1>66-stop</h1> + + <p> + This command stops one ore more <em>services</em> defined in <em>tree</em>. + </p> + +<h2> Interface </h2> + <pre> + 66-stop [ -h help ] [ -v <em>verbosity</em> ] [ -l <em>live</em> ] [ -t <em>tree</em> ] [ -T <em>timeout</em> ] [ -u unsupervise ] <em>service</em>" + </pre> + + <p> + The <em>service</em> to be stopped is expected to be enabled inside the given <em>tree</em> and started inside an already running <em>scandir</em>. + If the state of the <em>service</em> is already down <tt>66-stop</tt> does nothing. + Generally speaking this command is the strict opposite of <tt><a href="66-start.html">66-start</a></tt>.</p> + <p>Multiple <em>services</em> can be stopped by seperating their names with a space.</p> + +<h2> Options </h2> + + <ul> + <li> <tt>-h </tt> : prints this help. </li> + + <li> + <tt>-v <em>verbosity</em> </tt> : increases/decreases + the verbosity of the command. <tt>1(Default)</tt>: Only print + error messages. <tt>2</tt>: Also print warning messages. + <tt>3</tt>: Also print debugging messages. + </li> + + <li> + <tt>-l <em>live</em> </tt> : changes the supervision directory of <em>service</em> to <em>live</em>. By default this will be <tt>/run/66</tt>. The default can + also be changed at compile time by passing the <tt>--livedir=<em>live</em></tt> + option to <tt>./configure</tt>. An existing absolute path is expected and + should be within a writable filesystem - likely a RAM filesystem—see <tt><a href="66-scandir.html">66-scandir</a></tt>. + </li> + <li> + <tt>-t <em>tree</em> </tt> : stops <em>service</em> in + the given <em>tree</em>. This option is mandatory + except if a tree was marked as 'current'—see <a href="66-tree.html"><tt>66-tree</tt></a>. + </li> + + <li> + <tt>-T <em>timeout</em> </tt></tt> : specifies a timeout (in milliseconds) + after which <tt>66-stop</tt> will exit 111 with an error message if the service still hasn't reached the up state; + defaults to 1000. + </li> + + <li> + <tt>-u </tt> : unsupervise the <em>service</em>. + Remove the <em>service</em> directory from the <em>scandir</em> at the end of the stop process. This option only applies to services of type <tt><em>'classic'</em></tt>. + </li> + + </ul> +<h2 id="dependencies">Dependency handling</h2> +<p>For <em>services</em> of type <tt><em>'bundle'</em></tt>, <tt><em>'longrun'</em></tt> or <tt><em>'oneshot'</em></tt> any existing dependency chain will be resolved automatically. +It is unnecessary to manually define chained sets of dependencies. If FooA has a declared dependency on another service with the name FooB then FooB will be automatically considered and stopped first when stopping FooA. +This works recursively until all dependencies are stopped.</p> + +<h2>Classic service transitions</h2> + + <p> + <ul> + <li> + <tt>66-stop</tt> gathers the classic service(s) passed as argument in a list called <em>selection</em>. + </li> + <li> + The <em>selection</em> is then inspected and searched for any logger that may be associated with the passed <em>service(s)</em>. + If any such instruction was found the corresponding logger will be added to the <em>selection</em> as well. + </li> + <li> + The command continues issueing <tt>66-svctl -v <em>verbosity</em> -T <em>timeout</em> -l <em>live</em> -t <em>tree</em> -D <em>selection</em></tt> + and waits for the resulting exit code. + </li> + <li> + Finally the <em>service</em> directory is removed from the <em>scandir</em>. + </li> + </ul> + </p> +<p>If any one of these processes fails then as a result <tt>66-stop</tt> fails too and exits with code 111.</p> +<h2>Bundle, longrun, oneshot transitions</h2> + <p>The process for these service types is very similar to that of classic services except for the automated command that adapts accordingly. + <ul> + <li> + <tt>66-stop</tt> gathers the bundle, longrun and/or oneshot service(s) passed as argument in a list called <em>selection</em>. + </li> + <li> + The <em>selection</em> is then inspected and searched for any logger that may be associated with the passed <em>service(s)</em>. + If any such instruction was found the corresponding logger will be added to the <em>selection</em> as well. + </li> + <li> + Finally the command issues <tt>66-dbctl -v <em>verbosity</em> -T <em>timeout</em> -l <em>live</em> -t <em>tree</em> -d <em>selection</em></tt> + and waits for the resulting exit code. + </li> + </ul> + </p> +<p>If any one of these processes fails then as a result <tt>66-stop</tt> fails too and exits with code 111.</p> + +</body> +</html> diff --git a/doc/66-svctl.html b/doc/66-svctl.html new file mode 100644 index 0000000000000000000000000000000000000000..ec47c0b11befbd51d328e1cc276252a61c88a52c --- /dev/null +++ b/doc/66-svctl.html @@ -0,0 +1,96 @@ +<html> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Language" content="en" /> + <title>The 66 Suite: 66-svctl</title> + <meta name="Description" content="Detailed documentation for the 66-svctl command which is part of the 66 software suite" /> + <meta name="Keywords" content="66 command 66-svctl service supervision supervise handles service" /> + <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> --> + </head> +<body> + +<p> +<a href="index.html">66</a><br /> +<a href="//obarun.org/">www.obarun.org</a> +</p> + +<h1>66-svctl</h1> + + <p> + This command is used to control an already supervised <em>service</em> at <em>live</em> defined in a <em>tree</em>. + </p> + +<h2> Interface </h2> + <pre> + 66-svctl [ -h help ] [ -v <em>verbosity</em> ] [ -l <em>live</em> ] [ -t <em>tree</em> ] [ -T <em>timeout</em> ] [ -S <em>service timeout</em> ] [ -n <em>death</em> ] [ -u|U up ] [ -d|D down ] <em>service(s)</em> + </pre> + + <p> + This tool expects to find an already supervised <em>service</em> at <em>live</em> defined in the given <em>tree</em> and an already running <em>scandir</em>. + <br>(!) This tool only deals with <em>'classic'</em> services—see <a href="66-dbctl.html"><tt>66-dbctl</tt></a> for other types of services. + </p> + <p>Multiple <em>services</em> can be handled by seperating their names with a space. <tt>66-svctl</tt> gathers each of these services in a list called <em>selection</em>.</p> + +<h2> Options </h2> + + <ul> + <li> <tt>-h </tt> : prints this help. </li> + + <li> + <tt>-v <em>verbosity</em> </tt> : increases/decreases + the verbosity of the command. <tt>1(Default)</tt>: Only print + error messages. <tt>2</tt>: Also print warning messages. + <tt>3</tt>: Also print debugging messages. + </li> + + <li> + <tt>-l <em>live</em> </tt> : changes the supervision directory of <em>service</em> to <em>live</em>. By default this will be <tt>/run/66</tt>. The default can + also be changed at compile time by passing the <tt>--livedir=<em>live</em></tt> + option to <tt>./configure</tt>. An existing absolute path is expected and + should be within a writable filesystem - likely a RAM filesystem—see <tt><a href="66-scandir.html">66-scandir</a></tt>. + </li> + <li> + <tt>-t <em>tree</em> </tt> : handles the <em>service</em> from + the given <em>tree</em>. This option is mandatory + except if a tree was marked as 'current'—see <a href="66-tree.html"><tt>66-tree</tt></a>. + </li> + + <li> + <tt>-T <em>timeout</em> </tt></tt> : specifies a general timeout (in milliseconds) + after which <tt>66-svctl</tt> will exit 111 with an error message if the <em>selection</em> still hasn't reached the desired state for each <em>service</em>; + defaults to 0 (blocks indefinitely). + </li> + + <li> + <tt>-S <em>service timeout</em> </tt> : specifies a timeout (in milliseconds) + after which <tt>66-svctl</tt> will exit 111 with an error message if the <em>services</em> still hasn't reached the desired state. + This option has <strong>no effect</strong> if a <em>timeout-up</em> (for <em>up</em> signal) or <em>timeout-down</em> (for <em>down</em> signal) was defined + for the given service at parsing time—see <tt><a href="66-frontend.html">frontend</a></tt>. + If this option is not specified and no <em>timeout-up</em> or <em>timeout-down</em> file exists the timeout will default to 1000. + </li> + + <li> + <tt>-n <em>death</em> </tt> : specifies the maximum number of service death events that the supervisor will keep track of. + If the service dies more than this number of times, <tt>66-svctl</tt> will exit 111 with an error message if the <em>services</em> still hasn't reached the desired state. + This option has <strong>no effect</strong> if a <em>maxdeath</em> was defined for the given service at parsing time—see <tt><a href="66-frontend.html">frontend</a></tt>. + If this option is not specified and no <em>max-death-tally</em> file exists the maximum allowed deaths will default to 3. + </li> + <li> + <tt>-u|U </tt> : sends an <em>up</em> signal to the <em>service</em>. Uppercase <tt>U</tt> asks for readiness notification and searches for a <em>notification-fd</em> + file—see <tt><a href="https://skarnet.org/software/s6/notifywhenup.html">service startup notifications</a></tt> and <tt><a href="66-frontend.html">frontend</a></tt>. + If this file doesn't exist <tt>66-svctl</tt> will automatically change to lowercase <tt>u</tt> and warn the user about the change. + </li> + <li> + <tt>-d|D </tt> : sends a <em>down</em> signal to the <em>service</em>. Uppercase <tt>D</tt> asks for readiness notification and searches for a <em>notification-fd</em> + file—see <tt><a href="https://skarnet.org/software/s6/notifywhenup.html">service startup notifications</a></tt> and <tt><a href="66-frontend.html">frontend</a></tt>. + If this file doesn't exist <tt>66-svctl</tt> will automatically change to lowercase <tt>d</tt> and warn the user about the change. + </li> + </ul> +<h2> Note </h2> +<p>You can also send a signal in a similar fashion to a <em>'classic'</em> service with the <tt><a href="https://skarnet.org/software/s6/s6-svc.html">s6-svc</a></tt> tool which has the philosophy <em>"launch and forget"</em>. +In contrast to <tt>s6-svctl</tt> this does not care for the exit status of the service when a signal is sent.</p> +<p>As an extra convenience the <tt>-S</tt> and <tt>-n</tt> options allow you to deal directly on the command line with +<em>timeout-up</em> and <em>timeout-down</em> even if these were not specified explicitely in the services frontend file and no corresponding files exist.</p> +</body> +</html> diff --git a/doc/66-tree.html b/doc/66-tree.html index c9257019280d7c4ea0504476c95e3fef3b21193a..4abf64930a41d32329fd6588c58eba706dac0128 100644 --- a/doc/66-tree.html +++ b/doc/66-tree.html @@ -23,7 +23,7 @@ <h2> Interface </h2> <pre> - 66-tree [ -h help ] [ -v <em>verbosity</em> ] [ -n new ] [ -a allow <em>user,user,...</em> ] [ -d deny <em>user,user,...</em> ] [ -c current ] [ -E enable ] [ -D disable ] [ -R remove ] [ -C <em>clone</em> ] <em>tree</em>" + 66-tree [ -h help ] [ -v <em>verbosity</em> ] [ -n new ] [ -a allow <em>user,user,...</em> ] [ -d deny <em>user,user,...</em> ] [ -c current ] [ -E enable ] [ -D disable ] [ -R remove ] [ -C <em>clone</em> ] <em>tree</em> </pre> <p> diff --git a/doc/66-vm.mpg b/doc/66-vm.mpg new file mode 100644 index 0000000000000000000000000000000000000000..0c1751d19e70e4f8319943ff286a7cc679374aa0 Binary files /dev/null and b/doc/66-vm.mpg differ diff --git a/doc/execl-cmdline.html b/doc/execl-cmdline.html new file mode 100644 index 0000000000000000000000000000000000000000..06c17aafe2a7f560bca067095c39c696fe9bc696 --- /dev/null +++ b/doc/execl-cmdline.html @@ -0,0 +1,83 @@ +<html> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Language" content="en" /> + <title>The 66 Suite: execl-cmdline</title> + <meta name="Description" content="Detailed documentation for the execl-cmdline command which is part of the 66 software suite" /> + <meta name="Keywords" content="66 command execl-cmdline service supervision execute script execline" /> + <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> --> + </head> +<body> + +<p> +<a href="index.html">66</a><br /> +<a href="//obarun.org/">www.obarun.org</a> +</p> + +<h1>execl-cmdline</h1> + + <p> + This command parses a <em>command</em> line into an <a href="https://skarnet.org/software/execline"><tt>execline</tt></a> script. + </p> + + +<h2> Interface </h2> + + <p> + As <a href="execlineb.html">execlineb</a> script: + </p> + + <pre> + execl-cmdline -S { <em>command</em> } + </pre> + + <ul> + <li> + <tt>execl-cmdline</tt> reads the <em>command</em> and removes all whitespace or 'no word' before executing. + </li> + <li> + <tt>execl-cmdline</tt> exits with the exit code of the <em>command</em>. + </li> + </ul> + +<h2> Options </h2> + + <ul> + <li> + <tt>-S </tt> : splits a command considered by <em>execline</em> scripting language as one word into separate words. + </li> + </ul> + +<h2> Note and usage examples </h2> + <p><tt>execl-cmdline</tt> should be used at the end of <em>execline</em> scripts. If you want to run another program after the call of <tt>execl-cmdline</tt> you would need to use an + <a href="https://skarnet.org/software/execline/if.html"><tt>if</tt></a> command, <a href="https://skarnet.org/software/execline/foreground.html"><tt>foreground</tt></a>, + <a href="https://skarnet.org/software/execline/background.html"><tt>background</tt></a> or the likes.</p> + <p> + The following <em>command</em>: + <pre> + execl-cmdline { /usr/bin/ntpd -d "" -S } + </pre> + will result in: + <pre> + /usr/bin/ntpd "-d" "-S" + </pre> + </p> + <p> + This <em>command</em>: + <pre> + execl-cmdline -S { /usr/bin/ntpd "-d -S" } + </pre> + will result in: + <pre> + /usr/bin/ntpd "-d" "-S" + </pre> + </p> + <p> + To run another program after the call of <em>execl-cmdline</em> program: + <pre> + foreground { execl-cmdline { /usr/bin/ntpd -d "" -S } } + </pre> + </p> +</body> +</html> diff --git a/doc/frontend.html b/doc/frontend.html index 8beb03b14c367887945af4586a532adea9048fe8..90c0450cdb974841db14a1dd83fc113ac44874be 100644 --- a/doc/frontend.html +++ b/doc/frontend.html @@ -497,6 +497,23 @@ MYVALUE</pre> is used.</p> </li> </ul> + + +<br><hr style="border: 1px dashed #000000"> + + <li><h4>@down-signal</h4></li> + <h5>Corresponds to the file "<em>down-signal</em>" of s6-rc and s6 programs.</h5> + <p><tt>mandatory </tt> : no + </p><p><tt>syntax </tt> : uint</p> + <p><tt>valid value </tt> :</p> + <ul> + <li>The name or number of a signal. + <p>This will create the file <tt>down-signal</tt> which is + used to kill the supervised process when a <tt><a href="66-start.html">66-start -r</a></tt> or + <tt><a href="66-stop.html">66-stop</a></tt> command is used. + If the file does not exist SIGTERM will be used by default. </p> + </li> + </ul> </ul> <br><hr> @@ -807,7 +824,7 @@ for it in your <tt>@execute</tt> field.</p> @build = auto @execute = ( agetty -J 38400 @I } ) </pre> - <p>By using <tt><a href="66-enable.html">66-enable -I tty1 tty@</a></tt>, the resulting file will then be: </p> + <p>By using <tt><a href="66-enable.html">66-enable tty@tty1</a></tt>, the resulting file will then be: </p> <pre> [main] @type = classic @name = tty1 @@ -837,6 +854,7 @@ for it in your <tt>@execute</tt> field.</p> @timeout-up = @timeout-down = @maxdeath = + @down-signal = [start] @build = auto,custom diff --git a/doc/index.html b/doc/index.html index 73d9f6fb4a140f168e1b625d869189605c94a693..2acf4bff9bb35aa7f9e72f3cd4567ef62243635d 100644 --- a/doc/index.html +++ b/doc/index.html @@ -35,9 +35,9 @@ <li> Handling of any s6 and s6-rc service </li> <li> Backup a complete set of services.</li> <li> Controlling the environment of the init file. </li> - <li>Controlling permissions for the use of services and <a href="https://skarnet.org/software/s6/scandir.html">scandir</a>.</li> - </li> + <li> Controlling permissions for the use of services and <a href="https://skarnet.org/software/s6/scandir.html">scandir</a>.</li> <li> Nested supervision tree. </li> + <li> Instance service file creation. </li> </ul> <p> @@ -86,6 +86,7 @@ <li><a href="66-disable.html"><tt>66-disable</tt></a></li> <li><a href="66-start.html"><tt>66-start</tt></a></li> <li><a href="66-stop.html"><tt>66-stop</tt></a></li> + <li><a href="66-info.html"><tt>66-info</tt></a></li> </ul> <h3> execline tools </h3> diff --git a/package/deps.mak b/package/deps.mak index b3bf4a35a0162f5ba3ba01f05823a4979eaf211f..e9dfd77b212f0ca190e7517560915e97e7e1e821 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -11,13 +11,14 @@ src/66/66-dbctl.o src/66/66-dbctl.lo: src/66/66-dbctl.c src/include/66/constants src/66/66-disable.o src/66/66-disable.lo: src/66/66-disable.c src/include/66/backup.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/graph.h src/include/66/tree.h src/include/66/utils.h src/66/66-enable.o src/66/66-enable.lo: src/66/66-enable.c src/include/66/backup.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/graph.h src/include/66/parser.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h src/66/66-info.o src/66/66-info.lo: src/66/66-info.c src/include/66/constants.h src/include/66/enum.h src/include/66/graph.h src/include/66/tree.h src/include/66/utils.h -src/66/66-init.o src/66/66-init.lo: src/66/66-init.c src/include/66/backup.h src/include/66/constants.h src/include/66/db.h src/include/66/tree.h src/include/66/utils.h +src/66/66-init.o src/66/66-init.lo: src/66/66-init.c src/include/66/backup.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h src/66/66-scandir.o src/66/66-scandir.lo: src/66/66-scandir.c src/include/66/config.h src/include/66/constants.h src/include/66/utils.h src/66/66-start.o src/66/66-start.lo: src/66/66-start.c src/include/66/backup.h src/include/66/config.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h src/66/66-stop.o src/66/66-stop.lo: src/66/66-stop.c src/include/66/backup.h src/include/66/config.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h -src/66/66-svctl.o src/66/66-svctl.lo: src/66/66-svctl.c src/include/66/constants.h src/include/66/tree.h src/include/66/utils.h +src/66/66-svctl.o src/66/66-svctl.lo: src/66/66-svctl.c src/include/66/constants.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h src/66/66-tree.o src/66/66-tree.lo: src/66/66-tree.c src/include/66/config.h src/include/66/constants.h src/include/66/db.h src/include/66/tree.h src/include/66/utils.h -src/66/execl-cmdline.o src/66/execl-cmdline.lo: src/66/execl-cmdline.c +src/extra-tools/66-envfile.o src/extra-tools/66-envfile.lo: src/extra-tools/66-envfile.c src/include/66/parser.h +src/extra-tools/execl-cmdline.o src/extra-tools/execl-cmdline.lo: src/extra-tools/execl-cmdline.c src/lib66/backup_cmd_switcher.o src/lib66/backup_cmd_switcher.lo: src/lib66/backup_cmd_switcher.c src/include/66/constants.h src/include/66/enum.h src/include/66/utils.h src/lib66/backup_make_new.o src/lib66/backup_make_new.lo: src/lib66/backup_make_new.c src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/tree.h src/include/66/utils.h src/lib66/backup_realpath_sym.o src/lib66/backup_realpath_sym.lo: src/lib66/backup_realpath_sym.c src/include/66/constants.h src/include/66/enum.h src/include/66/utils.h @@ -45,20 +46,17 @@ src/lib66/set_livetree.o src/lib66/set_livetree.lo: src/lib66/set_livetree.c src src/lib66/set_ownerhome.o src/lib66/set_ownerhome.lo: src/lib66/set_ownerhome.c src/include/66/config.h src/include/66/utils.h src/lib66/set_ownersysdir.o src/lib66/set_ownersysdir.lo: src/lib66/set_ownersysdir.c src/include/66/config.h src/include/66/utils.h src/lib66/sv_alltype_zero.o src/lib66/sv_alltype_zero.lo: src/lib66/sv_alltype_zero.c src/include/66/parser.h -src/lib66/svc_init.o src/lib66/svc_init.lo: src/lib66/svc_init.c +src/lib66/svc_init.o src/lib66/svc_init.lo: src/lib66/svc_init.c src/include/66/svc.h src/include/66/utils.h +src/lib66/svc_init_pipe.o src/lib66/svc_init_pipe.lo: src/lib66/svc_init_pipe.c src/include/66/svc.h src/include/66/utils.h src/lib66/svc_switch_to.o src/lib66/svc_switch_to.lo: src/lib66/svc_switch_to.c src/include/66/backup.h src/include/66/enum.h src/include/66/utils.h src/lib66/tree_cmd_state.o src/lib66/tree_cmd_state.lo: src/lib66/tree_cmd_state.c src/include/66/constants.h src/include/66/utils.h -src/lib66/tree_cmd_switcher.o src/lib66/tree_cmd_switcher.lo: src/lib66/tree_cmd_switcher.c src/include/66/constants.h src/include/66/utils.h src/lib66/tree_copy.o src/lib66/tree_copy.lo: src/lib66/tree_copy.c src/include/66/constants.h src/include/66/tree.h src/include/66/utils.h -src/lib66/tree_copy_tmp.o src/lib66/tree_copy_tmp.lo: src/lib66/tree_copy_tmp.c src/include/66/constants.h src/include/66/tree.h src/include/66/utils.h +src/lib66/tree_copy_tmp.o src/lib66/tree_copy_tmp.lo: src/lib66/tree_copy_tmp.c src/include/66/constants.h src/include/66/enum.h src/include/66/tree.h src/include/66/utils.h src/lib66/tree_find_current.o src/lib66/tree_find_current.lo: src/lib66/tree_find_current.c src/include/66/constants.h src/include/66/utils.h -src/lib66/tree_from_current.o src/lib66/tree_from_current.lo: src/lib66/tree_from_current.c src/include/66/constants.h src/include/66/utils.h src/lib66/tree_get_permissions.o src/lib66/tree_get_permissions.lo: src/lib66/tree_get_permissions.c src/include/66/constants.h src/include/66/utils.h -src/lib66/tree_make_backup.o src/lib66/tree_make_backup.lo: src/lib66/tree_make_backup.c src/include/66/constants.h src/include/66/db.h src/include/66/tree.h src/include/66/utils.h src/lib66/tree_sethome.o src/lib66/tree_sethome.lo: src/lib66/tree_sethome.c src/include/66/constants.h src/include/66/tree.h src/lib66/tree_setname.o src/lib66/tree_setname.lo: src/lib66/tree_setname.c src/include/66/tree.h src/lib66/tree_switch_current.o src/lib66/tree_switch_current.lo: src/lib66/tree_switch_current.c src/include/66/config.h src/include/66/constants.h src/include/66/tree.h src/include/66/utils.h -src/lib66/tree_switch_tobackup.o src/lib66/tree_switch_tobackup.lo: src/lib66/tree_switch_tobackup.c src/include/66/constants.h src/include/66/db.h src/include/66/tree.h src/include/66/utils.h 66-all: EXTRA_LIBS := 66-all: src/66/66-all.o ${LIB66} -loblibs -ls6 -lskarnet @@ -82,12 +80,14 @@ src/lib66/tree_switch_tobackup.o src/lib66/tree_switch_tobackup.lo: src/lib66/tr 66-svctl: src/66/66-svctl.o ${LIB66} -loblibs -ls6 -lskarnet 66-tree: EXTRA_LIBS := 66-tree: src/66/66-tree.o ${LIB66} -loblibs -lskarnet +66-envfile: EXTRA_LIBS := +66-envfile: src/extra-tools/66-envfile.o ${LIB66} -lexecline -loblibs -lskarnet ${LIBEXECLINE} execl-cmdline: EXTRA_LIBS := -execl-cmdline: src/66/execl-cmdline.o -lexecline -loblibs -lskarnet +execl-cmdline: src/extra-tools/execl-cmdline.o -lexecline -loblibs -lskarnet ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) -lib66.a.xyzzy: src/lib66/backup_cmd_switcher.o src/lib66/backup_make_new.o src/lib66/backup_realpath_sym.o src/lib66/db_cmd_master.o src/lib66/db_compile.o src/lib66/db_find_compiled_state.o src/lib66/db_get_permissions.o src/lib66/db_ok.o src/lib66/db_switch_to.o src/lib66/db_update.o src/lib66/dir_cmpndel.o src/lib66/get_enum.o src/lib66/get_uidgid.o src/lib66/get_userhome.o src/lib66/graph.o src/lib66/parser.o src/lib66/parser_utils.o src/lib66/parser_write.o src/lib66/resolve.o src/lib66/scandir_ok.o src/lib66/scandir_send_signal.o src/lib66/set_livedir.o src/lib66/set_livescan.o src/lib66/set_livetree.o src/lib66/set_ownerhome.o src/lib66/set_ownersysdir.o src/lib66/sv_alltype_zero.o src/lib66/svc_switch_to.o src/lib66/tree_cmd_state.o src/lib66/tree_cmd_switcher.o src/lib66/tree_copy.o src/lib66/tree_copy_tmp.o src/lib66/tree_find_current.o src/lib66/tree_from_current.o src/lib66/tree_get_permissions.o src/lib66/tree_make_backup.o src/lib66/tree_sethome.o src/lib66/tree_setname.o src/lib66/tree_switch_current.o src/lib66/tree_switch_tobackup.o +lib66.a.xyzzy: src/lib66/backup_cmd_switcher.o src/lib66/backup_make_new.o src/lib66/backup_realpath_sym.o src/lib66/db_cmd_master.o src/lib66/db_compile.o src/lib66/db_find_compiled_state.o src/lib66/db_get_permissions.o src/lib66/db_ok.o src/lib66/db_switch_to.o src/lib66/db_update.o src/lib66/dir_cmpndel.o src/lib66/get_enum.o src/lib66/get_uidgid.o src/lib66/get_userhome.o src/lib66/graph.o src/lib66/parser.o src/lib66/parser_utils.o src/lib66/parser_write.o src/lib66/resolve.o src/lib66/scandir_ok.o src/lib66/scandir_send_signal.o src/lib66/set_livedir.o src/lib66/set_livescan.o src/lib66/set_livetree.o src/lib66/set_ownerhome.o src/lib66/set_ownersysdir.o src/lib66/sv_alltype_zero.o src/lib66/svc_init.o src/lib66/svc_init_pipe.o src/lib66/svc_switch_to.o src/lib66/tree_cmd_state.o src/lib66/tree_copy.o src/lib66/tree_copy_tmp.o src/lib66/tree_find_current.o src/lib66/tree_get_permissions.o src/lib66/tree_sethome.o src/lib66/tree_setname.o src/lib66/tree_switch_current.o else -lib66.a.xyzzy: src/lib66/backup_cmd_switcher.lo src/lib66/backup_make_new.lo src/lib66/backup_realpath_sym.lo src/lib66/db_cmd_master.lo src/lib66/db_compile.lo src/lib66/db_find_compiled_state.lo src/lib66/db_get_permissions.lo src/lib66/db_ok.lo src/lib66/db_switch_to.lo src/lib66/db_update.lo src/lib66/dir_cmpndel.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/graph.lo src/lib66/parser.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/resolve.lo src/lib66/scandir_ok.lo src/lib66/scandir_send_signal.lo src/lib66/set_livedir.lo src/lib66/set_livescan.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_switch_to.lo src/lib66/tree_cmd_state.lo src/lib66/tree_cmd_switcher.lo src/lib66/tree_copy.lo src/lib66/tree_copy_tmp.lo src/lib66/tree_find_current.lo src/lib66/tree_from_current.lo src/lib66/tree_get_permissions.lo src/lib66/tree_make_backup.lo src/lib66/tree_sethome.lo src/lib66/tree_setname.lo src/lib66/tree_switch_current.lo src/lib66/tree_switch_tobackup.lo +lib66.a.xyzzy: src/lib66/backup_cmd_switcher.lo src/lib66/backup_make_new.lo src/lib66/backup_realpath_sym.lo src/lib66/db_cmd_master.lo src/lib66/db_compile.lo src/lib66/db_find_compiled_state.lo src/lib66/db_get_permissions.lo src/lib66/db_ok.lo src/lib66/db_switch_to.lo src/lib66/db_update.lo src/lib66/dir_cmpndel.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/graph.lo src/lib66/parser.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/resolve.lo src/lib66/scandir_ok.lo src/lib66/scandir_send_signal.lo src/lib66/set_livedir.lo src/lib66/set_livescan.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_init.lo src/lib66/svc_init_pipe.lo src/lib66/svc_switch_to.lo src/lib66/tree_cmd_state.lo src/lib66/tree_copy.lo src/lib66/tree_copy_tmp.lo src/lib66/tree_find_current.lo src/lib66/tree_get_permissions.lo src/lib66/tree_sethome.lo src/lib66/tree_setname.lo src/lib66/tree_switch_current.lo endif lib66.so.xyzzy: EXTRA_LIBS := -loblibs -lskarnet -lib66.so.xyzzy: src/lib66/backup_cmd_switcher.lo src/lib66/backup_make_new.lo src/lib66/backup_realpath_sym.lo src/lib66/db_cmd_master.lo src/lib66/db_compile.lo src/lib66/db_find_compiled_state.lo src/lib66/db_get_permissions.lo src/lib66/db_ok.lo src/lib66/db_switch_to.lo src/lib66/db_update.lo src/lib66/dir_cmpndel.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/graph.lo src/lib66/parser.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/resolve.lo src/lib66/scandir_ok.lo src/lib66/scandir_send_signal.lo src/lib66/set_livedir.lo src/lib66/set_livescan.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_switch_to.lo src/lib66/tree_cmd_state.lo src/lib66/tree_cmd_switcher.lo src/lib66/tree_copy.lo src/lib66/tree_copy_tmp.lo src/lib66/tree_find_current.lo src/lib66/tree_from_current.lo src/lib66/tree_get_permissions.lo src/lib66/tree_make_backup.lo src/lib66/tree_sethome.lo src/lib66/tree_setname.lo src/lib66/tree_switch_current.lo src/lib66/tree_switch_tobackup.lo +lib66.so.xyzzy: src/lib66/backup_cmd_switcher.lo src/lib66/backup_make_new.lo src/lib66/backup_realpath_sym.lo src/lib66/db_cmd_master.lo src/lib66/db_compile.lo src/lib66/db_find_compiled_state.lo src/lib66/db_get_permissions.lo src/lib66/db_ok.lo src/lib66/db_switch_to.lo src/lib66/db_update.lo src/lib66/dir_cmpndel.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/graph.lo src/lib66/parser.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/resolve.lo src/lib66/scandir_ok.lo src/lib66/scandir_send_signal.lo src/lib66/set_livedir.lo src/lib66/set_livescan.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_init.lo src/lib66/svc_init_pipe.lo src/lib66/svc_switch_to.lo src/lib66/tree_cmd_state.lo src/lib66/tree_copy.lo src/lib66/tree_copy_tmp.lo src/lib66/tree_find_current.lo src/lib66/tree_get_permissions.lo src/lib66/tree_sethome.lo src/lib66/tree_setname.lo src/lib66/tree_switch_current.lo diff --git a/package/modes b/package/modes index 89f1f624ea4961bd6d9dec29eb4b21416dddbaf4..6f4cf32e99bab359f8f8c5eca4822076ac6e7eda 100644 --- a/package/modes +++ b/package/modes @@ -3,6 +3,7 @@ 66-tree 0755 66-dbctl 0755 66-enable 0755 +66-envfile 0755 66-disable 0755 66-start 0755 66-stop 0755 diff --git a/package/targets.mak b/package/targets.mak index fbe986d76de530e289334e736d776312065f822e..29b53db8de1d2e41f1beec5f4484b438682adf88 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -4,6 +4,7 @@ BIN_TARGETS := \ 66-tree \ 66-dbctl \ 66-enable \ +66-envfile \ 66-disable \ 66-start \ 66-stop \ diff --git a/src/66/66-all.c b/src/66/66-all.c index af6ba11456abae34d9c820c9e171877282ca7ef7..8d292ac69c728c7772942845853e8436dded7f48 100644 --- a/src/66/66-all.c +++ b/src/66/66-all.c @@ -14,6 +14,8 @@ #include <string.h> #include <sys/stat.h> +#include <sys/ioctl.h> +#include <fcntl.h> #include <oblibs/error2.h> #include <oblibs/obgetopt.h> @@ -31,6 +33,8 @@ #include <skalibs/direntry.h> #include <skalibs/tai.h> #include <skalibs/unix-transactional.h> +#include <skalibs/selfpipe.h> +#include <skalibs/sig.h> #include <66/constants.h> #include <66/config.h> @@ -43,9 +47,9 @@ //#include <stdio.h> unsigned int VERBOSITY = 1 ; -static tain_t DEADLINE ; +static unsigned int DEADLINE = 0 ; unsigned int trc = 0 ; -#define USAGE "66-all [ -h help ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] up/down" +#define USAGE "66-all [ -h ] [ -v verbosity ] [ -f ] [ -T timeout ] [ -l live ] [ -t tree ] up/down" static inline void info_help (void) { @@ -58,12 +62,14 @@ static inline void info_help (void) " -T: timeout\n" " -l: live directory\n" " -t: tree to use\n" +" -f: fork the process\n" ; if (buffer_putsflush(buffer_1, help) < 0) strerr_diefu1sys(111, "write to stdout") ; } + int doit(char const *tree,char const *treename,char const *live, unsigned int what, char const *const *envp) { int wstat ; @@ -92,25 +98,16 @@ int doit(char const *tree,char const *treename,char const *live, unsigned int wh VERBO3 strerr_warnwu2x("add Master as service to ", what ? "start" : "stop") ; return 0 ; } - tain_now_g() ; - tain_add_g(&DEADLINE, &DEADLINE) ; + char const *newargv[10 + genalloc_len(stralist,&ga)] ; unsigned int m = 0 ; char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; - - int globalt ; - tain_t globaltto ; - tain_sub(&globaltto,&DEADLINE, &STAMP) ; - globalt = tain_to_millisecs(&globaltto) ; - if (!globalt) globalt = 1 ; - if (globalt > 0 && (!trc || (unsigned int) globalt < trc)) - trc = (uint32_t)globalt ; - + char tt[UINT32_FMT] ; - tt[uint32_fmt(tt,trc)] = 0 ; - + tt[uint32_fmt(tt,DEADLINE)] = 0 ; + if (what) newargv[m++] = SS_BINPREFIX "66-start" ; else @@ -135,23 +132,40 @@ int doit(char const *tree,char const *treename,char const *live, unsigned int wh VERBO3 strerr_warnwu2sys("wait for ",newargv[0]) ; return 0 ; } - if (wstat) + if (wstat) return 0 ; + + return 1 ; +} + +static void redir_fd(void) +{ + int fd ; + while((fd = open("/dev/tty",O_RDWR|O_NOCTTY)) >= 0) { - VERBO3 strerr_warnwu3x(what ? "start" : "stop"," classic services for tree: ", treename) ; - return 0 ; + if (fd >= 3) break ; } - - return 1 ; + dup2 (fd,0) ; + dup2 (fd,1) ; + dup2 (fd,2) ; + fd_close(fd) ; + + if (setsid() < 0) strerr_diefu1sys(111,"setsid") ; + if ((chdir("/")) < 0) strerr_diefu1sys(111,"chdir") ; + ioctl(0,TIOCSCTTY,1) ; + + umask(022) ; } + int main(int argc, char const *const *argv,char const *const *envp) { int r ; int what ; int wstat ; + int shut = 0 ; pid_t pid ; - unsigned int tmain = 0 ; uid_t owner ; + int fd ; char const *treename = NULL ; @@ -171,7 +185,7 @@ int main(int argc, char const *const *argv,char const *const *envp) for (;;) { - int opt = getopt_args(argc,argv, ">hv:l:T:t:", &l) ; + int opt = getopt_args(argc,argv, ">hv:l:T:t:f", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) @@ -181,8 +195,9 @@ int main(int argc, char const *const *argv,char const *const *envp) case 'l' : if (!stralloc_cats(&live,l.arg)) retstralloc(111,"main") ; if (!stralloc_0(&live)) retstralloc(111,"main") ; break ; - case 'T' : if (!uint0_scan(l.arg, &tmain)) exitusage() ; break ; + case 'T' : if (!uint0_scan(l.arg, &DEADLINE)) exitusage() ; break ; case 't' : treename = l.arg ; break ; + case 'f' : shut = 1 ; break ; default : exitusage() ; } } @@ -195,12 +210,6 @@ int main(int argc, char const *const *argv,char const *const *envp) else if (*argv[0] == 'd') what = 0 ; else exitusage() ; - if (tmain){ - tain_from_millisecs(&DEADLINE, tmain) ; - trc = tmain ; - } - else DEADLINE = tain_infinite_relative ;; - owner = MYUID ; if (!set_ownersysdir(&base,owner)) strerr_diefu1sys(111, "set owner directory") ; @@ -264,6 +273,28 @@ int main(int argc, char const *const *argv,char const *const *envp) return 0 ; } + if (shut) + { + pid_t dpid ; + int wstat = 0 ; + + dpid = fork() ; + + if (dpid < 0) strerr_diefu1sys(111,"fork") ; + else if (dpid > 0) + { + if (waitpid_nointr(dpid,&wstat, 0) < 0) + strerr_diefu1sys(111,"wait for child") ; + + if (wstat) + strerr_dief1x(111,"child fail") ; + + goto end ; + + } + else redir_fd() ; + } + for (unsigned int i = 0 ; i < genalloc_len(stralist,&in) ; i++) { tree = stralloc_zero ; @@ -310,16 +341,26 @@ int main(int argc, char const *const *argv,char const *const *envp) return -1 ; } } - if (!doit(tree.s,treename,live.s,what,envp)) strerr_diefu2x(111,"start service for tree: ",treename) ; + + if (!doit(tree.s,treename,live.s,what,envp)) strerr_warnwu3x((what) ? "start" : "stop" , " service for tree: ",treename) ; } - - stralloc_free(&base) ; - stralloc_free(&live) ; - stralloc_free(&tree) ; - stralloc_free(&livetree) ; - stralloc_free(&scandir) ; - stralloc_free(&contents) ; - genalloc_deepfree(stralist,&in,stra_free) ; + end: + while((fd = open("/dev/tty",O_RDWR|O_NOCTTY)) >= 0) + { + if (fd >= 3) break ; + } + dup2 (fd,0) ; + dup2 (fd,1) ; + dup2 (fd,2) ; + fd_close(fd) ; + + stralloc_free(&base) ; + stralloc_free(&live) ; + stralloc_free(&tree) ; + stralloc_free(&livetree) ; + stralloc_free(&scandir) ; + stralloc_free(&contents) ; + genalloc_deepfree(stralist,&in,stra_free) ; return 0 ; } diff --git a/src/66/66-dbctl.c b/src/66/66-dbctl.c index cbace12d791ff57838c181b42600eacbdb113cbc..6620080e147c60e0c8b0ce19fdbf01963fad03be 100644 --- a/src/66/66-dbctl.c +++ b/src/66/66-dbctl.c @@ -43,10 +43,10 @@ //#include <stdio.h> unsigned int VERBOSITY = 1 ; -static tain_t DEADLINE ; +static unsigned int DEADLINE = 0 ; stralloc saresolve = STRALLOC_ZERO ; -#define USAGE "66-dbctl [ -h help ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -u up ] [ -d down ] service(s)" +#define USAGE "66-dbctl [ -h ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -u | d | r ] service(s)" static inline void info_help (void) { @@ -61,16 +61,46 @@ static inline void info_help (void) " -t: tree to use\n" " -u: bring up service in database of tree\n" " -d: bring down service in database of tree\n" +" -r: reload service\n" ; if (buffer_putsflush(buffer_1, help) < 0) strerr_diefu1sys(111, "write to stdout") ; } +static pid_t send(genalloc *gasv, char const *livetree, char const *signal,char const *const *envp) +{ + char const *newargv[10 + genalloc_len(stralist,gasv)] ; + unsigned int m = 0 ; + char fmt[UINT_FMT] ; + fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; + + char tt[UINT32_FMT] ; + tt[uint32_fmt(tt,DEADLINE)] = 0 ; + + newargv[m++] = S6RC_BINPREFIX "s6-rc" ; + newargv[m++] = "-v" ; + newargv[m++] = fmt ; + newargv[m++] = "-t" ; + newargv[m++] = tt ; + newargv[m++] = "-l" ; + newargv[m++] = livetree ; + newargv[m++] = signal ; + newargv[m++] = "change" ; + + for (unsigned int i = 0 ; i<genalloc_len(stralist,gasv); i++) + newargv[m++] = gaistr(gasv,i) ; + + newargv[m++] = 0 ; + + + return child_spawn0(newargv[0],newargv,envp) ; + +} int main(int argc, char const *const *argv,char const *const *envp) { int r ; - unsigned int up, down, tmain, trc ; + unsigned int up, down, reload ; int wstat ; pid_t pid ; @@ -78,6 +108,8 @@ int main(int argc, char const *const *argv,char const *const *envp) uid_t owner ; char *treename = 0 ; + char *signal = 0 ; + char *mainsv = "Master" ; stralloc base = STRALLOC_ZERO ; stralloc tree = STRALLOC_ZERO ; @@ -87,7 +119,7 @@ int main(int argc, char const *const *argv,char const *const *envp) genalloc gasv = GENALLOC_ZERO ; //stralist - up = down = tmain = trc = 0 ; + up = down = reload = 0 ; PROG = "66-dbctl" ; { @@ -95,7 +127,7 @@ int main(int argc, char const *const *argv,char const *const *envp) for (;;) { - int opt = getopt_args(argc,argv, "hv:l:t:udT:", &l) ; + int opt = getopt_args(argc,argv, "hv:l:t:udT:r", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) @@ -105,26 +137,21 @@ int main(int argc, char const *const *argv,char const *const *envp) case 'l' : if (!stralloc_cats(&live,l.arg)) retstralloc(111,"main") ; if (!stralloc_0(&live)) retstralloc(111,"main") ; break ; - case 'T' : if (!uint0_scan(l.arg, &tmain)) exitusage() ; break ; + case 'T' : if (!uint0_scan(l.arg, &DEADLINE)) exitusage() ; break ; case 't' : if(!stralloc_cats(&tree,l.arg)) retstralloc(111,"main") ; if(!stralloc_0(&tree)) retstralloc(111,"main") ; break ; case 'u' : up = 1 ; if (down) exitusage() ; break ; case 'd' : down = 1 ; if (up) exitusage() ; break ; + case 'r' : reload = 1 ; if (down || up) exitusage() ; break ; default : exitusage() ; } } argc -= l.ind ; argv += l.ind ; } - if (argc < 1) exitusage() ; + if (argc < 1) if (!stra_add(&gasv,mainsv)) strerr_diefu1sys(111,"add: Master as service to handle") ; - if (tmain){ - tain_from_millisecs(&DEADLINE, tmain) ; - trc = tmain ; - } - else DEADLINE = tain_infinite_relative ; - owner = MYUID ; if (!set_ownersysdir(&base,owner)) strerr_diefu1sys(111, "set owner directory") ; @@ -168,62 +195,29 @@ int main(int argc, char const *const *argv,char const *const *envp) if (!stralloc_cats(&livetree,treename)) retstralloc(111,"main") ; if (!stralloc_0(&livetree)) retstralloc(111,"main") ; - char const *newargv[10 + genalloc_len(stralist,&gasv)] ; - unsigned int m = 0 ; - char fmt[UINT_FMT] ; - fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; - - int globalt ; - tain_t globaltto ; - tain_sub(&globaltto,&DEADLINE, &STAMP) ; - globalt = tain_to_millisecs(&globaltto) ; - if (!globalt) globalt = 1 ; - if (globalt > 0 && (!trc || (unsigned int) globalt < trc)) - trc = (uint32_t)globalt ; - - char tt[UINT32_FMT] ; - tt[uint32_fmt(tt,trc)] = 0 ; - - newargv[m++] = S6RC_BINPREFIX "s6-rc" ; - newargv[m++] = "-v" ; - newargv[m++] = fmt ; - newargv[m++] = "-t" ; - newargv[m++] = tt ; - newargv[m++] = "-l" ; - newargv[m++] = livetree.s ; - if (down) - { - newargv[m++] = "-d" ; - } - else + if (reload) { - newargv[m++] = "-u" ; + pid = send(&gasv,livetree.s,"-d",envp) ; + + if (waitpid_nointr(pid,&wstat, 0) < 0) + strerr_diefu1sys(111,"wait for s6-rc") ; + + if (wstat) + { + if (down) + strerr_diefu1x(111,"bring down services list") ; + else + strerr_diefu1x(111,"bring up services list") ; + } } - newargv[m++] = "change" ; - for (unsigned int i = 0 ; i<genalloc_len(stralist,&gasv); i++) - newargv[m++] = gaistr(&gasv,i) ; + if (down) signal = "-d" ; + else signal = "-u" ; - newargv[m++] = 0 ; - - - /** implementation of a sigpipe is needed here in case of - * INT signal */ - int spfd = selfpipe_init() ; - if (spfd < 0) VERBO3 strerr_diefu1sys(111,"init selfpipe") ; - { - sigset_t set ; - sigemptyset(&set) ; - sigaddset(&set, SIGCHLD) ; - sigaddset(&set, SIGINT) ; - sigaddset(&set, SIGTERM) ; - if (selfpipe_trapset(&set) < 0) - strerr_diefu1sys(111,"trap signals") ; - } + pid = send(&gasv,livetree.s,signal,envp) ; - pid = child_spawn0(newargv[0],newargv,envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) - strerr_diefu2sys(111,"wait for ",newargv[0]) ; + strerr_diefu1sys(111,"wait for s6-rc") ; if (wstat) { @@ -232,7 +226,6 @@ int main(int argc, char const *const *argv,char const *const *envp) else strerr_diefu1x(111,"bring up services list") ; } - /** we are forced to do this ugly check cause of the design * of s6-rc(generally s6-svc) which is launch and forgot. So * s6-rc will not warn us if the daemon fail when we don't use @@ -242,7 +235,6 @@ int main(int argc, char const *const *argv,char const *const *envp) * between the end of the s6-rc process and the check of the daemon status, * the real value of the status can be not written yet,so we can hit * this window.*/ - int e = 0 ; s6_svstatus_t status = S6_SVSTATUS_ZERO ; stralloc stat = STRALLOC_ZERO ; if (!stralloc_catb(&stat,livetree.s,livetree.len - 1)) retstralloc(111,"main") ; @@ -284,7 +276,6 @@ int main(int argc, char const *const *argv,char const *const *envp) } } - selfpipe_finish() ; stralloc_free(&base) ; stralloc_free(&live) ; stralloc_free(&tree) ; @@ -295,7 +286,7 @@ int main(int argc, char const *const *argv,char const *const *envp) stralloc_free(&saresolve) ; free(treename) ; - return e ; + return 0 ; } diff --git a/src/66/66-disable.c b/src/66/66-disable.c index 0e16eaf01a663230180944303210162b399ac569..cd700b4269247dc4fddc25010a4fb787858e6d88 100644 --- a/src/66/66-disable.c +++ b/src/66/66-disable.c @@ -46,7 +46,7 @@ static stralloc saresolve = STRALLOC_ZERO ; unsigned int VERBOSITY = 1 ; -#define USAGE "66-disable [ -h help ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -S stop ] service(s)" +#define USAGE "66-disable [ -h help ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -S ] service(s)" static inline void info_help (void) { diff --git a/src/66/66-enable.c b/src/66/66-enable.c index 1639cefe8796d9351a6d086f3e33396c41d63ef2..ae7ccf7c53d38aa20e62737e729749b7f09cdb2f 100644 --- a/src/66/66-enable.c +++ b/src/66/66-enable.c @@ -30,6 +30,7 @@ #include <skalibs/buffer.h> #include <skalibs/direntry.h> #include <skalibs/unix-transactional.h> +#include <skalibs/diuint32.h> #include <66/constants.h> #include <66/utils.h> @@ -48,7 +49,7 @@ unsigned int VERBOSITY = 1 ; stralloc saresolve = STRALLOC_ZERO ; -#define USAGE "66-enable [ -h help ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -f force ] [ -S start ] service(s)" +#define USAGE "66-enable [ -h help ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -f ] [ -S ] service(s)" static inline void info_help (void) { @@ -102,7 +103,7 @@ int main(int argc, char const *const *argv,char const *const *envp) stralloc live = STRALLOC_ZERO ; stralloc livetree = STRALLOC_ZERO ; stralloc sasrc = STRALLOC_ZERO ; - genalloc gasrc = GENALLOC_ZERO ; //type sv_src_t + genalloc gasrc = GENALLOC_ZERO ; //type diuint32 genalloc ganlong = GENALLOC_ZERO ; // type stralist genalloc ganclassic = GENALLOC_ZERO ; // name of classic service, type stralist @@ -119,7 +120,7 @@ int main(int argc, char const *const *argv,char const *const *envp) for (;;) { - int opt = getopt_args(argc,argv, ">hv:l:t:fd:I:S", &l) ; + int opt = getopt_args(argc,argv, ">hv:l:t:fS", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) @@ -168,11 +169,13 @@ int main(int argc, char const *const *argv,char const *const *envp) if(r < 0) strerr_dief3x(111,"livetree: ",livetree.s," must be an absolute path") ; for(;*argv;argv++) - if (!resolve_src(&gasrc,&sasrc,*argv,src)) strerr_dief2x(111,"resolve source of service file: ",*argv) ; + { + unsigned int found = 0 ; + if (!resolve_src(&gasrc,&sasrc,*argv,src,&found)) strerr_diefu2x(111,"resolve source of service file: ",*argv) ; + } - - for (unsigned int i = 0 ; i < genalloc_len(sv_src_t,&gasrc) ; i++) - start_parser(sasrc.s + genalloc_s(sv_src_t,&gasrc)[i].src,sasrc.s + genalloc_s(sv_src_t,&gasrc)[i].name,tree.s,&nbsv) ; + for (unsigned int i = 0 ; i < genalloc_len(diuint32,&gasrc) ; i++) + start_parser(sasrc.s + genalloc_s(diuint32,&gasrc)[i].right,sasrc.s + genalloc_s(diuint32,&gasrc)[i].left,tree.s,&nbsv) ; sv_alltype svblob[nbsv] ; diff --git a/src/66/66-info.c b/src/66/66-info.c index 3727c101079f294cc5babf412bcad8d80e2fe815..29f73ddb1cb1778b639f4a386f023f4fd97722a3 100644 --- a/src/66/66-info.c +++ b/src/66/66-info.c @@ -41,7 +41,8 @@ #include <s6/s6-supervise.h>//s6_svc_ok -#include <stdio.h> +//#include <stdio.h> + unsigned int VERBOSITY = 1 ; static stralloc base = STRALLOC_ZERO ; static stralloc live = STRALLOC_ZERO ; @@ -53,11 +54,11 @@ static uid_t owner ; buffer_putflush(buffer_1,"\n",1) ; -#define USAGE "66-info [ -h help ] [ -T tree ] [ -S service ] sub-options (use -h as sub-options for futher informations)" +#define USAGE "66-info [ -h ] [ -T ] [ -S ] sub-options (use -h as sub-options for futher informations)" -#define TREE_USAGE "66-info -T [ -help ] [ -v verbosity ] [ -r reverse ] [ -d depth ] tree " +#define TREE_USAGE "66-info -T [ -h ] [ -v verbosity ] [ -r ] [ -d depth ] tree " #define exit_tree_usage() strerr_dieusage(100, TREE_USAGE) -#define SV_USAGE "66-info -S [ -help ] [ -v verbosity ] [ -l live ] [ -p n lines ] [ -r reverse ] [ -d depth ] service" +#define SV_USAGE "66-info -S [ -h ] [ -v verbosity ] [ -l live ] [ -p n lines ] [ -r ] [ -d depth ] service" #define exit_sv_usage() strerr_dieusage(100, SV_USAGE) unsigned int REVERSE = 0 ; @@ -240,18 +241,19 @@ int print_status(char const *svname,char const *type,char const *treename, char int graph_display(char const *tree,char const *treename,char const *svname,unsigned int what) { - int r ; + int r, e ; graph_t g = GRAPH_ZERO ; stralloc sagraph = STRALLOC_ZERO ; genalloc tokeep = GENALLOC_ZERO ; + e = 1 ; + size_t treelen = strlen(tree) ; - char dir[treelen + 1 + SS_SVDIRS_LEN + 1] ; + char dir[treelen + SS_SVDIRS_LEN + 1] ; memcpy(dir,tree,treelen) ; - dir[treelen] = '/' ; - memcpy(dir + treelen + 1,SS_SVDIRS,SS_SVDIRS_LEN) ; - dir[treelen + 1 + SS_SVDIRS_LEN] = 0 ; + memcpy(dir + treelen,SS_SVDIRS,SS_SVDIRS_LEN) ; + dir[treelen + SS_SVDIRS_LEN] = 0 ; r = graph_type_src(&tokeep,dir,what) ; if (!r) @@ -260,7 +262,7 @@ int graph_display(char const *tree,char const *treename,char const *svname,unsig goto err ; } if (r < 0) - goto err ; + goto empty ; if (!graph_build(&g,&sagraph,&tokeep,dir)) { @@ -285,14 +287,16 @@ int graph_display(char const *tree,char const *treename,char const *svname,unsig genalloc_free(vertex_graph_t,&g.stack) ; genalloc_free(vertex_graph_t,&g.vertex) ; - return 1 ; + return e ; + empty: + e = -1 ; err: genalloc_deepfree(stralist,&tokeep,stra_free) ; sagraph = stralloc_zero ; genalloc_free(vertex_graph_t,&g.stack) ; genalloc_free(vertex_graph_t,&g.vertex) ; - return 0 ; + return e ; } int tree_args(int argc, char const *const *argv) @@ -315,7 +319,7 @@ int tree_args(int argc, char const *const *argv) switch (opt) { - case 'h' : tree_help(); return 0 ; + case 'h' : tree_help(); return 1 ; case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) exit_tree_usage() ; break ; case 'r' : REVERSE = 1 ; break ; case 'd' : if (!uint0_scan(l.arg, &MAXDEPTH)) exit_tree_usage(); break ; @@ -421,7 +425,7 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) { - case 'h' : sv_help(); return 0 ; + case 'h' : sv_help(); return 1 ; case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) exit_sv_usage() ; break ; case 'l' : if (!stralloc_cats(&live,l.arg)) retstralloc(0,"sv_args") ; if (!stralloc_0(&live)) retstralloc(0,"sv_args") ; diff --git a/src/66/66-init.c b/src/66/66-init.c index e6e8f05547fe00910eb831019b955c2537a7ef37..f1cbceb860f501eb9358f5f4829c2679fe4dc993 100644 --- a/src/66/66-init.c +++ b/src/66/66-init.c @@ -19,25 +19,29 @@ #include <oblibs/error2.h> #include <oblibs/directory.h> #include <oblibs/types.h>//scan_mode +#include <oblibs/stralist.h> #include <skalibs/buffer.h> #include <skalibs/types.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> +#include <skalibs/direntry.h> #include <s6/config.h> #include <s6-rc/config.h> #include <s6/s6-supervise.h> #include <66/utils.h> +#include <66/enum.h> #include <66/constants.h> #include <66/tree.h> #include <66/backup.h> #include <66/db.h> +#include <66/svc.h> //#include <stdio.h> -#define USAGE "66-init [ -h help ] [ -v verbosity ] [ -l live ] [ -c classic ] [ -d database ] [ -B both service ] tree" +#define USAGE "66-init [ -h ] [ -v verbosity ] [ -l live ] [ -c | d | B ] tree" unsigned int VERBOSITY = 1 ; @@ -61,7 +65,7 @@ static inline void info_help (void) int main(int argc, char const *const *argv, char const *const *envp) { - int r, both, classic, db ; + int r, db, classic, earlier ; uid_t owner ; int wstat ; @@ -75,8 +79,13 @@ int main(int argc, char const *const *argv, char const *const *envp) stralloc live = STRALLOC_ZERO ; stralloc scandir = STRALLOC_ZERO ; stralloc livetree = STRALLOC_ZERO ; + stralloc saresolve = STRALLOC_ZERO ; + stralloc type = STRALLOC_ZERO ; + genalloc gasvc = GENALLOC_ZERO ; //stralist type - both = classic = db = 0 ; + svstat_t svstat = SVSTAT_ZERO ; + genalloc gasvstat = GENALLOC_ZERO ; //svstat_t type + classic = db = earlier = 0 ; PROG = "66-init" ; { @@ -96,7 +105,7 @@ int main(int argc, char const *const *argv, char const *const *envp) break ; case 'c' : classic = 1 ; break ; case 'd' : db = 1 ; break ; - case 'B' : both = 1 ; break ; + case 'B' : classic = 1 ; db = 1 ; break ; default : exitusage() ; } } @@ -131,8 +140,12 @@ int main(int argc, char const *const *argv, char const *const *envp) if (r < 0) strerr_dief3x(111,"scandir: ",scandir.s," must be an absolute path") ; r = scan_mode(scandir.s,S_IFDIR) ; + if (r < 0) strerr_dief2x(111,scandir.s," conflicted format") ; if (!r) strerr_dief3x(110,"scandir: ",scandir.s," doesn't exist") ; + r = scandir_ok(scandir.s) ; + if (r != 1) earlier = 1 ; + if (!stralloc_copy(&livetree,&live)) retstralloc(111,"main") ; r = set_livetree(&livetree,owner) ; if (!r) retstralloc(111,"main") ; @@ -146,16 +159,6 @@ int main(int argc, char const *const *argv, char const *const *envp) r = dir_create(livetree.s,0700) ; if (!r) strerr_diefu2sys(111,"create directory: ",livetree.s) ; } - if (db_ok(livetree.s,treename)) - { - strerr_warni2x(treename," already initiated") ; - return 0 ; - } - livetree.len--; - if (!stralloc_cats(&livetree,"/")) retstralloc(111,"main") ; - if (!stralloc_cats(&livetree,treename)) retstralloc(111,"main") ; - if (!stralloc_0(&livetree)) retstralloc(111,"main") ; - tree.len-- ; size_t svdirlen ; @@ -166,22 +169,84 @@ int main(int argc, char const *const *argv, char const *const *envp) memcpy(svdir + svdirlen, SS_SVC ,SS_SVC_LEN) ; svdir[svdirlen + SS_SVC_LEN] = 0 ; - /** svc service work */ - if (classic || both) + /** svc already initiated */ + if (classic) { - VERBO2 strerr_warni5x("copy svc service from ",svdir," to ",scandir.s," ...") ; - if (!hiercopy(svdir,scandir.s)) strerr_diefu4sys(111,"copy: ",svdir," to: ",scandir.s) ; + int i ; + if (!dir_cmp(svdir,scandir.s,"",&gasvc)) strerr_diefu4x(111,"compare ",svdir," to ",scandir.s) ; + if (!earlier) + { + for (i = 0 ; i < genalloc_len(stralist,&gasvc) ; i++) + { + char *name = gaistr(&gasvc,i) ; + size_t namelen = gaistrlen(&gasvc,i) ; + + if (!resolve_pointo(&saresolve,base.s,live.s,tree.s,treename,0,SS_RESOLVE_SRC)) + strerr_diefu1x(111,"set revolve pointer to source") ; + r = resolve_read(&type,saresolve.s,name,"type") ; + if (r < -1) strerr_dief2x(111,"invalid .resolve directory: ",saresolve.s) ; + if (r && type.len && get_enumbyid(type.s,key_enum_el) == CLASSIC) + { + svstat.down = 0 ; + svstat.name = name ; + svstat.namelen = namelen ; + r = resolve_read(&type,saresolve.s,name,"down") ; + if (r > 0) svstat.down = 1 ; + if (!genalloc_append(svstat_t,&gasvstat,&svstat)) strerr_diefu3x(111,"add: ",name," on genalloc") ; + } + } + if (genalloc_len(svstat_t,&gasvstat)) + { + if (!svc_init(scandir.s,svdir,&gasvstat)) strerr_diefu2x(111,"initiate service of tree: ",treename) ; + } + else strerr_warni3x("svc service of tree: ",treename," already initiated") ; + } + else + { + size_t dirlen = strlen(svdir) ; + for (i = 0 ; i < genalloc_len(stralist,&gasvc) ; i++) + { + char *name = gaistr(&gasvc,i) ; + size_t namelen = gaistrlen(&gasvc,i) ; + size_t scanlen = scandir.len - 1 ; + char svscan[scanlen + 1 + namelen + 1] ; + memcpy(svscan,scandir.s,scanlen) ; + svscan[scanlen] = '/' ; + memcpy(svscan + scanlen + 1, name,namelen) ; + svscan[scanlen + 1 + namelen] = 0 ; + char tocopy[dirlen + 1 + namelen + 1] ; + memcpy(tocopy,svdir,dirlen) ; + tocopy[dirlen] = '/' ; + memcpy(tocopy + dirlen + 1, name, namelen) ; + tocopy[dirlen + 1 + namelen] = 0 ; + if (!hiercopy(tocopy,svscan)) strerr_diefu4sys(111,"to copy: ",tocopy," to: ",svscan) ; + } + } } - if (db || both) + genalloc_deepfree(stralist,&gasvc,stra_free) ; + genalloc_free(svstat_t,&gasvstat) ; + stralloc_free(&saresolve) ; + stralloc_free(&type) ; + + /** db already initiated? */ + if (db) + { + if (!earlier) + { + if (db_ok(livetree.s,treename)) + { + strerr_warni3x(" db of tree: ",treename," already initiated") ; + goto end ; + } + }else strerr_dief3x(110,"scandir: ",scandir.s," is not running") ; + }else goto end ; + { + livetree.len--; + if (!stralloc_cats(&livetree,"/")) retstralloc(111,"main") ; + if (!stralloc_cats(&livetree,treename)) retstralloc(111,"main") ; + if (!stralloc_0(&livetree)) retstralloc(111,"main") ; - /** we assume that 66-scandir was launched previously because a db - * need an operationnal scandir, so we control if /run/66/scandir/owner exist, - * if not, exist immediately */ - r = scandir_ok(scandir.s) ; - if (r != 1) strerr_dief3x(111,"scandir: ",scandir.s," is not running") ; - - /** rc services work */ memcpy(svdir + svdirlen,SS_DB,SS_DB_LEN) ; memcpy(svdir + svdirlen + SS_DB_LEN, "/", 1) ; memcpy(svdir + svdirlen + SS_DB_LEN + 1, treename,treenamelen) ; @@ -217,12 +282,13 @@ int main(int argc, char const *const *argv, char const *const *envp) strerr_diefu2x(111,"init db: ",svdir) ; } } - - stralloc_free(&base) ; - stralloc_free(&tree) ; - stralloc_free(&live) ; - stralloc_free(&scandir) ; - stralloc_free(&livetree) ; + + end: + stralloc_free(&base) ; + stralloc_free(&tree) ; + stralloc_free(&live) ; + stralloc_free(&scandir) ; + stralloc_free(&livetree) ; return 0 ; } diff --git a/src/66/66-scandir.c b/src/66/66-scandir.c index 0bbd82c2d395e60d7f6f5fb35453d88d6bb7c7ee..e72721affeba891d315983e193a2214162f9f1ad 100644 --- a/src/66/66-scandir.c +++ b/src/66/66-scandir.c @@ -63,7 +63,7 @@ static char const *stage2tini = "/etc/66/stage2" ; static char const *stage3 = "/etc/66/stage3 $@" ; -#define USAGE "66-scandir [ -h help ] [ -v verbosity ] [ -b boot ] [ -l live ] [ -t rescan ] [ -2 stage2.tini ] [ -3 stage3 ] [ -e environment ] [ -c create ] [ -r remove ] [ -u up ] [ -s signal ] owner" +#define USAGE "66-scandir [ -h ] [ -v verbosity ] [ -b ] [ -l live ] [ -t rescan ] [ -2 stage2.tini ] [ -3 stage3 ] [ -e environment ] [ -c | u | r ] [ -s signal ] owner" unsigned int VERBOSITY = 1 ; static unsigned int BOOT = 0 ; diff --git a/src/66/66-start.c b/src/66/66-start.c index b2babc6f4100f67cde3b4afdd558a5cba8e6440e..5cbf8d223ebda2fd337b9561f6486ea3df0a3632 100644 --- a/src/66/66-start.c +++ b/src/66/66-start.c @@ -52,11 +52,13 @@ //#include <stdio.h> unsigned int VERBOSITY = 1 ; -unsigned int RELOAD = 0 ; -static tain_t DEADLINE ; -stralloc saresolve = STRALLOC_ZERO ; +static unsigned int RELOAD = 0 ; +static unsigned int DEADLINE = 0 ; +static stralloc saresolve = STRALLOC_ZERO ; +static char *SIG = "-U" ; +static genalloc DOWNFILE = GENALLOC_ZERO ; //stralist -#define USAGE "66-start [ -h help ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -r reload ] service(s)" +#define USAGE "66-start [ -h ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -r | R ] service(s)" static inline void info_help (void) { @@ -70,6 +72,7 @@ static inline void info_help (void) " -t: tree to use\n" " -T: timeout\n" " -r: reload the service(s)\n" +" -R: reload service(s) file(s) and the service(s) itself\n" ; if (buffer_putsflush(buffer_1, help) < 0) @@ -119,8 +122,9 @@ int svc_shutnremove(char const *base,char const *scandir,char const *live,char c unsigned int m = 0 ; char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; + char tt[UINT32_FMT] ; - tt[uint32_fmt(tt,tain_to_millisecs(&DEADLINE))] = 0 ; + tt[uint32_fmt(tt,DEADLINE)] = 0 ; newargv[m++] = SS_BINPREFIX "66-svctl" ; newargv[m++] = "-v" ; @@ -159,10 +163,10 @@ int svc_shutnremove(char const *base,char const *scandir,char const *live,char c memcpy(svscan + scanlen + 1,name, namelen) ; svscan[scanlen + 1 + namelen] = 0 ; - VERBO3 strerr_warnt2x("remove: ", svscan) ; + VERBO3 strerr_warnt2x("delete: ", svscan) ; if (rm_rf(svscan) < 0) { - VERBO3 strerr_warnwu2sys("remove: ",svscan) ; + VERBO3 strerr_warnwu2sys("delete: ",svscan) ; return 0 ; } } @@ -205,8 +209,9 @@ int svc_start(char const *base,char const *scandir,char const *live,char const * unsigned int m = 0 ; char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; + char tt[UINT32_FMT] ; - tt[uint32_fmt(tt,tain_to_millisecs(&DEADLINE))] = 0 ; + tt[uint32_fmt(tt,DEADLINE)] = 0 ; newargv[m++] = SS_BINPREFIX "66-svctl" ; newargv[m++] = "-v" ; @@ -217,7 +222,7 @@ int svc_start(char const *base,char const *scandir,char const *live,char const * newargv[m++] = live ; newargv[m++] = "-t" ; newargv[m++] = treename ; - newargv[m++] = "-U" ; + newargv[m++] = SIG ; for (unsigned int i = 0 ; i < genalloc_len(stralist,&tot) ; i++) newargv[m++] = gaistr(&tot,i) ; @@ -243,112 +248,18 @@ int svc_start(char const *base,char const *scandir,char const *live,char const * for (unsigned int i = 0; i < genalloc_len(svstat_t,ga) ; i++) { - VERBO3 strerr_warnt2x("remove reload resolve file for: ",genalloc_s(svstat_t,ga)[i].name) ; - if (!resolve_remove(saresolve.s,genalloc_s(svstat_t,ga)[i].name,"reload")) + if (genalloc_s(svstat_t,ga)[i].reload) { - VERBO3 strerr_warnwu3sys("remove resolve file",saresolve.s,"/reload") ; - return 0 ; + VERBO3 strerr_warnt2x("delete reload resolve file for: ",genalloc_s(svstat_t,ga)[i].name) ; + if (!resolve_remove(saresolve.s,genalloc_s(svstat_t,ga)[i].name,"reload")) + { + VERBO3 strerr_warnwu3sys("delete resolve file",saresolve.s,"/reload") ; + return 0 ; + } } } - - return 1 ; -} -int svc_init(char const *scandir,char const *src, genalloc *ga) -{ - - int r ; - gid_t gid = getgid() ; - uint16_t id ; - - ftrigr_t fifo = FTRIGR_ZERO ; - - tain_now_g() ; - tain_add_g(&DEADLINE, &DEADLINE) ; - - VERBO3 strerr_warnt1x("iniate fifo: fifo") ; - if (!ftrigr_startf(&fifo, &DEADLINE, &STAMP)) - return 0 ; - - for (unsigned int i=0 ; i <genalloc_len(svstat_t,ga); i++) - { - char const *name = genalloc_s(svstat_t,ga)[i].name ; - size_t namelen = genalloc_s(svstat_t,ga)[i].namelen ; - - size_t srclen = strlen(src) ; - char svsrc[srclen + 1 + namelen + 1] ; - memcpy(svsrc,src,srclen) ; - svsrc[srclen] = '/' ; - memcpy(svsrc + srclen + 1, name,namelen) ; - svsrc[srclen + 1 + namelen] = 0 ; - - size_t svscanlen = strlen(scandir) ; - char svscan[svscanlen + 1 + namelen + 6 + 1] ; - memcpy(svscan,scandir,svscanlen) ; - svscan[svscanlen] = '/' ; - memcpy(svscan + svscanlen + 1, name,namelen) ; - svscanlen = svscanlen + 1 + namelen ; - svscan[svscanlen] = 0 ; - - VERBO3 strerr_warnt2x("init service: ", svscan) ; - - VERBO3 strerr_warnt4x("copy: ",svsrc, " to ", svscan) ; - if (!hiercopy(svsrc,svscan )) - { - VERBO3 strerr_warnwu4sys("copy: ",svsrc," to: ",svscan) ; - goto err ; - } - memcpy(svscan + svscanlen, "/down", 5) ; - svscan[svscanlen + 5] = 0 ; - - VERBO3 strerr_warnt2x("create file: ",svscan) ; - if (!touch(svscan)) - { - VERBO3 strerr_warnwu2sys("create file: ",svscan) ; - goto err ; - } - memcpy(svscan + svscanlen, "/event", 6) ; - svscan[svscanlen + 6] = 0 ; - VERBO3 strerr_warnt2x("create fifo: ",svscan) ; - if (!ftrigw_fifodir_make(svscan, gid, 0)) - { - VERBO3 strerr_warnwu2sys("create fifo: ",svscan) ; - goto err ; - } - VERBO3 strerr_warnt2x("subcribe to fifo: ",svscan) ; - /** unsubscribe automatically, options is 0 */ - id = ftrigr_subscribe_g(&fifo, svscan, "s", 0, &DEADLINE) ; - if (!id) - { - VERBO3 strerr_warnwu2x("subcribe to fifo: ",svscan) ; - goto err ; - } - } - VERBO3 strerr_warnt2x("reload scandir: ",scandir) ; - r = s6_svc_writectl(scandir, S6_SVSCAN_CTLDIR, "an", 2) ; - if (r < 0) - { - VERBO3 strerr_warnw3sys("something is wrong with the ",scandir, "/" S6_SVSCAN_CTLDIR " directory. errno reported") ; - goto err ; - } - if (!r) - { - VERBO3 strerr_warnw3x("scandir: ",scandir, " is not running") ; - goto err ; - } - - VERBO3 strerr_warnt1x("waiting for events on fifo") ; - if (ftrigr_wait_and_g(&fifo, &id, 1, &DEADLINE) < 0) - goto err ; - - ftrigr_end(&fifo) ; - return 1 ; - - err: - ftrigr_end(&fifo) ; - return 0 ; - } int svc_sanitize(char const *base,char const *scandir,char const *live,char const *tree,char const *treename, genalloc *ga, char const *const *envp) @@ -456,7 +367,7 @@ int rc_init(char const *scandir, char const *live, char const *treename, char co return 1 ; } -int rc_sanitize(char const *base, char const *scandir, char const *live, char const *livetree, char const *tree, char const *treename,genalloc *ga, char const *const *envp,unsigned int trc) +int rc_sanitize(char const *base, char const *scandir, char const *live, char const *livetree, char const *tree, char const *treename,genalloc *ga, char const *const *envp) { pid_t pid ; int wstat ; @@ -488,6 +399,7 @@ int rc_sanitize(char const *base, char const *scandir, char const *live, char co } if (genalloc_len(stralist,&toreload)) { + if (!db_switch_to(base,livetree,tree,treename,envp,SS_SWBACK)) { VERBO3 strerr_warnwu3x("switch ",treename," to backup") ; @@ -508,22 +420,15 @@ int rc_sanitize(char const *base, char const *scandir, char const *live, char co VERBO3 strerr_warnwu3x("switch ",treename," to backup") ; return 0 ; } + char const *newargv[11 + genalloc_len(stralist,&toreload)] ; unsigned int m = 0 ; char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; - int globalt ; - tain_t globaltto ; - tain_sub(&globaltto,&DEADLINE, &STAMP) ; - globalt = tain_to_millisecs(&globaltto) ; - if (!globalt) globalt = 1 ; - if (globalt > 0 && (!trc || (unsigned int) globalt < trc)) - trc = (uint32_t)globalt ; - char tt[UINT32_FMT] ; - tt[uint32_fmt(tt,trc)] = 0 ; - + tt[uint32_fmt(tt,DEADLINE)] = 0 ; + newargv[m++] = SS_BINPREFIX "66-dbctl" ; newargv[m++] = "-v" ; newargv[m++] = fmt ; @@ -537,9 +442,9 @@ int rc_sanitize(char const *base, char const *scandir, char const *live, char co for (unsigned int i = 0; i < genalloc_len(stralist,&toreload) ; i++) newargv[m++] = gaistr(&toreload,i) ; - + newargv[m++] = 0 ; - + pid = child_spawn0(newargv[0],newargv,envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) { @@ -553,14 +458,15 @@ int rc_sanitize(char const *base, char const *scandir, char const *live, char co goto err ; } } - + return 1 ; err: genalloc_deepfree(stralist,&toreload,stra_free) ; return 0 ; } -int rc_start(char const *base,char const *live, char const *livetree,char const *tree, char const *treename,genalloc *ga,char const *const *envp,unsigned int trc) + +int rc_start(char const *base,char const *live, char const *livetree,char const *tree, char const *treename,genalloc *ga,char const *const *envp) { int wstat ; @@ -573,18 +479,10 @@ int rc_start(char const *base,char const *live, char const *livetree,char const unsigned int m = 0 ; char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; - - int globalt ; - tain_t globaltto ; - tain_sub(&globaltto,&DEADLINE, &STAMP) ; - globalt = tain_to_millisecs(&globaltto) ; - if (!globalt) globalt = 1 ; - if (globalt > 0 && (!trc || (unsigned int) globalt < trc)) - trc = (uint32_t)globalt ; - + char tt[UINT32_FMT] ; - tt[uint32_fmt(tt,trc)] = 0 ; - + tt[uint32_fmt(tt,DEADLINE)] = 0 ; + newargv[m++] = SS_BINPREFIX "66-dbctl" ; newargv[m++] = "-v" ; newargv[m++] = fmt ; @@ -594,27 +492,22 @@ int rc_start(char const *base,char const *live, char const *livetree,char const newargv[m++] = live ; newargv[m++] = "-t" ; newargv[m++] = treename ; - newargv[m++] = "-u" ; - + if (RELOAD == 1) + newargv[m++] = "-r" ; + else + newargv[m++] = "-u" ; + for (unsigned int i = 0; i < genalloc_len(svstat_t,ga) ; i++) newargv[m++] = genalloc_s(svstat_t,ga)[i].name ; ; newargv[m++] = 0 ; - + + tain_t deadline ; + tain_from_millisecs(&deadline, DEADLINE) ; + tain_now_g() ; - tain_add_g(&DEADLINE,&DEADLINE) ; + tain_add_g(&deadline, &deadline) ; - int spfd = selfpipe_init() ; - if (spfd < 0) VERBO3 strerr_diefu1sys(111,"init selfpipe") ; - { - sigset_t set ; - sigemptyset(&set) ; - sigaddset(&set, SIGCHLD) ; - sigaddset(&set, SIGINT) ; - sigaddset(&set, SIGTERM) ; - if (selfpipe_trapset(&set) < 0) - VERBO3 strerr_diefu1sys(111,"trap signals") ; - } pid = child_spawn0(newargv[0],newargv,envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) @@ -637,10 +530,10 @@ int rc_start(char const *base,char const *live, char const *livetree,char const for (unsigned int i = 0; i < genalloc_len(svstat_t,ga) ; i++) { - VERBO3 strerr_warnt2x("remove reload resolve file for: ",genalloc_s(svstat_t,ga)[i].name) ; + VERBO3 strerr_warnt2x("delete reload resolve file for: ",genalloc_s(svstat_t,ga)[i].name) ; if (!resolve_remove(saresolve.s,genalloc_s(svstat_t,ga)[i].name,"reload")) { - VERBO3 strerr_warnwu3sys("remove resolve file",saresolve.s,"/reload") ; + VERBO3 strerr_warnwu3sys("delete resolve file",saresolve.s,"/reload") ; return 0 ; } } @@ -648,14 +541,12 @@ int rc_start(char const *base,char const *live, char const *livetree,char const return 1 ; err: - selfpipe_finish() ; return 0 ; } int main(int argc, char const *const *argv,char const *const *envp) { int r,rb ; - unsigned int trc ; uid_t owner ; @@ -671,15 +562,13 @@ int main(int argc, char const *const *argv,char const *const *envp) genalloc nclassic = GENALLOC_ZERO ; //svstat_t type genalloc nrc = GENALLOC_ZERO ; //svstat_t type - unsigned int tmain = trc = 0 ; - PROG = "66-start" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - int opt = getopt_args(argc,argv, ">hv:l:t:rT:", &l) ; + int opt = getopt_args(argc,argv, ">hv:l:t:rRT:", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; @@ -687,8 +576,9 @@ int main(int argc, char const *const *argv,char const *const *envp) { case 'h' : info_help(); return 0 ; case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) exitusage() ; break ; - case 'T' : if (!uint0_scan(l.arg, &tmain)) exitusage() ; break ; - case 'r' : RELOAD = 1 ; break ; + case 'T' : if (!uint0_scan(l.arg, &DEADLINE)) exitusage() ; break ; + case 'r' : if (RELOAD) exitusage() ; RELOAD = 1 ; SIG = "-R" ; break ; + case 'R' : if (RELOAD) exitusage() ; RELOAD = 2 ; SIG = "-R" ; break ; case 'l' : if(!stralloc_cats(&live,l.arg)) retstralloc(111,"main") ; if(!stralloc_0(&live)) retstralloc(111,"main") ; break ; @@ -707,12 +597,6 @@ int main(int argc, char const *const *argv,char const *const *envp) if (!set_ownersysdir(&base,owner)) strerr_diefu1sys(111, "set owner directory") ; - if (tmain){ - tain_from_millisecs(&DEADLINE, tmain) ; - trc = tmain ; - } - else DEADLINE = tain_infinite_relative ; - r = tree_sethome(&tree,base.s) ; if (r < 0) strerr_diefu1x(110,"find the current tree. You must use -t options") ; if (!r) strerr_diefu2sys(111,"find tree: ", tree.s) ; @@ -754,6 +638,7 @@ int main(int argc, char const *const *argv,char const *const *envp) svsrc.type = 0 ; svsrc.name = 0 ; svsrc.namelen = 0 ; + svsrc.down = 0 ; svsrc.reload = 0 ; svsrc.init = 0 ; svok.len = svoklen ; @@ -779,6 +664,9 @@ int main(int argc, char const *const *argv,char const *const *envp) r = resolve_read(&type,saresolve.s,*argv,"reload") ; if (r < -1) strerr_diefu2sys(111,"invalid .resolve directory: ",saresolve.s) ; if (r > 0) svsrc.reload = 1 ; + r = resolve_read(&type,saresolve.s,*argv,"down") ; + if (r < -1) strerr_diefu2sys(111,"invalid .resolve directory: ",saresolve.s) ; + if (r > 0) svsrc.down = 1 ; r = resolve_read(&type,saresolve.s,*argv,"remove") ; if (r > 0) strerr_dief3x(111,"service: ",*argv," was disabled, you can only stop it") ; } @@ -791,7 +679,7 @@ int main(int argc, char const *const *argv,char const *const *envp) if (!r) svsrc.init = 1 ; } - if (RELOAD) svsrc.reload = 1 ; + if (RELOAD > 1) svsrc.reload = 1 ; if (svsrc.init) svsrc.reload = 0 ; if (svsrc.type == CLASSIC) @@ -825,10 +713,10 @@ int main(int argc, char const *const *argv,char const *const *envp) if (genalloc_len(svstat_t,&nrc)) { VERBO2 strerr_warni1x("sanitize rc services ...") ; - if (!rc_sanitize(base.s,scandir.s,live.s,livetree.s,tree.s,treename,&nrc,envp,trc)) + if (!rc_sanitize(base.s,scandir.s,live.s,livetree.s,tree.s,treename,&nrc,envp)) strerr_diefu1x(111,"sanitize s6-rc services") ; VERBO2 strerr_warni1x("start rc services ...") ; - if (!rc_start(base.s,live.s,livetree.s,tree.s,treename,&nrc,envp,trc)) + if (!rc_start(base.s,live.s,livetree.s,tree.s,treename,&nrc,envp)) strerr_diefu1x(111,"update s6-rc services") ; VERBO2 strerr_warni3x("switch rc services of: ",treename," to source") ; if (!db_switch_to(base.s,livetree.s,tree.s,treename,envp,SS_SWSRC)) @@ -843,6 +731,7 @@ int main(int argc, char const *const *argv,char const *const *envp) stralloc_free(&saresolve) ; genalloc_free(svstat_t,&nclassic) ; genalloc_free(svstat_t,&nrc) ; + genalloc_deepfree(stralist,&DOWNFILE,stra_free) ; free(treename) ; return 0 ; diff --git a/src/66/66-stop.c b/src/66/66-stop.c index 86ee583693b729a2f98135a2f0dc41007859be63..c0d2840b8ad9a54f391b90f8fb561cfae0fc7e03 100644 --- a/src/66/66-stop.c +++ b/src/66/66-stop.c @@ -29,6 +29,8 @@ #include <skalibs/genalloc.h> #include <skalibs/djbunix.h> #include <skalibs/unix-transactional.h> +#include <skalibs/selfpipe.h> +#include <skalibs/sig.h> #include <s6/s6-supervise.h>//s6_svc_ok #include <s6/config.h> @@ -46,12 +48,14 @@ //#include <stdio.h> unsigned int VERBOSITY = 1 ; -static tain_t DEADLINE ; +static unsigned int DEADLINE = 0 ; unsigned int UNSUP = 0 ; +static char *SIG = "-D" ; stralloc saresolve = STRALLOC_ZERO ; genalloc gatoremove = GENALLOC_ZERO ;//stralist genalloc gaunsup = GENALLOC_ZERO ; //stralist -#define USAGE "66-stop [ -h help ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -u unsupervise ] service(s)" + +#define USAGE "66-stop [ -h ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -u ] [ -X ] [ -K ] service(s)" static inline void info_help (void) { @@ -64,7 +68,10 @@ static inline void info_help (void) " -l: live directory\n" " -T: timeout\n" " -t: tree to use\n" -" -u: unsupervise service\n" +" -u: unsupervise service(s)\n" +" -X: bring down the service(s) and kill his supervisor\n" +" -K: kill the service(s) and keep it down\n" + ; if (buffer_putsflush(buffer_1, help) < 0) @@ -90,7 +97,7 @@ int svc_release(char const *base, char const *scandir, char const *live, char co VERBO3 strerr_warnt2x("unsupervise: ",rm) ; if (rm_rf(rm) < 0) { - VERBO3 strerr_warnwu2sys("remove directory: ",rm) ; + VERBO3 strerr_warnwu2sys("delete directory: ",rm) ; return 0 ; } } @@ -108,7 +115,7 @@ int svc_release(char const *base, char const *scandir, char const *live, char co if (!resolve_remove_service(saresolve.s,svname)) { - VERBO3 strerr_warnwu4sys("remove resolve service file: ",saresolve.s,"/.resolve/",svname) ; + VERBO3 strerr_warnwu4sys("delete resolve service file: ",saresolve.s,"/.resolve/",svname) ; return 0 ; } } @@ -140,7 +147,7 @@ int svc_down(char const *base,char const *scandir,char const *live,char const *t { if (!stra_add(&gatoremove,svname)) { - VERBO3 strerr_warnwu3x("add: ",svname," as service to remove") ; + VERBO3 strerr_warnwu3x("add: ",svname," as service to delete") ; return 0 ; } } @@ -170,7 +177,7 @@ int svc_down(char const *base,char const *scandir,char const *live,char const *t { if (!stra_add(&gatoremove,saresolve.s)) { - VERBO3 strerr_warnwu3x("add logger of: ",saresolve.s," as service to remove") ; + VERBO3 strerr_warnwu3x("add logger of: ",saresolve.s," as service to delete") ; return 0 ; } } @@ -188,8 +195,9 @@ int svc_down(char const *base,char const *scandir,char const *live,char const *t unsigned int m = 0 ; char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; + char tt[UINT32_FMT] ; - tt[uint32_fmt(tt,tain_to_millisecs(&DEADLINE))] = 0 ; + tt[uint32_fmt(tt,DEADLINE)] = 0 ; newargv[m++] = SS_BINPREFIX "66-svctl" ; newargv[m++] = "-v" ; @@ -200,7 +208,7 @@ int svc_down(char const *base,char const *scandir,char const *live,char const *t newargv[m++] = live ; newargv[m++] = "-t" ; newargv[m++] = treename ; - newargv[m++] = "-D" ; + newargv[m++] = SIG ; for (unsigned int i = 0 ; i < genalloc_len(stralist,&tot) ; i++) newargv[m++] = gaistr(&tot,i) ; @@ -226,10 +234,10 @@ int svc_down(char const *base,char const *scandir,char const *live,char const *t } for (unsigned int i = 0; i < genalloc_len(svstat_t,ga) ; i++) { - VERBO3 strerr_warnt2x("remove remove resolve file for: ",genalloc_s(svstat_t,ga)[i].name) ; + VERBO3 strerr_warnt2x("delete remove resolve file for: ",genalloc_s(svstat_t,ga)[i].name) ; if (!resolve_remove(saresolve.s,genalloc_s(svstat_t,ga)[i].name,"remove")) { - VERBO3 strerr_warnwu3sys("remove resolve file",saresolve.s,"/remove") ; + VERBO3 strerr_warnwu3sys("delete resolve file",saresolve.s,"/remove") ; return 0 ; } } @@ -254,7 +262,7 @@ int rc_release(char const *base, char const *scandir, char const *live,char cons if (!resolve_remove_service(saresolve.s,svname)) { - VERBO3 strerr_warnwu4sys("remove resolve service file: ",saresolve.s,"/.resolve/",svname) ; + VERBO3 strerr_warnwu4sys("delete resolve service file: ",saresolve.s,"/.resolve/",svname) ; return 0 ; } } @@ -263,7 +271,7 @@ int rc_release(char const *base, char const *scandir, char const *live,char cons return 1 ; } -int rc_down(char const *base, char const *scandir, char const *live, char const *livetree,char const *tree, char const *treename,genalloc *ga,char const *const *envp,unsigned int trc) +int rc_down(char const *base, char const *scandir, char const *live, char const *livetree,char const *tree, char const *treename,genalloc *ga,char const *const *envp) { int wstat ; pid_t pid ; @@ -290,7 +298,7 @@ int rc_down(char const *base, char const *scandir, char const *live, char const { if (!stra_add(&gatoremove,svname)) { - VERBO3 strerr_warnwu3x("add: ",svname," as service to remove") ; + VERBO3 strerr_warnwu3x("add: ",svname," as service to delete") ; return 0 ; } } @@ -311,7 +319,7 @@ int rc_down(char const *base, char const *scandir, char const *live, char const { if (!stra_add(&gatoremove,saresolve.s)) { - VERBO3 strerr_warnwu3x("add logger of: ",saresolve.s," as service to remove") ; + VERBO3 strerr_warnwu3x("add logger of: ",saresolve.s," as service to delete") ; return 0 ; } } @@ -333,18 +341,10 @@ int rc_down(char const *base, char const *scandir, char const *live, char const unsigned int m = 0 ; char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; - - int globalt ; - tain_t globaltto ; - tain_sub(&globaltto,&DEADLINE, &STAMP) ; - globalt = tain_to_millisecs(&globaltto) ; - if (!globalt) globalt = 1 ; - if (globalt > 0 && (!trc || (unsigned int) globalt < trc)) - trc = (uint32_t)globalt ; - + char tt[UINT32_FMT] ; - tt[uint32_fmt(tt,trc)] = 0 ; - + tt[uint32_fmt(tt,DEADLINE)] = 0 ; + newargv[m++] = SS_BINPREFIX "66-dbctl" ; newargv[m++] = "-v" ; newargv[m++] = fmt ; @@ -380,10 +380,10 @@ int rc_down(char const *base, char const *scandir, char const *live, char const } for (unsigned int i = 0; i < genalloc_len(svstat_t,ga) ; i++) { - VERBO3 strerr_warnt2x("remove remove resolve file for: ",genalloc_s(svstat_t,ga)[i].name) ; + VERBO3 strerr_warnt2x("delete remove resolve file for: ",genalloc_s(svstat_t,ga)[i].name) ; if (!resolve_remove(saresolve.s,genalloc_s(svstat_t,ga)[i].name,"remove")) { - VERBO3 strerr_warnwu3sys("remove resolve file",saresolve.s,"/remove") ; + VERBO3 strerr_warnwu3sys("delete resolve file",saresolve.s,"/remove") ; return 0 ; } } @@ -396,9 +396,8 @@ int rc_down(char const *base, char const *scandir, char const *live, char const int main(int argc, char const *const *argv,char const *const *envp) { - int r, rb ; - unsigned int trc ; - + int r, rb, sigopt ; + uid_t owner ; char *treename = 0 ; @@ -413,7 +412,7 @@ int main(int argc, char const *const *argv,char const *const *envp) genalloc nclassic = GENALLOC_ZERO ; genalloc nrc = GENALLOC_ZERO ; - unsigned int tmain = trc = 0 ; + sigopt = 0 ; PROG = "66-stop" ; { @@ -421,7 +420,7 @@ int main(int argc, char const *const *argv,char const *const *envp) for (;;) { - int opt = getopt_args(argc,argv, ">hv:l:t:T:u", &l) ; + int opt = getopt_args(argc,argv, ">hv:l:t:T:uXK", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; @@ -432,11 +431,13 @@ int main(int argc, char const *const *argv,char const *const *envp) case 'l' : if(!stralloc_cats(&live,l.arg)) retstralloc(111,"main") ; if(!stralloc_0(&live)) retstralloc(111,"main") ; break ; - case 'T' : if (!uint0_scan(l.arg, &tmain)) exitusage() ; break ; + case 'T' : if (!uint0_scan(l.arg, &DEADLINE)) exitusage() ; break ; case 't' : if(!stralloc_cats(&tree,l.arg)) retstralloc(111,"main") ; if(!stralloc_0(&tree)) retstralloc(111,"main") ; break ; case 'u' : UNSUP = 1 ; break ; + case 'X' : if (sigopt) exitusage() ; sigopt = 1 ; SIG = "-X" ; break ; + case 'K' : if (sigopt) exitusage() ; sigopt = 1 ; SIG = "-K" ; break ; default : exitusage() ; } } @@ -448,13 +449,7 @@ int main(int argc, char const *const *argv,char const *const *envp) owner = MYUID ; if (!set_ownersysdir(&base,owner)) strerr_diefu1sys(111, "set owner directory") ; - - if (tmain){ - tain_from_millisecs(&DEADLINE, tmain) ; - trc = tmain ; - } - else DEADLINE = tain_infinite_relative ; - + r = tree_sethome(&tree,base.s) ; if (r < 0) strerr_diefu1x(110,"find the current tree. You must use -t options") ; if (!r) strerr_diefu2sys(111,"find tree: ", tree.s) ; @@ -520,10 +515,10 @@ int main(int argc, char const *const *argv,char const *const *envp) r = resolve_read(&type,saresolve.s,*argv,"remove") ; if (r < -1) strerr_diefu2sys(111,"invalid .resolve directory: ",saresolve.s) ; if (r > 0) svsrc.remove = 1 ; - if (!resolve_pointo(&saresolve,base.s,live.s,tree.s,treename,0,SS_RESOLVE_BACK)) + /* if (!resolve_pointo(&saresolve,base.s,live.s,tree.s,treename,0,SS_RESOLVE_BACK)) strerr_diefu1x(111,"set revolve pointer to backup") ; r = resolve_read(&type,saresolve.s,*argv,"type") ; - if (r <= 0 && !UNSUP) strerr_dief3x(111,"service: ",*argv," is not running, you can only start it") ; + if (r <= 0 && !UNSUP) strerr_dief3x(111,"service: ",*argv," is not running, you can only start it") ;*/ } if (svsrc.type == CLASSIC) { @@ -531,7 +526,8 @@ int main(int argc, char const *const *argv,char const *const *envp) if (!stralloc_0(&svok)) retstralloc(111,"main") ; r = s6_svc_ok(svok.s) ; if (r < 0) strerr_diefu2sys(111,"check ", svok.s) ; - if (!r) svsrc.remove = 1 ; + //if (!r) svsrc.remove = 1 ; + if (!r) strerr_dief3x(111,"service: ",*argv," is not running, you can only start it") ; } if (UNSUP) svsrc.unsupervise = 1 ; @@ -549,7 +545,22 @@ int main(int argc, char const *const *argv,char const *const *envp) stralloc_free(&type) ; stralloc_free(&svok) ; } - + + /** rc work */ + if (genalloc_len(svstat_t,&nrc)) + { + VERBO2 strerr_warni1x("stop rc services ...") ; + if (!rc_down(base.s, scandir.s, live.s,livetree.s,tree.s,treename,&nrc,envp)) + strerr_diefu1x(111,"update rc services") ; + VERBO2 strerr_warni1x("release rc services ...") ; + if (!rc_release(base.s,scandir.s, live.s,tree.s,treename)) + strerr_diefu1x(111,"release rc services") ; + VERBO2 strerr_warni3x("switch rc services of: ",treename," to source") ; + if (!db_switch_to(base.s,livetree.s,tree.s,treename,envp,SS_SWSRC)) + strerr_diefu5x(111,"switch",livetree.s,"/",treename," to source") ; + } + + /** svc work */ if (genalloc_len(svstat_t,&nclassic)) { VERBO2 strerr_warni1x("stop svc services ...") ; @@ -563,18 +574,6 @@ int main(int argc, char const *const *argv,char const *const *envp) strerr_diefu3x(111,"switch svc service of: ",treename," to source") ; } - if (genalloc_len(svstat_t,&nrc)) - { - VERBO2 strerr_warni1x("stop rc services ...") ; - if (!rc_down(base.s, scandir.s, live.s,livetree.s,tree.s,treename,&nrc,envp,trc)) - strerr_diefu1x(111,"update rc services") ; - VERBO2 strerr_warni1x("release rc services ...") ; - if (!rc_release(base.s,scandir.s, live.s,tree.s,treename)) - strerr_diefu1x(111,"release rc services") ; - VERBO2 strerr_warni3x("switch rc services of: ",treename," to source") ; - if (!db_switch_to(base.s,livetree.s,tree.s,treename,envp,SS_SWSRC)) - strerr_diefu5x(111,"switch",livetree.s,"/",treename," to source") ; - } if (UNSUP || genalloc_len(stralist,&gatoremove)) { @@ -591,7 +590,7 @@ int main(int argc, char const *const *argv,char const *const *envp) genalloc_free(svstat_t,&nrc) ; genalloc_free(svstat_t,&nclassic) ; free(treename) ; - + return 0 ; } diff --git a/src/66/66-svctl.c b/src/66/66-svctl.c index 77c0196f684c9114a3a45d9abb1cc4e9f1daccfa..6f54bbb9f9590a2f2dca1b4234229364c6f116e2 100644 --- a/src/66/66-svctl.c +++ b/src/66/66-svctl.c @@ -11,7 +11,8 @@ * This file may not be copied, modified, propagated, or distributed * except according to the terms contained in the LICENSE file./ */ - +#include <signal.h> +#include <stdio.h> #include <string.h> #include <stdlib.h> @@ -32,72 +33,26 @@ #include <skalibs/sig.h> #include <s6/s6-supervise.h>//s6_svstatus_t -#include <s6/ftrigw.h> #include <s6/ftrigr.h> +#include <66/svc.h> #include <66/constants.h> #include <66/utils.h> #include <66/tree.h> +//#include <stdio.h> unsigned int VERBOSITY = 1 ; stralloc svkeep = STRALLOC_ZERO ; genalloc gakeep = GENALLOC_ZERO ; //type svc_sig_s stralloc saresolve = STRALLOC_ZERO ; -typedef struct svc_sig_s svc_sig, *svc_sig_t_ref ; -struct svc_sig_s -{ - unsigned int scan ; //pos in sv - size_t scanlen ; - unsigned int name ; //pos in sv - size_t namelen ; - unsigned int src ; //pos in sv - size_t srclen ; - unsigned int notify ; - unsigned int ndeath; - tain_t deadline ; -} ; - -#define SVC_SIG_ZERO \ -{ \ - .scan = 0 , \ - .name = 0 , \ - .namelen = 0 , \ - .src = 0 , \ - .srclen = 0, \ - .notify = 0, \ - .ndeath = 3, \ - .deadline = TAIN_ZERO \ -} - -unsigned int SV_DEADLINE = 1000 ; -typedef enum state_e state_t, *state_t_ref ; -enum state_e -{ - UP = 0, // u - RUP , // U - really up - DOWN , // d - RDOWN ,// D - really down - SUP ,//supervise - O , //0 - X //x -} ; -typedef enum actions_e actions_t, *actions_t_ref ; -enum actions_e -{ - GOTIT = 0 , - WAIT , - DEAD , - DONE , - PERM , - OUT , - UKNOW -} ; +unsigned int SV_DEADLINE = 3000 ; +unsigned int DEATHSV = 10 ; int SIGNAL = -1 ; -#define USAGE "66-svctl [ -h help ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -S service timeout ] [ -n death ] [ -u|U up ] [ -d|D down ] service(s)" +#define USAGE "66-svctl [ -h ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -n death ] [ -u | U | d | D | r | R | K | X ] service(s)" static inline void info_help (void) { @@ -109,13 +64,16 @@ static inline void info_help (void) " -v: increase/decrease verbosity\n" " -l: live directory\n" " -t: tree to use\n" -" -T: general timeout\n" -" -S: service timeout\n" +" -T: service timeout\n" " -n: number of death\n" -" -u: bring up service\n" +" -u: bring up the service(s)\n" " -U: really up\n" -" -d: bring down service\n" +" -d: bring down the service(s)\n" " -D: really down\n" +" -r: reload\n" +" -R: reload and really up\n" +" -X: bring down the service(s) and the kill his supervisor\n" +" -K: kill the service(s) and keep it down\n" ; if (buffer_putsflush(buffer_1, help) < 0) @@ -146,8 +104,7 @@ static int read_uint (char const *file, unsigned int *fd) return 1 ; } -/** @Return -1 on error - * @Return 0 on fail +/** @Return 0 on fail * @Return 1 on success */ int handle_signal_svc(svc_sig *sv_signal) { @@ -160,40 +117,55 @@ int handle_signal_svc(svc_sig *sv_signal) } int exitcode, exitstatus ; - for (;;) - { - int sig = selfpipe_read() ; - switch (sig) - { - case -1: VERBO3 strerr_warnwu1sys("selfpipe_read()") ; - return -1 ; - case 0: - exitcode = WIFEXITED(status.wstat) ; - exitstatus = WEXITSTATUS(status.wstat) ; - - if (exitcode && exitstatus <= 1) - return 1 ; - else - return 0 ; - case SIGTERM: - case SIGINT: - /** TODO, little ugly for me - * KILL work but s6-supervice reload it*/ - if (SIGNAL == UP || SIGNAL == RUP) - s6_svc_writectl(sv, S6_SUPERVISE_CTLDIR, "d", 1) ; - // kill(status.pid, SIGKILL) ; - return -1 ; - default : VERBO3 strerr_warnw1x("inconsistent signal state") ; return 0 ; - } - } + exitcode = WIFEXITED(status.wstat) ; + exitstatus = WEXITSTATUS(status.wstat) ; + if (exitcode && exitstatus <= 1) return 1 ; + else return 0 ; } -/** we use three file more for s6-svc service : + +static unsigned char const actions[9][9] = +{ + //signal receive: + // c->u U r/u R/U d D x O s + //signal wanted + { GOTIT, DONE, GOTIT, DONE, DEAD, DEAD, PERM, PERM, UKNOW },// SIGUP + { WAIT, GOTIT, WAIT, GOTIT, DEAD, DEAD, PERM, PERM, UKNOW },// SIGRUP + { GOTIT, DONE, GOTIT, DONE, WAIT, WAIT, PERM, PERM, UKNOW },// SIGR + { WAIT, GOTIT, WAIT, GOTIT, WAIT, WAIT, PERM, PERM, UKNOW },// SIGRR + { DEAD, DEAD, DEAD, DEAD, GOTIT, DONE, PERM, PERM, UKNOW },// SIGDOWN + { DEAD, DEAD, DEAD, DEAD, WAIT, GOTIT, PERM, PERM, UKNOW },// SIGRDOWN + { DEAD, DEAD, DEAD, DEAD, WAIT, WAIT, GOTIT, WAIT, UKNOW },// SIGX + { WAIT, WAIT, WAIT, WAIT, WAIT, WAIT, PERM, GOTIT, UKNOW },// SIGO + { UKNOW, UKNOW, UKNOW, UKNOW, UKNOW, UKNOW, UKNOW, UKNOW, DONE }, // SIGSUP + +} ; +// convert signal receive into enum number +static const uint8_t chtenum[128] = +{ + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //8 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //16 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //24 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //32 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //40 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //48 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //56 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //64 + 0 , 0 , 0 , 0 , 5 , 0 , 0 , 0 , //72 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , //80 + 0 , 0 , 0 , 0 , 0 , 1, 0 , 0 , //88 + 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //96 + 0 , 0 , 0 , 0 , 4 , 0 , 0 , 0 , //104 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //112 + 0 , 0 , 0 , 8 , 0 , 0 , 0 , 0 , //120 + 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 //128 +} ; +/** we use three file more than s6-svc program : * * timeout-up and timeout-down will define the deadline for the iopause * each service contain his deadline into the sv_signal.deadline key. * If thoses files doesn't exit 3000 millisec is set by default. - * This deadline value can be set on commandline by the -S options. + * This deadline value can be set on commandline by the -T options. * max-death-tally * We let s6-supervise make what it need to do with this file but * we take the same number to set the sv_signal.death value @@ -208,7 +180,7 @@ int handle_signal_svc(svc_sig *sv_signal) * doesn't exist and the SIGNAL is U , we change SIGNAL to u and warn * the user about it. * - * In the iopause_svc function a reached timeout is not an absolute error + * In the send_svc function a reached timeout is not an absolute error * because we can have a notification-file in the servicedirs of the * service with a deamon which doesn't support readiness notification. * In this case, we send U and only receive u as event, the daemon is @@ -216,250 +188,145 @@ int handle_signal_svc(svc_sig *sv_signal) * We accept this case as an "half" success. We exit with success but * the user is warned about the state. */ -/** @Return -2 on SIGINT reception - * @Return -1 on error - * @Return 0 on fail - * @Return 1 on success - * @Return 2 if signal is not complete (e.g. want U receive only u) - * @Return 3 for PERMANENT failure - * @Return 4 is a last status checking is need */ -int iopause_svc(svc_sig *sv_signal,char const *sig, ftrigr_t *fifo) -{ +/**@Return 0 on success + * @Return 1 on if signal is not complete (e.g. want U receive only u) + * @Return 2 on fail + * @Return 3 for PERMANENT failure */ - int id ; +int handle_case(char c, svc_sig *sv_signal) +{ + int p, h, err ; + unsigned int state ; + state = sv_signal->sig ; + err = 2 ; - stralloc sa = STRALLOC_ZERO ; + p = chtenum[(unsigned char)c] ; - static unsigned char const actions[7][8] = - { - //signal receive: - // c->UP, RUP, DOWN, RDOWN O X SUP UNKNOW - { GOTIT, DONE, DEAD, DEAD, PERM, PERM, DEAD, UKNOW }, // u - { WAIT, GOTIT, DEAD, DEAD, PERM, PERM, DEAD, UKNOW }, // U signal - { DEAD, DEAD, GOTIT, DONE, DONE, DONE, DEAD, UKNOW }, // d wanted - { DEAD, DEAD, WAIT, GOTIT, DONE, DONE, DEAD, UKNOW }, // D - { DEAD, DEAD, DEAD, DEAD, OUT, OUT, GOTIT, UKNOW }, // s - { PERM, PERM, WAIT, WAIT, GOTIT, WAIT, PERM, UKNOW }, // O - { PERM, PERM, DONE, GOTIT, DONE, GOTIT, PERM, UKNOW }, // x - + unsigned char action = actions[state][p] ; - } ; -// convert signal receive into enum number - static const uint8_t chtenum[128] = - { - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 3 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 5 , - 0 , 0 , 0 , 0 , 0 , 1, 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 - } ; - - int spfd = selfpipe_init() ; - if (spfd < 0){ VERBO3 strerr_warnwu1sys("init selfpipe") ; return -1 ; } + switch (action) { - sigset_t set ; - sigemptyset(&set) ; - sigaddset(&set, SIGINT) ; - sigaddset(&set, SIGTERM) ; - if (selfpipe_trapset(&set) < 0) - { - VERBO3 strerr_warnwu1sys("trap signals") ; - return -1 ; - } + case GOTIT: + h = handle_signal_svc(sv_signal) ; + + if (!h) + { + err = 1 ; + break ; + } + err = 0 ; + break ; + case WAIT: + err = 1 ; + break ; + case DEAD: + err = 2 ; + break ; + case DONE: + err = 0 ; + break ; + case PERM: + err = 3 ; + break ; + case UKNOW: + default: + VERBO3 strerr_warnw1x("invalid state, make a bug report"); + err = 2 ; + break ; } - - iopause_fd x[2] = { { .fd = ftrigr_fd(fifo), .events = IOPAUSE_READ }, { .fd = spfd, .events = IOPAUSE_READ, .revents = 0 } } ; - - unsigned int t, h, p, state, err, check ; - - err = h = t = check = 0 ; - state = SIGNAL ; - tain_now_g() ; - tain_add_g(&sv_signal->deadline,&sv_signal->deadline) ; + return err ; +} - int n = sv_signal->ndeath ; - /** loop even number of death is reached */ - while(n>0) +static int handle_signal_pipe(svc_sig *svc) +{ + char *sv = svkeep.s + svc->scan ; + for (;;) { - int r = iopause_g(x, 2, &sv_signal->deadline) ; - if (r < 0){ VERBO3 strerr_warnwu1sys("iopause") ; err = -1 ; goto end ; } - /** timeout is not a error , the iopause process did right */ - else if (!r) { VERBO3 strerr_warnt2x("timed out reached for: ",svkeep.s + sv_signal->scan) ; t = 1 ; goto end ; } - if (x[1].revents & IOPAUSE_READ) - if (handle_signal_svc(sv_signal) < 0){ err = -2 ; goto end ; } - - if (x->revents & IOPAUSE_READ) - { - - id = ftrigr_updateb(fifo) ; - if (id < 0){ VERBO3 strerr_warnwu1sys("ftrigr_update") ; return -1 ; } - if (id) - { - sa.len = 0 ; - r = ftrigr_checksa(fifo, id, &sa) ; - if (r < 0) { VERBO3 strerr_warnwu1sys("ftrigr_update") ; return -1 ; } - if (r) - { - VERBO3 - { - buffer_putsflush(buffer_1,"66-svctl: tracing: ") ; - buffer_putsflush(buffer_1,"signal received: ") ; - buffer_putflush(buffer_1,sa.s,1) ; - buffer_putsflush(buffer_1,"\n") ; - } - for (int i = 0;i < sa.len ; i++) - { - - p = chtenum[(unsigned char)sa.s[i]] ; - { - unsigned char action = actions[state][p] ; - - switch (action) - { - case GOTIT: - h = handle_signal_svc(sv_signal) ; - if (h) - { - check = 4 ; - break ; - } - err = 1 ; - goto end ; - case WAIT: - err = 2 ; - break ; - case DEAD: - err = -1 ; - break ; - case DONE: - err = 1 ; - goto end ; - case OUT: - err = 0 ; - goto end ; - case PERM: - err = 3 ; - goto end ; - case UKNOW : - default: - VERBO3 strerr_warnw1x("invalid state"); - err = -1 ; - goto end ; - } - } - } - } - } - n-- ; + switch (selfpipe_read()) + { + case -1 : strerr_warnwu1sys("selfpipe_read") ; return 0 ; + case 0 : return 1 ; + case SIGTERM: + case SIGINT: + // TODO, little ugly for me + VERBO2 strerr_warnw1x("received SIGINT, aborting service transition") ; + if (svc->sig <= SIGRR) + s6_svc_writectl(sv, S6_SUPERVISE_CTLDIR, "d", 1) ; + return 0 ; + default : strerr_warn1x("unexpected data in selfpipe") ; return 0 ; } } - end: - stralloc_free(&sa) ; - selfpipe_finish() ; - - if (err == 2 && sv_signal->ndeath == 1 && !h) - err = 2 ; - - if ((err < 0) && (t) ) - err = 2 ; - - if (check) return check ; +} +static void announce(svc_sig *sv_signal) +{ - return err ; + int r = sv_signal->state ; + char *sv = svkeep.s + sv_signal->scan ; + if (r == 3) { VERBO2 strerr_warnw3x(sv," report permanent failure to bring ",(sv_signal->sig > 1) ? "down" : "up") ; } + else if (r == 2) { VERBO2 strerr_warnwu3x("bring ", (sv_signal->sig > 3) ? "down " : "up ", sv) ; } + else if (r == 1) { VERBO2 strerr_warni4x(sv," is ",(sv_signal->sig > 3) ? "down" : "up"," but not notified by the daemon itself") ; } + else if (!r) { VERBO2 strerr_warni4x(sv,": ",(sv_signal->sig > 3) ? "stopped" : "started"," successfully") ; } } -int send_svc(svc_sig *sv_signal, char const *sig, ftrigr_t *fifo,tain_t const *ttmain) +int svc_listen(genalloc *gasv, ftrigr_t *fifo,int spfd,svc_sig *svc) { - int r, id, fdlock ; - size_t siglen = strlen(sig) ; - - size_t scanlen = sv_signal->scanlen ; - char *svok = svkeep.s + sv_signal->scan ; + int r ; + iopause_fd x[2] = { { .fd = ftrigr_fd(fifo), .events = IOPAUSE_READ } , { .fd = spfd, .events = IOPAUSE_READ, .revents = 0 } } ; + + tain_t t ; + tain_now_g() ; + tain_add_g(&t,&svc->deadline) ; - char svfifo[scanlen + 6 + 1] ; - memcpy(svfifo, svok,scanlen) ; - memcpy(svfifo + scanlen, "/event",6 + 1) ; + VERBO3 strerr_warnt2x("start iopause for: ",svkeep.s + svc->name) ; - VERBO3 strerr_warnt2x("take lock of: ",svok) ; - fdlock = s6_svc_lock_take(svok) ; - if (fdlock < 0) - { - VERBO3 strerr_warnwu2sys("take lock of: ",svok) ; - return 0 ; - } - VERBO3 strerr_warnt2x("clean up fifo: ", svfifo) ; - if (!ftrigw_clean (svok)) + for(;;) { - VERBO3 strerr_warnwu2sys("clean up fifo: ", svfifo) ; - return 0 ; - } - VERBO3 strerr_warnt2x("subcribe to fifo: ",svfifo) ; - /** we let opened the fifo for the iopause work */ - id = ftrigr_subscribe_g(fifo, svfifo, "[DuUdOx]", 1, ttmain) ; - if (!id) - { - VERBO3 strerr_warnwu2sys("subcribe to fifo: ",svfifo) ; - goto errlock ; - } - VERBO3 strerr_warnt2x("unlock: ",svok) ; - s6_svc_lock_release(fdlock) ; - VERBO3 strerr_warnt6x("send signal: ",sig," to: ", svok,"/",S6_SUPERVISE_CTLDIR) ; - r = s6_svc_writectl(svok, S6_SUPERVISE_CTLDIR, sig, siglen) ; - if (r < 0) - { - VERBO3 strerr_warnwu3sys("something is wrong with the ",svok, "/" S6_SUPERVISE_CTLDIR " directory. errno reported") ; - goto errunsub ; - } - if (!r) - { - VERBO3 strerr_warnw3x("sv: ",svok, " is not supervised") ; - goto errunsub ; - } - VERBO3 strerr_warnt2x("start iopause for: ",svok) ; - r = iopause_svc(sv_signal,sig,fifo) ; - - if (r < 0) - { - VERBO3 strerr_warnt1sys("handle iopause") ; - return -1 ; + char receive ; + r = ftrigr_check(fifo,svc->ids, &receive) ; + if (r < 0) { VERBO3 strerr_warnwu1sys("ftrigr_check") ; return 0 ; } + if (r) + { + svc->state = handle_case(receive, svc) ; + if (svc->state < 0) return 0 ; + if (!svc->state){ announce(svc) ; break ; } + else if (svc->state > 2){ announce(svc) ; break ; } + } + if (!(svc->ndeath)) + { + VERBO2 strerr_warnw2x("number of try exceeded for: ",svkeep.s + svc->scan) ; + announce(svc) ; + break ; + } + + r = iopause_g(x, 2, &t) ; + if (r < 0){ VERBO3 strerr_warnwu1sys("iopause") ; return 0 ; } + /** timeout is not a error , the iopause process did right */ + else if (!r) { VERBO3 strerr_warnt2x("timed out reached for: ",svkeep.s + svc->name) ; announce(svc) ; break ; } + + if (x[1].revents & IOPAUSE_READ) return handle_signal_pipe(svc) ? 1 : 0 ; + + if (x[0].revents & IOPAUSE_READ) + { + if (ftrigr_update(fifo) < 0){ VERBO3 strerr_warnwu1sys("ftrigr_update") ; return 0 ; } + svc->ndeath--; + } } - if (!ftrigr_unsubscribe_g(fifo,id, ttmain)) - { - VERBO3 strerr_warnwu2sys("unsubcribe from: ",svfifo) ; - return 0 ; - } - - return r ; - - errlock: - s6_svc_lock_release(fdlock) ; - errunsub: - if (!ftrigr_unsubscribe_g(fifo,id, &sv_signal->deadline)) VERBO3 strerr_warnwu2sys("unsubcribe from: ",svfifo) ; - return 0 ; + return 1 ; } int main(int argc, char const *const *argv,char const *const *envp) { - int r, e ; - + int r, e, isup ; + unsigned int death, tsv ; uid_t owner ; + svc_sig sv_signal = SVC_SIG_ZERO ; char *treename = 0 ; + char *sig = 0 ; stralloc base = STRALLOC_ZERO ; stralloc tree = STRALLOC_ZERO ; @@ -469,10 +336,7 @@ int main(int argc, char const *const *argv,char const *const *envp) ftrigr_t fifo = FTRIGR_ZERO ; s6_svstatus_t status = S6_SVSTATUS_ZERO ; - tain_t ttmain ; - unsigned int deathsv = 0 ; - unsigned int tmain = 0 ; - unsigned int tsv = 0 ; + tsv = death = 0 ; PROG = "66-svctl" ; { @@ -480,7 +344,7 @@ int main(int argc, char const *const *argv,char const *const *envp) for (;;) { - int opt = getopt_args(argc,argv, "hv:l:t:T:S:n:udUD", &l) ; + int opt = getopt_args(argc,argv, "hv:l:t:T:n:udUDXrRK", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) @@ -493,13 +357,16 @@ int main(int argc, char const *const *argv,char const *const *envp) case 't' : if(!stralloc_cats(&tree,l.arg)) retstralloc(111,"main") ; if(!stralloc_0(&tree)) retstralloc(111,"main") ; break ; - case 'T' : if (!uint0_scan(l.arg, &tmain)) exitusage() ; break ; - case 'S' : if (!uint0_scan(l.arg, &tsv)) exitusage() ; break ; - case 'n' : if (!uint0_scan(l.arg, &deathsv)) exitusage() ; break ; - case 'u' : if (SIGNAL == DOWN || SIGNAL == RDOWN) exitusage() ; SIGNAL = UP ; break ; - case 'U' : if (SIGNAL == DOWN || SIGNAL == DOWN) exitusage() ; SIGNAL = RUP ; break ; - case 'd' : if (SIGNAL == UP || SIGNAL == RUP) ; SIGNAL = DOWN ; break ; - case 'D' : if (SIGNAL == UP || SIGNAL == RUP) ; SIGNAL = RDOWN ; break ; + case 'T' : if (!uint0_scan(l.arg, &tsv)) exitusage() ; break ; + case 'n' : if (!uint0_scan(l.arg, &death)) exitusage() ; break ; + case 'u' : if (SIGNAL > 0) exitusage() ; SIGNAL = SIGUP ; sig ="u" ; break ; + case 'U' : if (SIGNAL > 0) exitusage() ; SIGNAL = SIGRUP ; sig = "u" ; break ; + case 'd' : if (SIGNAL > 0) ; SIGNAL = SIGDOWN ; sig = "d" ; break ; + case 'D' : if (SIGNAL > 0) ; SIGNAL = SIGRDOWN ; sig = "d" ; break ; + case 'X' : if (SIGNAL > 0) ; SIGNAL = SIGX ; sig = "dx" ; break ; + case 'K' : if (SIGNAL > 0) ; SIGNAL = SIGRDOWN ; sig = "kd" ; break ; + case 'r' : if (SIGNAL > 0) ; SIGNAL = SIGR ; sig = "r" ; break ; + case 'R' : if (SIGNAL > 0) ; SIGNAL = SIGRR ; sig = "r" ; break ; default : exitusage() ; } @@ -509,9 +376,6 @@ int main(int argc, char const *const *argv,char const *const *envp) if (argc < 1 || (SIGNAL < 0)) exitusage() ; - if (tmain) tain_from_millisecs(&ttmain, tmain) ; - else ttmain = tain_infinite_relative ; - owner = MYUID ; if (!set_ownersysdir(&base,owner)) strerr_diefu1sys(111, "set owner directory") ; @@ -559,6 +423,7 @@ int main(int argc, char const *const *argv,char const *const *envp) svok[svoklen] = '/' ; memcpy(svok + svoklen + 1 ,svname,namelen + 1) ; svoklen = svoklen + 1 + namelen ; + /** do not check the logger*/ if (!resolve_pointo(&saresolve,base.s,live.s,tree.s,treename,0,SS_RESOLVE_SRC)) { @@ -574,6 +439,21 @@ int main(int argc, char const *const *argv,char const *const *envp) if (!r) strerr_dief2x(110,svok," is not initialized") ; } } + + if (!s6_svstatus_read(svok,&status)) strerr_diefu2sys(111,"read status of: ",svok) ; + isup = status.pid && !status.flagfinishing ; + + if (isup && (SIGNAL <= SIGRUP)) + { + VERBO2 strerr_warni2x(svok,": already up") ; + continue ; + } + else if (!isup && (SIGNAL >= SIGDOWN)) + { + VERBO2 strerr_warni2x(svok,": already down") ; + continue ; + } + sv_signal.scan = svkeep.len ; if (!stralloc_catb(&svkeep, svok, svoklen + 1)) retstralloc(111,"main") ; sv_signal.scanlen = svoklen ; @@ -586,6 +466,8 @@ int main(int argc, char const *const *argv,char const *const *envp) if (!stralloc_catb(&svkeep, src, srclen + 1)) retstralloc(111,"main") ; sv_signal.srclen = srclen ; + sv_signal.sigtosend = sig ; + sv_signal.sig = SIGNAL ; /** notification-fd */ memcpy(svok + svoklen,"/notification-fd",16) ; @@ -595,10 +477,24 @@ int main(int argc, char const *const *argv,char const *const *envp) if (access(svok, F_OK) < 0) { if (errno != ENOENT) strerr_diefu2sys(111, "access ", svok) ; - if (SIGNAL == RUP) SIGNAL = UP ; - if (SIGNAL == RDOWN) SIGNAL = DOWN ; - - VERBO2 strerr_warnw2x(svok, " is not present - ignoring request for readiness notification") ; + if (SIGNAL == SIGRUP) + { + sv_signal.sig = SIGUP ; + sv_signal.sigtosend = "uwu" ; + VERBO2 strerr_warnw2x(svok, " is not present - ignoring request for readiness notification") ; + } + if (SIGNAL == SIGRR) + { + sv_signal.sig = SIGR ; + sv_signal.sigtosend = "uwr" ; + VERBO2 strerr_warnw2x(svok, " is not present - ignoring request for readiness notification") ; + } + if (SIGNAL == SIGRDOWN) + { + sv_signal.sig = SIGDOWN ; + sv_signal.sigtosend = "dwd" ; + VERBO2 strerr_warnw2x(svok, " is not present - ignoring request for readiness notification") ; + } } else { @@ -606,7 +502,7 @@ int main(int argc, char const *const *argv,char const *const *envp) } /** max-death-tally */ - if (!deathsv) + if (!death) { memcpy(svok + svoklen,"/max-death-tally", 16) ; svok[svoklen + 16] = 0 ; @@ -615,22 +511,29 @@ int main(int argc, char const *const *argv,char const *const *envp) { if (errno != ENOENT) strerr_diefu2sys(111, "access ", svok) ; } + if (errno == ENOENT) + { + sv_signal.ndeath = DEATHSV ; + } else { if (!read_uint(svok,&sv_signal.ndeath)) strerr_diefu2sys(111,"read: ",svok) ; } } - else sv_signal.ndeath = deathsv ; - - errno = 0 ; - - if (!tsv) + else sv_signal.ndeath = death ; + + tain_t tcheck ; + tain_from_millisecs(&tcheck,tsv) ; + int check = tain_to_millisecs(&tcheck) ; + if (check > 0) tain_from_millisecs(&sv_signal.deadline, tsv) ; + + else { /** timeout-{up/down} */ { char *tm = NULL ; unsigned int t ; - if (SIGNAL == RUP || SIGNAL == UP) + if (SIGNAL <= SIGRR) { tm="/timeout-up" ; } @@ -638,7 +541,7 @@ int main(int argc, char const *const *argv,char const *const *envp) { tm="/timeout-down" ; } - + errno = 0 ; memcpy(svok + svoklen,tm, strlen(tm) + 1) ; if (access(svok, F_OK) < 0) { @@ -655,7 +558,7 @@ int main(int argc, char const *const *argv,char const *const *envp) } } } - else tain_from_millisecs(&sv_signal.deadline, tsv) ; + errno = e ; if (!genalloc_append(svc_sig,&gakeep,&sv_signal)) strerr_diefu1sys(111,"append genalloc") ; @@ -667,124 +570,31 @@ int main(int argc, char const *const *argv,char const *const *envp) stralloc_free(&tree) ; stralloc_free(&scandir) ; - if (!genalloc_len(svc_sig,&gakeep)) - { - VERBO2 strerr_warni1x("nothing to do") ; - return 0 ; - } + /** nothing to do */ + if (!genalloc_len(svc_sig,&gakeep)) goto finish ; - tain_now_g() ; - tain_add_g(&ttmain, &ttmain) ; - - VERBO2 strerr_warni1x("initiate fifo: fifo") ; - if (!ftrigr_startf(&fifo, &ttmain, &STAMP)) - strerr_diefu1sys(111,"initiate fifo") ; - - for (unsigned int i = 0 ; i < genalloc_len(svc_sig,&gakeep) ; i++) - { - int isup ; - char *sig ; - - char *sv = svkeep.s + genalloc_s(svc_sig,&gakeep)[i].scan ; - if (!s6_svstatus_read(sv,&status)) strerr_diefu2sys(111,"read status of: ",sv) ; - isup = status.pid && !status.flagfinishing ; - - if (isup && (SIGNAL == RUP || SIGNAL == UP)) - { - VERBO2 strerr_warni2x(sv,": already up") ; - continue ; - } - - if (isup && (SIGNAL == RDOWN || SIGNAL == DOWN)) - { - if (SIGNAL == RDOWN) - sig = "dwD" ; - else sig = "dwd" ; - - VERBO2 strerr_warni3x("bring down ", sv," ...") ; - r = send_svc(&genalloc_s(svc_sig,&gakeep)[i],sig,&fifo,&ttmain) ; - if (r == 4) - { - if (!s6_svstatus_read(sv,&status)) strerr_diefu2sys(111,"read status of: ",sv) ; - isup = status.pid && !status.flagfinishing ; - if (!isup) r = 1 ; - else r = 0 ; - } - if (r == 3) - { - VERBO2 strerr_warnw2x(sv," report permanent failure to bring down") ; - goto errftrigr ; - } - if (r == 2) VERBO2 strerr_warni2x(sv," is down but not notified by the daemon itself") ; - if (!r) - { - VERBO2 strerr_warnwu2x("bring down: ", sv) ; - goto errftrigr ; - } - if (r < -1) - { - VERBO2 strerr_warnw1x("received SIGINT, aborting service transition") ; - goto errftrigr ; - } - if (r == 1) VERBO2 strerr_warni2x(sv,": stopped successfully") ; - continue ; - } - - if (!isup && (SIGNAL == RDOWN || SIGNAL == DOWN)) - { - VERBO2 strerr_warni2x(sv,": already down") ; - continue ; - } + int spfd = selfpipe_init() ; + if (spfd < 0) strerr_diefu1sys(111, "selfpipe_trap") ; + if (selfpipe_trap(SIGINT) < 0) strerr_diefu1sys(111, "selfpipe_trap") ; + if (selfpipe_trap(SIGTERM) < 0) strerr_diefu1sys(111, "selfpipe_trap") ; + if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111,"ignore SIGPIPE") ; - if (!isup && (SIGNAL == RUP || SIGNAL == UP)) - { - if (SIGNAL == RUP) - sig = "uwU" ; - else sig = "uwu" ; - - VERBO2 strerr_warni3x("bring up ", sv," ...") ; - r = send_svc(&genalloc_s(svc_sig,&gakeep)[i],sig,&fifo,&ttmain) ; - if (r == 4) - { - if (!s6_svstatus_read(sv,&status)) strerr_diefu2sys(111,"read status of: ",sv) ; - isup = status.pid && !status.flagfinishing ; - if (isup) r = 1 ; - else r = 0 ; - } - if (r == 3) - { - VERBO2 strerr_warnw2x(sv,"report permanent failure to bring up") ; - goto errftrigr ; - } - if (r == 2) VERBO2 strerr_warni2x(sv," is up but not notified by the daemon itself") ; - if (!r) - { - VERBO2 strerr_warnwu2x("bring up: ", sv) ; - goto errftrigr ; - } - if (r < -1) - { - VERBO2 strerr_warnw1x("received SIGINT, aborting service transition") ; - goto errftrigr ; - } - if (r == 1) VERBO2 strerr_warni2x(sv,": started successfully") ; - - } + if (!svc_init_pipe(&fifo,&gakeep,&svkeep)) strerr_diefu1x(111,"init pipe") ; + + for (unsigned int i = 0 ; i < genalloc_len(svc_sig,&gakeep) ; i++) + { + svc_sig *sv = &genalloc_s(svc_sig,&gakeep)[i] ; + if (!svc_listen(&gakeep,&fifo,spfd,sv)) strerr_diefu1x(111,"listen pipe") ; } - ftrigr_end(&fifo) ; - stralloc_free(&svkeep) ; - genalloc_free(svc_sig,&gakeep) ; - free(treename) ; - - return 0 ; - - errftrigr: + finish: ftrigr_end(&fifo) ; + selfpipe_finish() ; stralloc_free(&svkeep) ; genalloc_free(svc_sig,&gakeep) ; free(treename) ; - return 111 ; + + return 0 ; } diff --git a/src/66/66-tree.c b/src/66/66-tree.c index 5c7fc8485b23fc5f8fb5deb66d19b3edeeafcb53..a4affc09d0c7e48b2012c50566bdc055d0526b2b 100644 --- a/src/66/66-tree.c +++ b/src/66/66-tree.c @@ -33,8 +33,9 @@ #include <66/constants.h> #include <66/db.h> -#include <stdio.h> -#define USAGE "66-tree [ -h help ] [ -v verbosity ] [ -n new ] [ -a allow user,user,... ] [ -d deny user,user,... ] [ -c current ] [ -E enable ] [ -D disable ] [ -R remove ] [ -C clone ] tree" +//#include <stdio.h> + +#define USAGE "66-tree [ -h ] [ -v verbosity ] [ -n | R ] [ -a ] [ -d ] [ -c ] [ -E | D ] [ -C ] tree" unsigned int VERBOSITY = 1 ; diff --git a/src/extra-tools/66-envfile.c b/src/extra-tools/66-envfile.c new file mode 100644 index 0000000000000000000000000000000000000000..dc980d2ed78528092cdc6ca5a94940e02733e4cc --- /dev/null +++ b/src/extra-tools/66-envfile.c @@ -0,0 +1,251 @@ +/* + * 66-envfile.c + * + * Copyright (c) 2018 Eric Vidal <eric@obarun.org> + * + * All rights reserved. + * + * This file is part of Obarun. It is subject to the license terms in + * the LICENSE file found in the top-level directory of this + * distribution. + * This file may not be copied, modified, propagated, or distributed + * except according to the terms contained in the LICENSE file./ + */ +#include <string.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <unistd.h> + +#include <oblibs/string.h> +#include <oblibs/stralist.h> +#include <oblibs/error2.h> +#include <oblibs/obgetopt.h> +#include <oblibs/directory.h> +#include <oblibs/files.h> + +#include <skalibs/bytestr.h> +#include <skalibs/stralloc.h> +#include <skalibs/genalloc.h> +#include <skalibs/env.h> +#include <skalibs/djbunix.h> +#include <skalibs/diuint32.h> +#include <skalibs/env.h> +#include <skalibs/sgetopt.h> + +#include <execline/execline.h> + +#include <66/parser.h> + +//#include <stdio.h> + +unsigned int VERBOSITY = 1 ; +static stralloc senv = STRALLOC_ZERO ; +static genalloc gaenv = GENALLOC_ZERO ; //diuint32, pos in senv + +#define USAGE "66-envfile [ -h help ] [ -f file ] [ -l ] dir prog" + +typedef struct exlsn_s exlsn_t, *exlsn_t_ref ; +struct exlsn_s +{ + stralloc vars ; + stralloc values ; + genalloc data ; // array of elsubst + stralloc modifs ; +} ; + +#define EXLSN_ZERO { .vars = STRALLOC_ZERO, .values = STRALLOC_ZERO, .data = GENALLOC_ZERO, .modifs = STRALLOC_ZERO } + +static inline void info_help (void) +{ + static char const *help = +"66-envfile <options> dir prog\n" +"\n" +"options :\n" +" -h: print this help\n" +" -f: file to parse\n" +" -l: loose\n" +; + + if (buffer_putsflush(buffer_1, help) < 0) + strerr_diefu1sys(111, "write to stdout") ; +} + +static int env_substitute(char const *key, char const *val,exlsn_t *info, char const *const *envp,int unexport) +{ + char const *defaultval = "" ; + char const *x ; + int insist = 0 ; + + eltransforminfo_t si = ELTRANSFORMINFO_ZERO ; + elsubst_t blah ; + + blah.var = info->vars.len ; + blah.value = info->values.len ; + + if (el_vardupl(key, info->vars.s, info->vars.len)) strerr_dief1x(111, "bad substitution key") ; + if (!stralloc_catb(&info->vars,key, strlen(key) + 1)) retstralloc(111,"env_substitute") ; + + x = env_get2(envp, key) ; + if (!x) + { + if (insist) strerr_dief2x(111, val,": is not set") ; + x = defaultval ; + } + else if (unexport) + { + if (!stralloc_catb(&info->modifs, key, strlen(key) + 1)) goto err ; + } + if (!x) blah.n = 0 ; + else + { + int r ; + if (!stralloc_cats(&info->values, x)) goto err ; + r = el_transform(&info->values, blah.value, &si) ; + if (r < 0) goto err ; + blah.n = r ; + } + + if (!genalloc_append(elsubst_t, &info->data, &blah)) goto err ; + + return 1 ; + + err: + info->vars.len = blah.var ; + info->values.len = blah.value ; + strerr_diefu1x(111,"complete environment substition") ; +} + +int new_env(char const *path,char const *file,stralloc *modifs) +{ + int nbline = 0, i = 0 ; + + keynocheck nocheck = KEYNOCHECK_ZERO ; + genalloc gatmp = GENALLOC_ZERO ;//stralist + + if (!file_readputsa(&nocheck.val,path,file)) strerr_diefu4sys(111,"read file: ",path,"/",file) ; + if (!parse_env(&nocheck)) strerr_dief2x(111,"parse file: ", file) ; + + nbline = get_nbline_ga(nocheck.val.s,nocheck.val.len,&gatmp) ; + + for (i = 0;i < nbline;i++) + if (!add_env(gaistr(&gatmp,i),&gaenv,&senv)) strerr_diefu2x(111,"append genalloc with: ",gaistr(&gatmp,i)) ; + + for (i = 0 ; i < genalloc_len(diuint32,&gaenv) ; i++) + { + int key = genalloc_s(diuint32,&gaenv)[i].left ; + int val = genalloc_s(diuint32,&gaenv)[i].right ; + if ((senv.s+key)[0] == '!') + key++; + if (!env_addmodif(modifs,senv.s + key,senv.s + val)) strerr_diefu1x(111,"add environment") ; + } + + genalloc_deepfree(stralist,&gatmp,stra_free) ; + + return 1 ; +} + +int main (int argc, char const *const *argv, char const *const *envp) +{ + int r, i, one, unexport ; + int insist = 1 ; + + char const *path = 0 ; + char const *file = 0 ; + + stralloc modifs = STRALLOC_ZERO ; + stralloc dst = STRALLOC_ZERO ; + genalloc toparse = GENALLOC_ZERO ; //stralist + + + + exlsn_t info = EXLSN_ZERO ; + + r = i = one = unexport = 0 ; + insist = 1 ; + + PROG = "66-envfile" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + + for (;;) + { + int opt = subgetopt_r(argc,argv, ">hlf:", &l) ; + if (opt == -1) break ; + if (opt == -2) strerr_dief1x(110,"options must be set first") ; + switch (opt) + { + case 'h' : info_help(); return 0 ; + case 'f' : file = l.arg ; one = 1 ; break ; + case 'l' : insist = 0 ; break ; + default : exitusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + } + + if (argc < 2) exitusage() ; + + path = *argv ; + + if (path[0] != '/') strerr_dief3x(111,"directory: ",path," must be an absolute path") ; + + r = dir_get(&toparse,path,"",S_IFREG) ; + if (!r && insist) strerr_diefu2sys(111,"get file from: ",path) ; + else if (!r && !insist) + { + argv++; + argc--; + xpathexec_run(argv[0],argv,envp) ; + } + + if (one) + { + r = stra_findidx(&toparse,file) ; + if (r < 0) strerr_diefu2x(111,"find: ",file) ; + new_env(path,file,&modifs) ; + } + else + { + for (i = 0 ; i < genalloc_len(stralist,&toparse) ; i++) + new_env(path,gaistr(&toparse,i),&modifs) ; + } + genalloc_deepfree(stralist,&toparse,stra_free) ; + + size_t n = env_len(envp) + 1 + byte_count(modifs.s,modifs.len,'\0') ; + char const *newenv[n] ; + if (!env_merge (newenv, n ,envp,env_len(envp),modifs.s, modifs.len)) strerr_diefu1sys(111,"build environment") ; + + modifs = stralloc_zero ; + + for (i = 0 ; i < genalloc_len(diuint32,&gaenv) ; i++) + { + unexport = 0 ; + int key = genalloc_s(diuint32,&gaenv)[i].left ; + int val = genalloc_s(diuint32,&gaenv)[i].right ; + if ((senv.s+key)[0] == '!') + { + key++ ; + unexport = 1 ; + } + env_substitute(senv.s + key,senv.s + val,&info,newenv,unexport) ; + } + genalloc_free(diuint32,&gaenv) ; + stralloc_free(&senv) ; + + argv++; + argc--; + + if (!env_string (&modifs, argv, (unsigned int) argc)) strerr_diefu1x(111,"make environment string") ; + r = el_substitute (&dst, modifs.s, modifs.len, info.vars.s, info.values.s, + genalloc_s (elsubst_t const, &info.data),genalloc_len (elsubst_t const, &info.data)) ; + if (r < 0) strerr_diefu1sys(111,"el_substitute") ; + else if (!r) _exit(0) ; + + stralloc_free(&modifs) ; + { + char const *v[r + 1] ; + if (!env_make (v, r ,dst.s, dst.len)) strerr_diefu1sys(111,"make environment") ; + v[r] = 0 ; + pathexec_r (v, newenv, env_len(newenv),info.modifs.s,info.modifs.len) ; + } +} diff --git a/src/extra-tools/deps-exe/66-envfile b/src/extra-tools/deps-exe/66-envfile new file mode 100644 index 0000000000000000000000000000000000000000..77b1d97fdc3b7efce73a9a3efb7a8691bb92c0ea --- /dev/null +++ b/src/extra-tools/deps-exe/66-envfile @@ -0,0 +1,5 @@ +${LIB66} +-lexecline +-loblibs +-lskarnet +${LIBEXECLINE} diff --git a/src/66/deps-exe/execl-cmdline b/src/extra-tools/deps-exe/execl-cmdline similarity index 100% rename from src/66/deps-exe/execl-cmdline rename to src/extra-tools/deps-exe/execl-cmdline diff --git a/src/66/execl-cmdline.c b/src/extra-tools/execl-cmdline.c similarity index 100% rename from src/66/execl-cmdline.c rename to src/extra-tools/execl-cmdline.c diff --git a/src/include/66/constants.h b/src/include/66/constants.h index 5d7439cdd43ad767f8c1dcc51329fb0f47f49dbd..b52bc373418e9cc60e4e1856dad6f64072acef30 100644 --- a/src/include/66/constants.h +++ b/src/include/66/constants.h @@ -74,7 +74,7 @@ #define SS_SWBACK 1 //switch to backup /** environment and data */ -#define SS_ENVDIR "/env" +#define SS_ENVDIR "/conf" #define SS_ENVDIR_LEN (sizeof SS_ENVDIR - 1) #define SS_DATADIR "/data" #define SS_DATADIR_LEN (sizeof SS_DATADIR - 1) diff --git a/src/include/66/parser.h b/src/include/66/parser.h index e36cfc11706e98a3be14299c56ac075ab9077862..a0f5c49dfe83cc1c709fa4dab982516d49e0ddec 100644 --- a/src/include/66/parser.h +++ b/src/include/66/parser.h @@ -131,7 +131,7 @@ struct sv_alltype_s uint32_t death ; int signal ; unsigned int pipeline ; //pos in deps - genalloc env ; //type sv_env, pos in gaenv + genalloc env ; //type diuint32, pos in saenv } ; #define SV_EXEC_ZERO \ @@ -294,6 +294,10 @@ extern void sep_err(int r,char const sepstart,char const sepend,char const *keyn extern int add_cname(genalloc *ga,avltree *tree,char const *name, sv_alltype *sv_before) ; +extern int add_env(char *line,genalloc *ga,stralloc *sa) ; + +extern int parse_env(keynocheck *nocheck) ; + extern int resolve_srcdeps(sv_alltype *sv_before,char const *svmain,char const *src, char const *tree,unsigned int *nbsv,stralloc *sasv) ; extern int parse_service_before(char const *src,char const *sv,char const *tree, unsigned int *nbsv, stralloc *sasv) ; @@ -326,7 +330,7 @@ extern int write_consprod(sv_alltype *sv,char const *prodname,char const *consna extern int write_dependencies(char const *src, sv_name_t *cname,char const *dst,char const *filename, genalloc *ga, unsigned int force) ; -extern int write_env(genalloc *env,stralloc *sa,char const *dst) ; +extern int write_env(char const *name, genalloc *env,stralloc *sa,char const *dst) ; extern void freed_parser(void) ; diff --git a/src/include/66/svc.h b/src/include/66/svc.h index 6c39a0b7ce6be0bda42ee231d160866b07e3ea0a..1f72dd8191fcf286990c46284b6074f21d16833a 100644 --- a/src/include/66/svc.h +++ b/src/include/66/svc.h @@ -15,6 +15,97 @@ #ifndef SVC_H #define SVC_H +#include <skalibs/tai.h> +#include <skalibs/stralloc.h> +#include <skalibs/genalloc.h> +#include <s6/ftrigr.h> + +typedef struct svstat_s svstat_t, *svstat_t_ref ; +struct svstat_s +{ + int type ; + char const *name ; + size_t namelen ; + int down ; + int reload ; + int init ; + int unsupervise ; + int remove ; +} ; + +#define SVSTAT_ZERO \ +{ \ + .type = 0, \ + .name = 0, \ + .namelen = 0, \ + .down = 0, \ + .init = 0, \ + .reload = 0, \ + .unsupervise = 0, \ + .remove = 0 \ +} + +typedef struct svc_sig_s svc_sig, *svc_sig_t_ref ; +struct svc_sig_s +{ + unsigned int scan ; //pos in sv + size_t scanlen ; + unsigned int name ; //pos in sv + size_t namelen ; + unsigned int src ; //pos in sv + size_t srclen ; + unsigned int notify ; + unsigned int ndeath; + tain_t deadline ; + uint16_t ids ; + char *sigtosend ; + int sig ; + int state ; +} ; + +#define SVC_SIG_ZERO \ +{ \ + .scan = 0 , \ + .name = 0 , \ + .namelen = 0 , \ + .src = 0 , \ + .srclen = 0, \ + .notify = 0, \ + .ndeath = 3, \ + .deadline = TAIN_ZERO, \ + .ids = 0, \ + .sigtosend = 0, \ + .sig = 0, \ + .state = -1 \ +} + +typedef enum state_e state_t, *state_t_ref ; +enum state_e +{ + SIGUP = 0, // u + SIGRUP , // U - really up + SIGR, // r + SIGRR, // R - really up + SIGDOWN , // d + SIGRDOWN ,// D - really down + SIGX, //X + SIGO , //0 + SIGSUP //s supervise +} ; +typedef enum sigactions_e sigactions_t, *sigactions_t_ref ; +enum sigactions_e +{ + GOTIT = 0 , + WAIT , + DEAD , + DONE , + PERM , + UKNOW +} ; + + extern int svc_switch_to(char const *base, char const *tree,char const *treename,unsigned int where) ; +extern int svc_init(char const *scandir,char const *src, genalloc *ga) ; +extern int svc_init_pipe(ftrigr_t *fifo,genalloc *gasv,stralloc *sasv) ; #endif diff --git a/src/include/66/tree.h b/src/include/66/tree.h index 4dadfb3f1e39e5ad8cb8142b7ec39952f731029c..c80e2ceec0fe82d9350f47355ceaec8949a22e57 100644 --- a/src/include/66/tree.h +++ b/src/include/66/tree.h @@ -22,20 +22,6 @@ extern int tree_cmd_state(unsigned int verbosity,char const *cmd,char const *tree) ; extern int tree_state(int argc, char const *const *argv) ; -/** USAGE "tree_cmd_switcher [ -v verbosity ] [ -b backup ] [ -s switch ] tree" - * -b : look if current point to backup folder - * @Return 0 if point to original source - * @Return 1 if point to backup - * -s : point the current symlink to backup/source - * -s0 mean original source - * -s1 mean backup source - * @Return 1 on success - * @Return -1 on fail - * for -b option : @Return 0 for source - * @Return 1 for backup */ -extern int tree_cmd_switcher(unsigned int verbosity, char const *cmd,char const *tree) ; -extern int tree_switcher(int argc, char const *const *argv) ; - extern int tree_copy(stralloc *dir, char const *tree,char const *treename) ; extern int tree_copy_tmp(char const *workdir, char const *base, char const *live, char const *tree,char const *treename) ; @@ -48,7 +34,6 @@ extern int tree_copy_tmp(char const *workdir, char const *base, char const *live * @Return 0 on fail */ extern int tree_find_current(stralloc *tree, char const *base) ; -extern int tree_from_current(stralloc *sa, char const *tree) ; extern int tree_get_permissions(char const *tree) ; @@ -58,9 +43,4 @@ extern char *tree_setname(char const *tree) ; extern int tree_switch_current(char const *base, char const *tree) ; -extern int tree_switch_tobackup(char const *base, char const *treename, char const *tree, char const *livetree,char const *const *envp) ; - -extern int tree_make_backup(char const *base, char const *tree, char const *treename) ; - - #endif diff --git a/src/include/66/utils.h b/src/include/66/utils.h index 9781ef525a6b7935a4b6a95a4b149a9fd1549cfa..ed384f3318b5c8fc7a773511736f4cd755e0fb02 100644 --- a/src/include/66/utils.h +++ b/src/include/66/utils.h @@ -20,9 +20,6 @@ #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> -#include <skalibs/tai.h> - -#include <s6/ftrigr.h> extern unsigned int VERBOSITY ; @@ -35,28 +32,7 @@ extern unsigned int VERBOSITY ; #define MYGID getgid() #define YOURGID(passto,owner) yourgid(passto,owner) -typedef struct svstat_s svstat_t, *svstat_t_ref ; -struct svstat_s -{ - int type ; - char const *name ; - size_t namelen ; - int reload ; - int init ; - int unsupervise ; - int remove ; -} ; -#define SVSTAT_ZERO { .type = 0, .name = 0, .namelen = 0, .init = 0, .reload = 0, .unsupervise = 0, .remove = 0 } -/** signal */ -#define ALARM 0 - -/** struct to resolve source of service */ -typedef struct sv_src_s sv_src_t, *sv_src_t_ref ; -struct sv_src_s -{ - int name ; - int src ; -} ; + extern int dir_cmpndel(char const *src, char const *dst,char const *exclude) ; @@ -93,7 +69,7 @@ extern int resolve_symlive(char const *live, char const *tree, char const *treen extern int resolve_pointo(stralloc *sa,char const *base, char const *live,char const *tree,char const *treename,unsigned int type, unsigned int what) ; -extern int resolve_src(genalloc *ga, stralloc *sasrc, char const *name, char const *src) ; +extern int resolve_src(genalloc *ga, stralloc *sasrc, char const *name, char const *src,unsigned int *found) ; extern int insta_check(char const *svname) ; diff --git a/src/lib66/db_ok.c b/src/lib66/db_ok.c index 52c8c795c3b942829bd61296f5e10d93595ae18e..09f4ab58a8592216ee285c2bbeaa355dadeceb8e 100644 --- a/src/lib66/db_ok.c +++ b/src/lib66/db_ok.c @@ -30,7 +30,7 @@ int db_ok(char const *livetree, char const *treename) sym[treelen] = '/' ; memcpy(sym + treelen + 1, treename,namelen) ; sym[treelen + 1 + namelen] = 0 ; - + if(lstat(sym,&st) < 0) return 0 ; if(!(S_ISLNK(st.st_mode))) return 0 ; diff --git a/src/lib66/deps-lib/66 b/src/lib66/deps-lib/66 index e540c0ff22bfd9334dc7ef47d6c261f4ddf64b17..4acfa46269454cd90206b839e5fae4fbe13e76ea 100644 --- a/src/lib66/deps-lib/66 +++ b/src/lib66/deps-lib/66 @@ -25,18 +25,16 @@ set_livetree.o set_ownerhome.o set_ownersysdir.o sv_alltype_zero.o +svc_init.o +svc_init_pipe.o svc_switch_to.o tree_cmd_state.o -tree_cmd_switcher.o tree_copy.o tree_copy_tmp.o tree_find_current.o -tree_from_current.o tree_get_permissions.o -tree_make_backup.o tree_sethome.o tree_setname.o tree_switch_current.o -tree_switch_tobackup.o -loblibs -lskarnet diff --git a/src/lib66/get_enum.c b/src/lib66/get_enum.c index 20145d494607e377ed9f48b64c1a7658478525b6..9a2366f83198499c98d7d453d7a1274546a6d125 100644 --- a/src/lib66/get_enum.c +++ b/src/lib66/get_enum.c @@ -42,7 +42,7 @@ char const *get_keybyid(key_enum_t key) (key == T_FINISH ) ? "@timeout-finish" : (key == T_KILL ) ? "@timeout-kill" : (key == T_UP ) ? "@timeout-up" : - (key == T_DOWN ) ? "t@imeout-down" : + (key == T_DOWN ) ? "@timeout-down" : (key == DEATH) ? "@maxdeath" : (key == EXEC ) ? "@execute" : (key == DESTINATION ) ? "@destination" : diff --git a/src/lib66/parser.c b/src/lib66/parser.c index 6675796617d1989a6550738c234c0ad9a2f565ea..e24b29deb9ef828b04feaa6132ab73e39f606c2e 100644 --- a/src/lib66/parser.c +++ b/src/lib66/parser.c @@ -29,6 +29,7 @@ #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> #include <skalibs/avltree.h> +#include <skalibs/diuint32.h> #include <66/enum.h> #include <66/config.h> @@ -278,7 +279,7 @@ static int deps_src(stralloc *newsrc,char const *src, char const *name, char con r = avltree_search(&deps_map,name,&avlid) ; if (r) return 2 ; //already added nothing to do - genalloc tmpsrc = GENALLOC_ZERO ; //type sv_src_t + genalloc tmpsrc = GENALLOC_ZERO ; //type diuint32 *newsrc = stralloc_zero ; @@ -303,13 +304,14 @@ static int deps_src(stralloc *newsrc,char const *src, char const *name, char con if (!r) { stralloc sa = STRALLOC_ZERO ; + unsigned int found = 0 ; if (!stralloc_obreplace(newsrc, SS_SERVICE_DIR)) retstralloc(0,"resolve_deps") ; - if (!resolve_src(&tmpsrc,&sa,name,newsrc->s)) + if (!resolve_src(&tmpsrc,&sa,name,newsrc->s,&found)) { VERBO3 strerr_warnwu2sys("find dependency ",name) ; return 0 ; } - if (!stralloc_obreplace(newsrc, sa.s + genalloc_s(sv_src_t,&tmpsrc)->src)) retstralloc(0,"resolve_deps") ; + if (!stralloc_obreplace(newsrc, sa.s + genalloc_s(diuint32,&tmpsrc)->right)) retstralloc(0,"resolve_deps") ; stralloc_free(&sa) ; } } @@ -320,7 +322,7 @@ static int deps_src(stralloc *newsrc,char const *src, char const *name, char con return 0 ; } - genalloc_free(sv_src_t,&tmpsrc) ; + genalloc_free(diuint32,&tmpsrc) ; return 1 ; } diff --git a/src/lib66/parser_utils.c b/src/lib66/parser_utils.c index e0334de2c2da62ed4ec42d59351dde36bf2a920a..c81a06cf24fc04774e8f1bc5314fe9786814a2e9 100644 --- a/src/lib66/parser_utils.c +++ b/src/lib66/parser_utils.c @@ -872,7 +872,7 @@ int keep_logger(sv_execlog *log,keynocheck *nocheck) r = get_enumbyid (nocheck->val.s,key_enum_el) ; if (r < 0) { - VERBO3 parse_err(0,nocheck->idsec,TIMESTAMP) ; + VERBO3 parse_err(0,nocheck->idsec,TIMESTP) ; return 0 ; } log->timestamp = r ; diff --git a/src/lib66/parser_write.c b/src/lib66/parser_write.c index 7d9b624cd73c5d4f1d34fbd88fc4a51c8a8d4644..385af8f9330712f8a803c33c20913b8f1e0bd762 100644 --- a/src/lib66/parser_write.c +++ b/src/lib66/parser_write.c @@ -219,8 +219,15 @@ int write_services(sv_alltype *sv, char const *workdir, unsigned int force) } } } - - + /** down file*/ + if (sv->flags[0]) + { + if (!resolve_write(workdir,name,"down","",force)) + { + VERBO3 strerr_warnwu2x("write resolve file: down for service: ",name) ; + return 0 ; + } + } return 1 ; } @@ -745,18 +752,27 @@ int write_common(sv_alltype *sv, char const *dst) /** environment */ if (sv->opts[2]) { + stralloc sa = STRALLOC_ZERO ; + if (!set_ownersysdir(&sa,MYUID)) + { + VERBO3 strerr_warnwu1sys("get home system directory") ; + return 0 ; + } + /** /etc/env/sv_name*/ - size_t sslen = strlen(SS_SERVICEDIR) - 1 ; + size_t sslen = sa.len - 2 ;//-2 remove 0 and '/' char *name = keep.s + sv->cname.name ; - size_t namelen = strlen(name) ; - char dst[sslen + SS_ENVDIR_LEN + 1 + namelen + 1] ; - memcpy(dst,SS_SERVICEDIR,sslen) ; + char dst[sslen + SS_ENVDIR_LEN + 1] ; + memcpy(dst,sa.s,sslen) ; memcpy(dst + sslen,SS_ENVDIR,SS_ENVDIR_LEN) ; dst[sslen + SS_ENVDIR_LEN] = 0 ; + + stralloc_free(&sa) ; + r = scan_mode(dst,S_IFDIR) ; if (r < 0) { - VERBO3 strerr_warnwu2sys("invalid environment directory: ",dst) ; + VERBO3 strerr_warnw2sys("invalid environment directory: ",dst) ; return 0 ; } if (!r) @@ -767,12 +783,8 @@ int write_common(sv_alltype *sv, char const *dst) return 0 ; } } - - dst[sslen + SS_ENVDIR_LEN] = '/' ; - memcpy(dst + sslen + SS_ENVDIR_LEN + 1, name,namelen) ; - dst[sslen + SS_ENVDIR_LEN + 1 + namelen] = 0 ; - - if (!write_env(&sv->env,&saenv,dst)) + + if (!write_env(name,&sv->env,&saenv,dst)) { VERBO3 strerr_warnwu1x("write environment") ; return 0 ; @@ -785,10 +797,9 @@ int write_common(sv_alltype *sv, char const *dst) int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,int mode) { - unsigned int key, val ; unsigned int type = sv->cname.itype ; char *name = keep.s+sv->cname.name ; - size_t namelen = strlen(name) ; + size_t filelen = strlen(file) ; size_t dstlen = strlen(dst) ; char write[dstlen + 1 + filelen + 1] ; @@ -799,16 +810,21 @@ int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,in stralloc runuser = STRALLOC_ZERO ; stralloc execute = STRALLOC_ZERO ; - key = val = 0 ; - size_t envdstlen = strlen(SS_SERVICEDIR) - 1; - char envdata[envdstlen + SS_ENVDIR_LEN + 1 + namelen + 1] ; - memcpy(envdata,SS_SERVICEDIR,envdstlen) ; + stralloc sa = STRALLOC_ZERO ; + if (!set_ownersysdir(&sa,MYUID)) + { + VERBO3 strerr_warnwu1sys("get home system directory") ; + return 0 ; + } + size_t envdstlen = sa.len - 2 ;//-2 0 of stra and last '/' + char envdata[envdstlen + SS_ENVDIR_LEN + 1] ; + memcpy(envdata,sa.s,envdstlen) ; memcpy(envdata + envdstlen, SS_ENVDIR,SS_ENVDIR_LEN) ; - envdata[envdstlen + SS_ENVDIR_LEN] = '/' ; - memcpy(envdata + envdstlen + SS_ENVDIR_LEN + 1, name,namelen) ; - envdata[envdstlen + SS_ENVDIR_LEN + 1 + namelen] = 0 ; + envdata[envdstlen + SS_ENVDIR_LEN] = 0 ; - + + stralloc_free(&sa) ; + switch (exec->build) { case AUTO: @@ -826,31 +842,11 @@ int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,in /** environment */ if (sv->opts[2] && (exec->build == AUTO)) { - if (!stralloc_cats(&env,S6_BINPREFIX "s6-envdir ")) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&env,S6_BINPREFIX "66-envfile -f ")) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&env,name)) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&env," ")) retstralloc(0,"write_exec") ; if (!stralloc_cats(&env,envdata)) retstralloc(0,"write_exec") ; if (!stralloc_cats(&env,"\n")) retstralloc(0,"write_exec") ; - if (genalloc_len(diuint32,&sv->env)) - { - for (unsigned int i = 0 ; i < genalloc_len(diuint32,&sv->env) ; i++) - { - key = genalloc_s(diuint32,&sv->env)[i].left ; - if ((saenv.s+key)[0] == '!') - { - if (!stralloc_cats(&env,"importas -uD \"\" ")) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&env,saenv.s+1+key)) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&env," ")) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&env,saenv.s+1+key)) retstralloc(0,"write_exec") ; - } - else - { - if (!stralloc_cats(&env,"importas -D \"\" ")) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&env,saenv.s+key)) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&env," ")) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&env,saenv.s+key)) retstralloc(0,"write_exec") ; - } - if (!stralloc_cats(&env,"\n")) retstralloc(0,"write_exec") ; - } - } } /** shebang */ if (type != ONESHOT) @@ -990,14 +986,14 @@ int write_uint(char const *dst, char const *name, uint32_t ui) return 1 ; } -int write_env(genalloc *env,stralloc *sa,char const *dst) +int write_env(char const *name, genalloc *env,stralloc *sa,char const *dst) { int r ; - + stralloc tmp = STRALLOC_ZERO ; if (genalloc_len(diuint32,env)) { - unsigned int key = 0 ; - unsigned int val = 0 ; + char *key = 0 ; + char *val = 0 ; r = scan_mode(dst,S_IFDIR) ; if (r < 0) { @@ -1014,23 +1010,22 @@ int write_env(genalloc *env,stralloc *sa,char const *dst) } for (unsigned int i = 0 ; i < genalloc_len(diuint32,env) ; i++) { - key = genalloc_s(diuint32,env)[i].left ; - val = genalloc_s(diuint32,env)[i].right ; + key = sa->s + genalloc_s(diuint32,env)[i].left ; + val = sa->s + genalloc_s(diuint32,env)[i].right ; - if ((sa->s+key)[0] == '!') - key++ ; - /* if (dir_search(dst,sa->s+key,S_IFREG)) - { - VERBO3 strerr_warnw5x("file: ",dst,"/",sa->s+key," already exist, skip it") ; - continue ; - }*/ - if (!file_write_unsafe(dst,sa->s+key,sa->s+val,strlen(sa->s+val))) - { - VERBO3 strerr_warnwu4sys("create file: ",dst,"/",sa->s+key) ; - return 0 ; - } + if (!stralloc_cats(&tmp,key)) retstralloc(0,"write_env") ; + if (!stralloc_cats(&tmp,"=")) retstralloc(0,"write_env") ; + if (!stralloc_cats(&tmp,val)) retstralloc(0,"write_env") ; + if (!stralloc_cats(&tmp,"\n")) retstralloc(0,"write_env") ; } } + if (!file_write_unsafe(dst,name,tmp.s,tmp.len)) + { + VERBO3 strerr_warnwu4sys("create file: ",dst,"/",name) ; + return 0 ; + } + + stralloc_free(&tmp) ; return 1 ; } diff --git a/src/lib66/resolve.c b/src/lib66/resolve.c index e703c3e518f28d9dede45226addfe6a9fd27672f..12c7e490bc9e9c05b7a8518eafce7d9534999150 100644 --- a/src/lib66/resolve.c +++ b/src/lib66/resolve.c @@ -27,12 +27,13 @@ #include <skalibs/djbunix.h> #include <skalibs/direntry.h> #include <skalibs/unix-transactional.h> +#include <skalibs/diuint32.h> #include <66/constants.h> #include <66/utils.h> #include <66/enum.h> -#include <stdio.h> +//#include <stdio.h> /** @Return -2 on error * @Return -1 if resolve directory doesn't exist * @Return 0 is file doesn't exist @@ -349,11 +350,11 @@ int resolve_pointo(stralloc *sa,char const *base, char const *live,char const *t return stralloc_obreplace(sa,r) ; } -int resolve_src(genalloc *ga, stralloc *sasrc, char const *name, char const *src) +int resolve_src(genalloc *ga, stralloc *sasrc, char const *name, char const *src,unsigned int *found) { int fdsrc, obr, insta ; - sv_src_t svtmp = {0} ; + diuint32 svtmp = DIUINT32_ZERO ;//left->name,right->src size_t srclen = strlen(src) ; size_t namelen = strlen(name) ; @@ -393,7 +394,8 @@ int resolve_src(genalloc *ga, stralloc *sasrc, char const *name, char const *src { if (!stralloc_cats(&subdir,d->d_name)) goto errdir ; if (!stralloc_0(&subdir)) goto errdir ; - if (!resolve_src(ga,sasrc,name,subdir.s)) goto errdir ; + *found = 2 ; + if (!resolve_src(ga,sasrc,name,subdir.s,found)) goto errdir ; } obr = 0 ; insta = 0 ; @@ -405,14 +407,16 @@ int resolve_src(genalloc *ga, stralloc *sasrc, char const *name, char const *src if (!insta_splitname(&sainsta,name,insta,0)) goto errdir ; obr = obstr_equal(sainsta.s,d->d_name) ; } - + if (obr) { + *found = 1 ; if (stat_at(fdsrc, d->d_name, &st) < 0) { VERBO3 strerr_warnwu3sys("stat ", src, d->d_name) ; goto errdir ; } + if (S_ISDIR(st.st_mode)) { if (!stralloc_cats(&subdir,d->d_name)) goto errdir ; @@ -425,21 +429,21 @@ int resolve_src(genalloc *ga, stralloc *sasrc, char const *name, char const *src } for (unsigned int i = 0 ; i < genalloc_len(stralist,&tmp) ; i++) { - svtmp.name = sasrc->len ; + svtmp.left = sasrc->len ; if (!stralloc_catb(sasrc,gaistr(&tmp,i), gaistrlen(&tmp,i) + 1)) goto errdir ; - svtmp.src = sasrc->len ; + svtmp.right = sasrc->len ; if (!stralloc_catb(sasrc,subdir.s, subdir.len + 1)) goto errdir ; - if (!genalloc_append(sv_src_t,ga,&svtmp)) goto errdir ; + if (!genalloc_append(diuint32,ga,&svtmp)) goto errdir ; } break ; } else if(S_ISREG(st.st_mode)) { - svtmp.name = sasrc->len ; + svtmp.left = sasrc->len ; if (!stralloc_catb(sasrc,name, namelen + 1)) goto errdir ; - svtmp.src = sasrc->len ; + svtmp.right = sasrc->len ; if (!stralloc_catb(sasrc,src,srclen + 1)) goto errdir ; - if (!genalloc_append(sv_src_t,ga,&svtmp)) goto errdir ; + if (!genalloc_append(diuint32,ga,&svtmp)) goto errdir ; break ; } else goto errdir ; @@ -450,7 +454,14 @@ int resolve_src(genalloc *ga, stralloc *sasrc, char const *name, char const *src genalloc_deepfree(stralist,&tmp,stra_free) ; stralloc_free(&subdir) ; stralloc_free(&sainsta) ; - return 1 ; + + if (*found > 1) + { + *found = 0 ; + return 1 ; + } + + return (*found) ? 1 : 0 ; errdir: dir_close(dir) ; diff --git a/src/lib66/svc_init.c b/src/lib66/svc_init.c index d1d393fb89677cdc144a44efaeb84488560eff7e..f5c463c71d74ab461e405f4763a1861e7412763e 100644 --- a/src/lib66/svc_init.c +++ b/src/lib66/svc_init.c @@ -11,68 +11,137 @@ * This file may not be copied, modified, propagated, or distributed * except according to the terms contained in the LICENSE file./ */ - +#include <66/svc.h> -int svc_init(char const *scandir,char const *svsrc, char const *sv,ftrigr_t *fifo) +#include <string.h> +#include <stdlib.h> + +#include <oblibs/error2.h> +#include <oblibs/stralist.h> + +#include <skalibs/genalloc.h> +#include <skalibs/types.h> +#include <skalibs/tai.h> +#include <skalibs/djbunix.h> + +#include <s6/s6-supervise.h> +#include <s6/ftrigr.h> +#include <s6/ftrigw.h> + +#include <66/utils.h> + +int svc_init(char const *scandir,char const *src, genalloc *ga) { + int r ; gid_t gid = getgid() ; uint16_t id ; - size_t svlen = strlen(sv) ; - char s[svlen + 6 + 1] ; - memcpy(s,sv,svlen) ; - s[svlen] = 0 ; - VERBO3 strerr_warnt4x("copy: ",svsrc, " to ", s) ; - if (!hiercopy(svsrc, s)) - { - VERBO3 strerr_warnwu4sys("copy: ",svsrc," to: ",s) ; - return 0 ; - } - memcpy(s + svlen, "/down", 5) ; - s[svlen + 5] = 0 ; - - VERBO3 strerr_warnt2x("create file: ",s) ; - if (!touch(s)) - { - VERBO3 strerr_warnwu2sys("create file: ",s) ; - return 0 ; - } - memcpy(s + svlen, "/event", 6) ; - s[svlen + 6] = 0 ; - VERBO3 strerr_warnt2x("create fifo: ",s) ; - if (!ftrigw_fifodir_make(s, gid, 0)) - { - VERBO3 strerr_warnwu2sys("create fifo: ",s) ; - return 0 ; - } - VERBO3 strerr_warnt2x("subcribe to fifo: ",s) ; - /** unsubscribe automatically, options is 0 */ - id = ftrigr_subscribe_g(fifo, s, "s", 0, &DEADLINE) ; - if (!id) + ftrigr_t fifo = FTRIGR_ZERO ; + genalloc gadown = GENALLOC_ZERO ; + + tain_t deadline ; + tain_now_g() ; + tain_addsec(&deadline,&STAMP,2) ; + + VERBO3 strerr_warnt1x("iniate fifo: fifo") ; + if (!ftrigr_startf(&fifo, &deadline, &STAMP)) + return 0 ; + + for (unsigned int i=0 ; i < genalloc_len(svstat_t,ga); i++) { - VERBO3 strerr_warnwu2x("subcribe to fifo: ",s) ; - return 0 ; + char const *name = genalloc_s(svstat_t,ga)[i].name ; + size_t namelen = genalloc_s(svstat_t,ga)[i].namelen ; + + size_t srclen = strlen(src) ; + char svsrc[srclen + 1 + namelen + 1] ; + memcpy(svsrc,src,srclen) ; + svsrc[srclen] = '/' ; + memcpy(svsrc + srclen + 1, name,namelen) ; + svsrc[srclen + 1 + namelen] = 0 ; + + size_t svscanlen = strlen(scandir) ; + char svscan[svscanlen + 1 + namelen + 6 + 1] ; + memcpy(svscan,scandir,svscanlen) ; + svscan[svscanlen] = '/' ; + memcpy(svscan + svscanlen + 1, name,namelen) ; + svscanlen = svscanlen + 1 + namelen ; + svscan[svscanlen] = 0 ; + + VERBO3 strerr_warnt2x("init service: ", svscan) ; + + VERBO3 strerr_warnt4x("copy: ",svsrc, " to ", svscan) ; + if (!hiercopy(svsrc,svscan )) + { + VERBO3 strerr_warnwu4sys("copy: ",svsrc," to: ",svscan) ; + goto err ; + } + memcpy(svscan + svscanlen, "/down", 5) ; + svscan[svscanlen + 5] = 0 ; + + if (!genalloc_s(svstat_t,ga)[i].down) + { + if (!stra_add(&gadown,svscan)) + { + VERBO3 strerr_warnwu3x("add: ",svscan," to genalloc") ; + goto err ; + } + } + + VERBO3 strerr_warnt2x("create file: ",svscan) ; + if (!touch(svscan)) + { + VERBO3 strerr_warnwu2sys("create file: ",svscan) ; + goto err ; + } + memcpy(svscan + svscanlen, "/event", 6) ; + svscan[svscanlen + 6] = 0 ; + VERBO3 strerr_warnt2x("create fifo: ",svscan) ; + if (!ftrigw_fifodir_make(svscan, gid, 0)) + { + VERBO3 strerr_warnwu2sys("create fifo: ",svscan) ; + goto err ; + } + VERBO3 strerr_warnt2x("subcribe to fifo: ",svscan) ; + /** unsubscribe automatically, options is 0 */ + id = ftrigr_subscribe_g(&fifo, svscan, "s", 0, &deadline) ; + if (!id) + { + VERBO3 strerr_warnwu2x("subcribe to fifo: ",svscan) ; + goto err ; + } } - VERBO3 strerr_warnt2x("reload scandir: ",scandir) ; r = s6_svc_writectl(scandir, S6_SVSCAN_CTLDIR, "an", 2) ; if (r < 0) { VERBO3 strerr_warnw3sys("something is wrong with the ",scandir, "/" S6_SVSCAN_CTLDIR " directory. errno reported") ; - return -1 ; + goto err ; } if (!r) { - VERBO3 strerr_warnw3x("scandir: ",scandir, " is not running") ; - return -1 ; + VERBO3 strerr_warnw3x("scandir: ",scandir, " is not running, make a bug report") ; + goto err ; } - VERBO3 strerr_warnt2x("waiting for events on fifo: ",s) ; - if (ftrigr_wait_and_g(fifo, &id, 1, &DEADLINE) < 0) - return 0 ; - + VERBO3 strerr_warnt1x("waiting for events on fifo") ; + if (ftrigr_wait_and_g(&fifo, &id, 1, &deadline) < 0) + goto err ; + + for (unsigned int i = 0 ; i < genalloc_len(stralist,&gadown) ; i++) + { + VERBO3 strerr_warnt2x("delete down file for: ",genalloc_s(svstat_t,ga)[i].name) ; + if (unlink(gaistr(&gadown,i)) < 0 && errno != ENOENT) return 0 ; + } + + ftrigr_end(&fifo) ; + genalloc_deepfree(stralist,&gadown,stra_free) ; + return 1 ; + + err: + ftrigr_end(&fifo) ; + return 0 ; } diff --git a/src/lib66/svc_init_pipe.c b/src/lib66/svc_init_pipe.c new file mode 100644 index 0000000000000000000000000000000000000000..b09aed00b34a2c48e93389d72de3193087ff1f4b --- /dev/null +++ b/src/lib66/svc_init_pipe.c @@ -0,0 +1,88 @@ +/* + * svc_init_pipe.c + * + * Copyright (c) 2018 Eric Vidal <eric@obarun.org> + * + * All rights reserved. + * + * This file is part of Obarun. It is subject to the license terms in + * the LICENSE file found in the top-level directory of this + * distribution. + * This file may not be copied, modified, propagated, or distributed + * except according to the terms contained in the LICENSE file./ + */ + + +#include <66/svc.h> + +#include <oblibs/error2.h> + +#include <skalibs/genalloc.h> +#include <skalibs/stralloc.h> +#include <skalibs/tai.h> + +#include <s6/ftrigr.h> +#include <s6/ftrigw.h> +#include <s6/s6-supervise.h> + +#include <66/utils.h> + +int svc_init_pipe(ftrigr_t *fifo,genalloc *gasv,stralloc *sasv) +{ + tain_t ttmain ; + + tain_now_g() ; + tain_addsec(&ttmain,&STAMP,2) ; + + VERBO2 strerr_warni1x("initiate fifo: fifo") ; + if (!ftrigr_startf(fifo, &ttmain, &STAMP)) + VERBO3 { strerr_warnwu1sys("initiate fifo") ; return 0 ; } + + for (unsigned int i = 0 ; i < genalloc_len(svc_sig,gasv) ; i++) + { + svc_sig *svc = &genalloc_s(svc_sig,gasv)[i] ; + int r ; + size_t siglen = strlen(svc->sigtosend) ; + + size_t scanlen = svc->scanlen ; + char *svok = sasv->s + svc->scan ; + + char svfifo[scanlen + 6 + 1] ; + memcpy(svfifo, svok,scanlen) ; + memcpy(svfifo + scanlen, "/event",6) ; + svfifo[scanlen + 6] = 0 ; + + VERBO3 strerr_warnt2x("clean up fifo: ", svfifo) ; + if (!ftrigw_clean (svok)) + { + VERBO3 strerr_warnwu2sys("clean up fifo: ", svfifo) ; + return 0 ; + } + + VERBO3 strerr_warnt2x("subcribe to fifo: ",svfifo) ; + svc->ids = ftrigr_subscribe_g(fifo, svfifo, "[DuUdOxs]", FTRIGR_REPEAT, &ttmain) ; + if (!svc->ids) + { + VERBO3 strerr_warnwu2sys("subcribe to fifo: ",svfifo) ; + goto end ; + } + + VERBO3 strerr_warnt6x("send signal: ",svc->sigtosend," to: ", svok,"/",S6_SUPERVISE_CTLDIR) ; + r = s6_svc_writectl(svok, S6_SUPERVISE_CTLDIR, svc->sigtosend, siglen) ; + if (r < 0) + { + VERBO3 strerr_warnwu3sys("something is wrong with the ",svok, "/" S6_SUPERVISE_CTLDIR " directory. errno reported") ; + goto end ; + } + if (!r) + { + VERBO3 strerr_warnw3x("sv: ",svok, " is not supervised") ; + goto end ; + } + } + + return 1 ; + + end: + return 0 ; +} diff --git a/src/lib66/tree_cmd_switcher.c b/src/lib66/tree_cmd_switcher.c deleted file mode 100644 index 455073b753f2703861e31321e1aa7cd81d987686..0000000000000000000000000000000000000000 --- a/src/lib66/tree_cmd_switcher.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * tree_cmd_switcher.c - * - * Copyright (c) 2018 Eric Vidal <eric@obarun.org> - * - * All rights reserved. - * - * This file is part of Obarun. It is subject to the license terms in - * the LICENSE file found in the top-level directory of this - * distribution. - * This file may not be copied, modified, propagated, or distributed - * except according to the terms contained in the LICENSE file./ - */ - -#include <errno.h> -#include <string.h> -#include <sys/stat.h> - -#include <oblibs/obgetopt.h> -#include <oblibs/error2.h> -#include <oblibs/string.h> -#include <oblibs/types.h> -#include <oblibs/stralist.h> - -#include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> -#include <skalibs/types.h> -#include <skalibs/djbunix.h> - - -#include <66/utils.h> -#include <66/constants.h> - -//USAGE "tree_switcher [ -v verbosity ] [ -b backup ] [ -s switch ] tree" -// if -b return 0 if point to original source, return 1 if point to backup -// -s , 0 mean original source, 1 mean backup -int tree_switcher(int argc, char const *const *argv) -{ - unsigned int r, change, back, verbosity ; - uint32_t what = -1 ; - - struct stat st ; - - char const *tree = NULL ; - - uid_t owner = MYUID ; - - stralloc base = STRALLOC_ZERO ; - - verbosity = 1 ; - - change = back = 0 ; - - { - subgetopt_t l = SUBGETOPT_ZERO ; - - for (;;) - { - int opt = getopt_args(argc,argv, "v:s:b", &l) ; - if (opt == -1) break ; - if (opt == -2){ strerr_warnw1x("options must be set first") ; return -1 ; } - switch (opt) - { - case 'v' : if (!uint0_scan(l.arg, &verbosity)) return -1 ; break ; - case 's' : change = 1 ; if (!uint0_scan(l.arg, &what)) return -1 ; break ; - case 'b' : back = 1 ; break ; - default : return -1 ; - } - } - argc -= l.ind ; argv += l.ind ; - } - - if (argc < 1) return -1 ; - if (!change && !back) return -1 ; - - tree = *argv ; - size_t treelen = strlen(tree) ; - - if (!set_ownersysdir(&base,owner)) - { - VERBO3 strerr_warnwu1sys("set owner directory") ; - return -1 ; - } - /** $HOME/66/system/tree/servicedirs */ - base.len-- ; - size_t symlen ; - char sym[base.len + SS_SYSTEM_LEN + 1 + treelen + SS_SVDIRS_LEN + 1 + SS_TREE_CURRENT_LEN + 1] ; - memcpy(sym,base.s,base.len) ; - memcpy(sym + base.len, SS_SYSTEM,SS_SYSTEM_LEN) ; - memcpy(sym + base.len + SS_SYSTEM_LEN, "/", 1) ; - memcpy(sym + base.len + SS_SYSTEM_LEN + 1, tree, treelen) ; - memcpy(sym + base.len + SS_SYSTEM_LEN + 1 + treelen, SS_SVDIRS, SS_SVDIRS_LEN) ; - memcpy(sym + base.len + SS_SYSTEM_LEN + 1 + treelen + SS_SVDIRS_LEN, "/", 1) ; - memcpy(sym + base.len + SS_SYSTEM_LEN + 1 + treelen + SS_SVDIRS_LEN + 1, SS_TREE_CURRENT, SS_TREE_CURRENT_LEN) ; - symlen = base.len + SS_SYSTEM_LEN + 1 + treelen + SS_SVDIRS_LEN + 1 + SS_TREE_CURRENT_LEN ; - sym[symlen] = 0 ; - - if (back) - { - if(lstat(sym,&st) < 0) return -1 ; - if(!(S_ISLNK(st.st_mode))) - { - VERBO3 strerr_warnwu2x("find symlink: ",sym) ; - return -1 ; - } - stralloc symreal = STRALLOC_ZERO ; - - r = sarealpath(&symreal,sym) ; - if (r < 0) - { - VERBO3 strerr_warnwu2sys("retrieve real path from: ",sym) ; - return -1 ; - } - char *b = NULL ; - b = memmem(symreal.s,symreal.len,SS_BACKUP,SS_BACKUP_LEN) ; - - stralloc_free(&symreal) ; - - if (!b) return 0 ; - - return 1 ; - } - - if (change) - { - char dstori[base.len + SS_SYSTEM_LEN + 1 + treelen + SS_SVDIRS_LEN + 1] ; - char dstback[base.len + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + treelen + SS_SVDIRS_LEN + 1] ; - - memcpy(dstori, base.s, base.len) ; - memcpy(dstori + base.len, SS_SYSTEM, SS_SYSTEM_LEN) ; - memcpy(dstori + base.len + SS_SYSTEM_LEN, "/", 1) ; - memcpy(dstori + base.len + SS_SYSTEM_LEN + 1, tree, treelen) ; - memcpy(dstori + base.len + SS_SYSTEM_LEN + 1 + treelen, SS_SVDIRS, SS_SVDIRS_LEN) ; - dstori[base.len + SS_SYSTEM_LEN + 1 + treelen + SS_SVDIRS_LEN] = 0 ; - - memcpy(dstback, base.s, base.len) ; - memcpy(dstback + base.len, SS_SYSTEM, SS_SYSTEM_LEN) ; - memcpy(dstback + base.len + SS_SYSTEM_LEN, SS_BACKUP, strlen(SS_BACKUP)) ; - memcpy(dstback + base.len + SS_SYSTEM_LEN + SS_BACKUP_LEN, "/", 1) ; - memcpy(dstback + base.len + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1, tree, treelen) ; - memcpy(dstback + base.len + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + treelen, SS_SVDIRS, SS_SVDIRS_LEN) ; - dstback[base.len + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + treelen + SS_SVDIRS_LEN] = 0 ; - - if (what >= 0) - { - if (unlink(sym) < 0) - { - VERBO3 strerr_warnwu2sys("remove symlink: ", sym) ; - return -1 ; - } - } - - if (what) - { - - if (symlink(dstback,sym) < 0) - { - VERBO3 strerr_warnwu2sys("symlink: ", dstback) ; - return -1 ; - } - } - if (!what) - { - if (symlink(dstori,sym) < 0) - { - VERBO3 strerr_warnwu2sys("symlink: ", dstori) ; - return -1 ; - } - } - } - - stralloc_free(&base) ; - - return 1 ; -} - -int tree_cmd_switcher(unsigned int verbosity,char const *cmd, char const *tree) -{ - int r ; - - genalloc opts = GENALLOC_ZERO ; - - if (!clean_val(&opts,cmd)) - { - VERBO3 strerr_warnwu2x("clean: ",cmd) ; - return -1 ; - } - int newopts = 5 + genalloc_len(stralist,&opts) ; - char const *newargv[newopts] ; - unsigned int m = 0 ; - char fmt[UINT_FMT] ; - fmt[uint_fmt(fmt, verbosity)] = 0 ; - - newargv[m++] = "tree_switcher" ; - newargv[m++] = "-v" ; - newargv[m++] = fmt ; - - for (unsigned int i = 0; i < genalloc_len(stralist,&opts); i++) - newargv[m++] = gaistr(&opts,i) ; - - newargv[m++] = tree ; - newargv[m++] = 0 ; - - r = tree_switcher(newopts,newargv) ; - - genalloc_deepfree(stralist,&opts,stra_free) ; - - return r ; -} diff --git a/src/lib66/tree_from_current.c b/src/lib66/tree_from_current.c deleted file mode 100644 index bb62eb60393a53862a7f67d305f30dd4a62cfd1a..0000000000000000000000000000000000000000 --- a/src/lib66/tree_from_current.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * tree_from_current.c - * - * Copyright (c) 2018 Eric Vidal <eric@obarun.org> - * - * All rights reserved. - * - * This file is part of Obarun. It is subject to the license terms in - * the LICENSE file found in the top-level directory of this - * distribution. - * This file may not be copied, modified, propagated, or distributed - * except according to the terms contained in the LICENSE file./ - */ - -#include <66/utils.h> - -#include <sys/stat.h> - -#include <oblibs/error2.h> - -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> - -#include <66/constants.h> - -int tree_from_current(stralloc *sa, char const *tree) -{ - int r ; - size_t treelen = strlen(tree) ; - - struct stat st ; - - char current[treelen + SS_SVDIRS_LEN + 1 + SS_TREE_CURRENT_LEN + 1] ; - memcpy(current, tree, treelen) ; - memcpy(current + treelen, SS_SVDIRS, SS_SVDIRS_LEN) ; - memcpy(current + treelen + SS_SVDIRS_LEN, "/", 1) ; - memcpy(current + treelen + SS_SVDIRS_LEN + 1, SS_TREE_CURRENT, SS_TREE_CURRENT_LEN) ; - current[treelen + SS_SVDIRS_LEN + 1 + SS_TREE_CURRENT_LEN] = 0 ; - - if(lstat(current,&st) < 0) return 0 ; - if(!(S_ISLNK(st.st_mode))) - { - VERBO3 strerr_warnwu2x("find symlink: ",current) ; - return 0 ; - } - r = sarealpath(sa,current) ; - if (r < 0 ) - { - VERBO3 strerr_warnwu2x("find real path: ",current) ; - return 0 ; - } - if (!stralloc_0(sa)) retstralloc(0,"find_current_state") ; - - return 1 ; -} diff --git a/src/lib66/tree_make_backup.c b/src/lib66/tree_make_backup.c deleted file mode 100644 index 3d650d0ad33bd2131aa68541f60040a7f141be97..0000000000000000000000000000000000000000 --- a/src/lib66/tree_make_backup.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * tree_make_backup.c - * - * Copyright (c) 2018 Eric Vidal <eric@obarun.org> - * - * All rights reserved. - * - * This file is part of Obarun. It is subject to the license terms in - * the LICENSE file found in the top-level directory of this - * distribution. - * This file may not be copied, modified, propagated, or distributed - * except according to the terms contained in the LICENSE file./ - */ - -#include <66/tree.h> -#include <66/db.h> - -#include <sys/stat.h> - -#include <oblibs/error2.h> -#include <oblibs/types.h> -#include <oblibs/directory.h> - -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> - -#include <66/constants.h> -#include <66/utils.h> - -int tree_make_backup(char const *base, char const *tree, char const *treename) -{ - int r ; - - size_t baselen = strlen(base) - 1 ;//remove the last slash - size_t treenamelen = strlen(treename) ; - - char treetmp[baselen + 1 + SS_SYSTEM_LEN + SS_BACKUP_LEN + treenamelen + 1 + 1] ; - memcpy(treetmp, base, baselen) ; - memcpy(treetmp + baselen, "/", 1) ; - memcpy(treetmp + baselen + 1, SS_SYSTEM, SS_SYSTEM_LEN) ; - memcpy(treetmp + baselen + 1 + SS_SYSTEM_LEN, SS_BACKUP, SS_BACKUP_LEN) ; - memcpy(treetmp + baselen + 1 + SS_SYSTEM_LEN + SS_BACKUP_LEN, "/", 1) ; - memcpy(treetmp + baselen + 1 + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1, treename, treenamelen) ; - treetmp[baselen + 1 + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + treenamelen ] = 0 ; - - r = scan_mode(treetmp,S_IFDIR) ; - if (r || (r < 0)) - { - if (rm_rf(treetmp) < 0) - { - VERBO3 strerr_warnwu2sys("remove: ",treetmp) ; - return 0 ; - } - } - if (!r) - { - if (!dir_create(treetmp,0755)) - { - VERBO3 strerr_warnwu2sys("create directory: ",treetmp) ; - return 0 ; - } - } - if (!hiercopy(tree, treetmp)) - { - VERBO3 strerr_warnwu4sys("copy: ",tree," to ",treetmp) ; - return 0 ; - } - - return 1 ; -} diff --git a/src/lib66/tree_switch_tobackup.c b/src/lib66/tree_switch_tobackup.c deleted file mode 100644 index c2c041cc4b9862467910b35a633415915f6841a2..0000000000000000000000000000000000000000 --- a/src/lib66/tree_switch_tobackup.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * tree_switch_tobackup.c - * - * Copyright (c) 2018 Eric Vidal <eric@obarun.org> - * - * All rights reserved. - * - * This file is part of Obarun. It is subject to the license terms in - * the LICENSE file found in the top-level directory of this - * distribution. - * This file may not be copied, modified, propagated, or distributed - * except according to the terms contained in the LICENSE file./ - */ - -#include <66/tree.h> -#include <66/db.h> - -#include <sys/stat.h> - -#include <oblibs/error2.h> -#include <oblibs/types.h> - -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> - -#include <66/constants.h> -#include <66/utils.h> - -int tree_switch_tobackup(char const *base, char const *treename, char const *tree, char const *livetree,char const *const *envp) -{ - int r ; - - size_t baselen = strlen(base) - 1 ;//remove the last slash - size_t treenamelen = strlen(treename) ; - - r = tree_cmd_switcher(VERBOSITY,"-b",treename) ; - /** !r we are on original source, we need to switch - * to backup */ - if (r < 0) - { - VERBO3 strerr_warnwu2x("read symlink in: ", treename) ; - return 0 ; - } - if (!r) - { - char treetmp[baselen + 1 + SS_SYSTEM_LEN + SS_BACKUP_LEN + treenamelen + 1 + 1] ; - memcpy(treetmp, base, baselen) ; - memcpy(treetmp + baselen, "/", 1) ; - memcpy(treetmp + baselen + 1, SS_SYSTEM, SS_SYSTEM_LEN) ; - memcpy(treetmp + baselen + 1 + SS_SYSTEM_LEN, SS_BACKUP, SS_BACKUP_LEN) ; - memcpy(treetmp + baselen + 1 + SS_SYSTEM_LEN + SS_BACKUP_LEN, "/", 1) ; - memcpy(treetmp + baselen + 1 + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1, treename, treenamelen) ; - treetmp[baselen + 1 + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + treenamelen ] = 0 ; - - r = scan_mode(treetmp,S_IFDIR) ; - if (r || (r < 0)) - { - if (rm_rf(treetmp) < 0) - { - VERBO3 strerr_warnwu2sys("remove: ",treetmp) ; - return 0 ; - } - } - if (!hiercopy(tree, treetmp)) - { - VERBO3 strerr_warnwu4sys("copy: ",tree," to ",treetmp) ; - return 0 ; - } - r = tree_cmd_switcher(VERBOSITY,"-s1",treename) ; - if (r != 1) - { - rm_rf(treetmp) ; - VERBO3 strerr_warnwu3x("switch: ",treename," to backup directory") ; - return 0 ; - } - - stralloc tmp = STRALLOC_ZERO ; - - if (!tree_from_current(&tmp,tree)) - { - rm_rf(treetmp) ; - VERBO3 strerr_warnwu2x("find current state of tree: ", treename) ; - return 0 ; - } - /** only pass through here if the db is currently in use*/ - if ((db_find_compiled_state(livetree,treename) >= 0)) - { - if (!db_update(tmp.s, treename,livetree,envp)) - { - rm_rf(treetmp) ; - VERBO3 strerr_warnwu6x("update db: ",treename," to ",tmp.s,"/compiled/",treename) ; - return 0 ; - } - } - stralloc_free(&tmp) ; - } - - return 1 ; -}