diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a63e558466eea542545c8285a10edb1b56e20ad5..480889d641ceb31166570779fe7e878305e9cd27 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,5 +14,8 @@ build: - make -j9 man - make -j9 install DESTDIR=gitlab-ci - make -j9 install-man DESTDIR=gitlab-ci - + + only: + refs: + - master diff --git a/INSTALL b/INSTALL index 079717bd1c553d4c3444c647e84a9498da94f38a..27c09c24d47c419f469547b73023ba47f219ff3c 100644 --- a/INSTALL +++ b/INSTALL @@ -10,7 +10,7 @@ Build Instructions - execline version 2.5.1.0 or later: http://skarnet.org/software/execline/ - s6 version 2.8.0.1 or later: http://skarnet.org/software/s6/ - s6-rc version 0.5.0.0 or later: http://skarnet.org/software/s6-rc/ - - oblibs version 0.0.1.3 or later: https://framagit.org/Obarun/oblibs/ + - oblibs version 0.0.2.0 or later: https://framagit.org/Obarun/oblibs/ - scdoc version 1.9.4 or later for man pages: https://git.sr.ht/~sircmpwn/scdoc This software will run on any operating system that implements diff --git a/Makefile b/Makefile index 2a56436ac0317c44a03a9ef7c22ada23ebf97a60..f0f7beb6bf0a9c25febd89c8fe766fd27c90d375 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ INSTALL_DATA += init.conf INSTALL_MAN := $(wildcard doc/man/*.[1-8]) INSTALL_HTML := $(wildcard doc/html/*.html) INSTALL_DATA := skel/halt skel/init skel/ishell skel/poweroff skel/rc.init \ - skel/rc.shutdown skel/reboot skel/shutdown + skel/rc.shutdown skel/reboot skel/shutdown skel/rc.shutdown.final INSTALL_CONF := skel/init.conf all: $(ALL_LIBS) $(ALL_BINS) $(ALL_INCLUDES) diff --git a/configure b/configure index f11dccb31c85a41e84b8376cf42a1bfaf84dc530..2296f327c1bfafbdcd6402d3c3ddb91788f3beff 100755 --- a/configure +++ b/configure @@ -30,18 +30,19 @@ Fine tuning of the installation directories: --shebangdir=DIR absolute path for execline #\! invocations [BINDIR] --livedir=DIR default live directory [/run/66] --with-skeleton=DIR skeleton files directory installation [SYSDIR/66] - --with-system-log=DIR system service log directory[/var/log/66] - - --with-system-dir=DIR 66 tools system working directory[/var/lib/66] - --with-system-service=DIR system service frontend directory[DATAROOTDIR/66/service] + --with-system-log=DIR system service log directory [/var/log/66] + --with-s6-log-user=USER user for running s6-log program [root] + + --with-system-dir=DIR 66 tools system working directory [/var/lib/66] + --with-system-service=DIR system service frontend directory [DATAROOTDIR/66/service] - --with-sysadmin-service=DIR sysadmin service frontend directory[SYSDIR/66/service] - --with-sysadmin-service-conf=DIR sysadmin service configuration file directory[SYSDIR/66/conf] + --with-sysadmin-service=DIR sysadmin service frontend directory [SYSDIR/66/service] + --with-sysadmin-service-conf=DIR sysadmin service configuration file directory [SYSDIR/66/conf] - --with-user-dir=DIR 66 tools user working directory[.66] - --with-user-log=DIR user service log directory[.66/log] - --with-user-service=DIR user service directory[.66/service] - --with-user-service-conf=DIR user service configuration directory[.66/conf] + --with-user-dir=DIR 66 tools user working directory [.66] + --with-user-log=DIR user service log directory [.66/log] + --with-user-service=DIR user service directory [.66/service] + --with-user-service-conf=DIR user service configuration directory [.66/conf] Do not set an absolute path but a \$HOME relative path for --with-user-dir, --with-user-log, --with-user-service, --with-user-service-conf. The \$HOME prefix @@ -169,6 +170,7 @@ livedir='/run/66' skel='$sysconfdir/66' system_dir='/var/lib/66' system_log='/var/log/66' +s6log_user='root' service_system='$datarootdir/66/service' service_adm='$sysconfdir/66/service' service_admconf='$sysconfdir/66/conf' @@ -214,6 +216,7 @@ for arg ; do --with-skeleton=*) skel=${arg#*=} ;; --with-system-dir=*) system_dir=${arg#*=} ;; --with-system-log=*) system_log=${arg#*=} ;; + --with-s6-log-user=*) s6log_user=${arg#*=} ;; --with-system-service=*) service_system=${arg#*=} ;; --with-sysadmin-service=*) service_adm=${arg#*=} ;; --with-sysadmin-service-conf=*) service_admconf=${arg#*=} ;; @@ -365,6 +368,7 @@ if test -n "$target" && test x${build} != x${target} ; then else cross= fi + echo "Checking for C compiler..." trycc ${CC} if test -n "$CC_AUTO" ; then @@ -503,6 +507,7 @@ livedir := $livedir skel := $skel system_dir := $system_dir system_log := $system_log +s6log_user := $s6log_user service_system := $service_system service_adm := $service_adm service_admconf := $service_admconf @@ -581,6 +586,7 @@ All rights reserved.*/ #define ${package_macro_name}_SYSTEM_DIR "$system_dir/" #define ${package_macro_name}_SKEL_DIR "$sysconfdir/66/" #define ${package_macro_name}_LOGGER_SYSDIR "$system_log/" +#define ${package_macro_name}_LOGGER_RUNNER "$s6log_user" #define ${package_macro_name}_SERVICE_SYSDIR "$service_system/" #define ${package_macro_name}_SERVICE_ADMDIR "$service_adm/" #define ${package_macro_name}_SERVICE_ADMCONFDIR "$service_admconf/" diff --git a/doc/html/66-envfile.html b/doc/html/66-envfile.html deleted file mode 100644 index fc22f81e18c6765e7b61787e7896d660bad5ccf1..0000000000000000000000000000000000000000 --- a/doc/html/66-envfile.html +++ /dev/null @@ -1,24 +0,0 @@ -<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-envfile</title> - <meta name="Description" content="Detailed documentation for the 66-envfile command which is part of the 66 software suite" /> - <meta name="Keywords" content="66 command 66-envfile service supervision execute script execline environment importas" /> - <!-- <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-envfile</h1> - - <p> - <strong>Deprecated</strong>. See <a href="execl-envfile.html">execl-envfile</a> instead. - </p> -</body> -</html> diff --git a/doc/html/66-getenv.html b/doc/html/66-getenv.html deleted file mode 100644 index 86110f4e732bb65ee63f08b453b50bdef8c17b94..0000000000000000000000000000000000000000 --- a/doc/html/66-getenv.html +++ /dev/null @@ -1,58 +0,0 @@ -<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-getenv</title> - <meta name="Description" content="Detailed documentation for the 66-getenv command which is part of the 66 software suite" /> - <meta name="Keywords" content="66 command 66-getenv service supervision execute script execline environment write" /> - <!-- <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-getenv</h1> - - <p> - 66-getenv gets and displays the environment variables of a process name. - </p> - - -<h2> Interface </h2> - <pre> - 66-getenv [ -h ] [ -x ] [ -d <em>delim</em> ] <em>process</em> - </pre> - - <ul> - <li> - 66-getenv find the corresponding pid of the <em>process</em> name applying a regex search. - </li> - <li> - It open and read <tt>/proc/<pid>/environ</tt> file and displays its contain. - </li> - <li>Return 0 on success and 111 on fail.</li> - </ul> - -<h2> Options </h2> - - <ul> - <li> <tt>-h </tt> : prints this help. </li> - <li> - <tt>-x </tt>: match exactly with the process name. It can be a complete command line, in such case its must be double-quoted. - </li> - <li> - <tt>-d <em>delim</em> </tt> : specify output delimiter. The default is <tt>'\n'</tt> character. - </li> - </ul> -<h2>Example of use</h2> -<p>66-getenv -x jwm</p> -<p>66-getenv "ck-launch-session jwm"</p> -<h2>Notes</h2> -<p> The file <tt>/proc/<pid>/environ</tt> contains the initial environment that was set when the currently executing program was started via <tt>execve(2)</tt>. If, after an <tt>execve(2)</tt>, the process modifies its environment -(e.g., by calling functions such as <tt>putenv(3)</tt> or modifying the <tt>environ(7)</tt> variable directly), this file will <strong>not</strong> reflect those changes—see <tt>proc(5)</tt> for futher informations.</p> -</body> -</html> diff --git a/doc/html/66-gnwenv.html b/doc/html/66-gnwenv.html deleted file mode 100644 index 310f8b9b26643d69626a6e4d23daf68448df350c..0000000000000000000000000000000000000000 --- a/doc/html/66-gnwenv.html +++ /dev/null @@ -1,51 +0,0 @@ -<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-gnwenv</title> - <meta name="Description" content="Detailed documentation for the 66-gnwenv command which is part of the 66 software suite" /> - <meta name="Keywords" content="66 command 66-gnwenv service supervision execute script execline environment write" /> - <!-- <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-gnwenv</h1> - - <p> - 66-gnwenv gets and writes the environment variables of a process name at a specific file location. - </p> - - -<h2> Interface </h2> - <pre> - 66-gnwenv [ -h ] [ -x ] [ -m <em>mode</em> ] <em>process</em> <em>dir</em> <em>file</em> - </pre> - - <ul> - <li> - 66-gnwenv executes into <tt><a href="66-getenv.html">66-getenv</a> -x process</tt> <tt><a href="66-writenv.html">66-writenv</a> -m mode dir file</tt>. It does nothing else: it is just a convenience program. - <a href="66-getenv.html">66-getenv</a> read the environment variable of the <em>process</em>, and <a href="66-writenv.html">66-writenv</a> will write these variables into <em>dir/file</em> location. - </li> - - <li>Return 0 on success and 111 on fail.</li> - </ul> - -<h2> Options </h2> - - <ul> - <li> <tt>-h </tt> : prints this help. </li> - <li> - <tt>-x </tt>: match exactly with the process name. It can be a complete command line, in such case its must be double-quoted. - </li> - <li> - <tt>-m <em>mode</em> </tt> : create <em>dir</em> with mode <em>mode</em> if it doesn't exist yet. Default is 0755. - </li> - </ul> -</body> -</html> diff --git a/doc/html/66-which.html b/doc/html/66-which.html deleted file mode 100644 index eec1b78d1c406c782101bb70adb3ef146001b8b1..0000000000000000000000000000000000000000 --- a/doc/html/66-which.html +++ /dev/null @@ -1,140 +0,0 @@ -<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-envfile</title> - <meta name="Description" content="Detailed documentation for the execl-envfile command which is part of the 66 software suite" /> - <meta name="Keywords" content="66 command execl-envfile service supervision execute script execline environment importas" /> - <!-- <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-which</h1> - - <p> - 66-which is a portable which command that checks if a command exists - and is executable in PATH or at specified path. It behaves slightly - different then the GNU which command. - </p> - -<h2>Interface</h2> - - <pre> - 66-which [ -h ] [ -q | -a ] <em>command(s)</em> - </pre> - - <p> - This tool expect to find valid command name or path, it will check - if they exists and are executable by the current user. - </p> - - <ul> - <li> - It parse PATH for valid entries, applying a substitution of each - entry with its realpath and emilinating duplicates. - </li> - - <li> - It parses that command given checking if it is a path or a name. - </li> - - <li> - It prints each command found with the first PATH entry, otherwise - it print an error. By passing the <tt>-a</tt> option, it - searches and print command with all the PATH entries, even if it - been already found. - </li> - -<h2>Options</h2> - - <ul> - <li> - <tt><b>-h</b></tt> : print this help. - </li> - - <li> - <tt><b>-a</b></tt> : print all. Search and print the command using - all the PATH entries, even after the command has already been - found. - </li> - - <li> - <tt><b>-q</b></tt> : quiet. Do not print anything on stdout. - </li> - </ul> - -<h2>Exit codes</h2> - - <p> - <ul> - <li> - <tt><b> 0</b></tt> : success; all the commands have - been found on the system - </li> - - <li> - <tt><b>110</b></tt> : bad usage - </li> - - <li> - <tt><b>111</b></tt> : system call failed or at least one - command hasn't been found. - </li> - </ul> - </p> - -<h2>Example of use</h2> - - <p> - Search for a command by using its name: - </p> - - <pre> - $ 66-which 66-echo - /usr/bin/66-echo - </pre> - - <p> - Check for a command by using its path: - </p> - - <pre> - $ 66-which /usr/bin/66-echo - /usr/bin/66-echo - </pre> - - <p> - Usage of <em>66-which</em> in a script: - </p> - - <pre> - #!/usr/bin/execlineb -P - - if { 66-which -q vgchange } - vgchange -ay - </pre> - -<h2>Notes</h2> - - <p> - 66-which need at least one valid entry in PATH that exists on the - system. 66-which is often used on critical scripts, like the ones - booting the system, so it's important to check if PATH contains valid - entries for the current system. - </p> - - <p> - 66-which correctly handle the tilde <em>~</em> character for paths. - Beware that same shell, like bash, replaces this character with the - current user home path. To pass the correct string to 66-which, - containing the tilde character, use quoting like this: <tt>66-which - '~/.bin/gvr'</tt>. - -</body> -</html> diff --git a/doc/html/66-writenv.html b/doc/html/66-writenv.html deleted file mode 100644 index acc352d1e69566af394794756df2df5f8c665690..0000000000000000000000000000000000000000 --- a/doc/html/66-writenv.html +++ /dev/null @@ -1,47 +0,0 @@ -<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-writenv</title> - <meta name="Description" content="Detailed documentation for the 66-writenv command which is part of the 66 software suite" /> - <meta name="Keywords" content="66 command 66-writenv service supervision execute script execline environment write" /> - <!-- <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-writenv</h1> - - <p> - 66-writenv stores its environment variables at a specific file location. - </p> - - -<h2> Interface </h2> - <pre> - 66-writenv [ -h ] [ -m <em>mode</em> ] <em>dir</em> <em>file</em> - </pre> - - <ul> - <li> - This tool write its environment variables into <em>dir/file</em> under the classic format <tt>key=value</tt> pair and thoses one per line. <em>dir</em> must be an absolute path. - </li> - <li>Return 0 on success and 111 on fail.</li> - </ul> - - -<h2> Options </h2> - - <ul> - <li> <tt>-h </tt> : prints this help. </li> - <li> - <tt>-m <em>mode</em> </tt> : create <em>dir</em> with mode <em>mode</em> if it doesn't exist yet. Default is 0755. - </li> - </ul> -</body> -</html> diff --git a/doc/html/execl-cmdline.html b/doc/html/execl-cmdline.html deleted file mode 100644 index 6ec4ef3ffced3108b6c77fff1c03913ae14bd706..0000000000000000000000000000000000000000 --- a/doc/html/execl-cmdline.html +++ /dev/null @@ -1,83 +0,0 @@ -<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="https://www.skarnet.org/software/execline/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/html/execl-envfile.html b/doc/html/execl-envfile.html deleted file mode 100644 index 03bbb228b88d8aabaf7391a2d6e323bdb2bb0655..0000000000000000000000000000000000000000 --- a/doc/html/execl-envfile.html +++ /dev/null @@ -1,127 +0,0 @@ -<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-envfile</title> - <meta name="Description" content="Detailed documentation for the execl-envfile command which is part of the 66 software suite" /> - <meta name="Keywords" content="66 command execl-envfile service supervision execute script execline environment importas" /> - <!-- <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-envfile</h1> - - <p> - A mix of <a href="https://skarnet.org/software/s6/s6-envdir.html"><tt>s6-envdir</tt></a> and <a href="https://skarnet.org/software/execline/importas.html"><tt>importas</tt></a>. Reads files containing variable assignments in the given file/directory, adds the variables to the environment and then executes a program. - </p> - -<h2>Interface</h2> - - <pre> - execl-envfile [ -h ] [ -f <em>file</em> ] [ -l ] <em>src</em> <em>prog</em> - </pre> - - <p> - This tool expects to find a regular file or a directory in <em>src</em> containing one or multiple <tt>key=value</tt> pair(s). It will parse that file, import the <tt>key=value</tt> and then exec the given <em>prog</em> with the modified environment. In case of directory for each file found it apply the same process. - </p> - - <ul> - <li> - It opens and reads a file. - </li> - - <li> - It parses that file. - </li> - - <li> - It imports the found <tt>key=value</tt> pair(s). - </li> - - <li> - It substitutes each corresponding <tt>key</tt> with <tt>value</tt> from that file. - </li> - - <li> - It unexports the variable(s) if requested. - </li> - - <li> - It execs <em>prog</em> with the modified environment. - </li> - </ul> - -<h2>Options</h2> - - <ul> - <li> - <tt><b>-h</b></tt> : print this help. - </li> - - <li> - <tt><b>-f <em>file</em></b></tt> : only parse <em>file</em> found in <em>src</em>. <b>deprecated option</b> - </li> - - <li> - <tt><b>-l</b></tt> : loose; do nothing and execute <em>prog</em> directly if <em>src</em> does not contain any regular file(s) or <em>src</em> does not exist. - </li> - </ul> - -<h2>File syntax</h2> - - <p> - <em>src</em> is a text file or a directory containing lines of pairs with the syntax being:<br><tt>key = value</tt><br>Whitespace is permitted before and after <em>key</em>, and before or after <em>value</em>. Quoting is also possible. - </p> - - <p> - Empty lines or lines containing only whitespace are ignored. Lines beginning with <tt>#</tt> (also after whitespace) are ignored and typically used for comments. Comments are <strong>not</strong> possible at the end of lines: '<tt>key = value # comment</tt>' is not a valid comment. - </p> - - <p> - Empty <em>values</em> are <strong>not</strong> permitted. - </p> - - <p> - If <tt>val</tt> begin by a <tt>'!'</tt> character: <tt>key=!value</tt> the <tt>key</tt> will be removed from the environment after the substitution. - </p> - -<h2>Example of use</h2> - - <pre> - #!/usr/bin/execlineb -P - fdmove -c 2 1 - execl-envfile /etc/66/conf/ntpd - foreground { mkdir -p -m 0755 ${RUNDIR} } - execl-cmdline -s { ntpd ${CMD_ARGS} } - </pre> - - <p>The equivalent with s6-envdir and importas would be:</p> - - <pre> - #!/usr/bin/execlineb -P - fdmove -c 2 1 - s6-envdir %%service_admconf%% - importas -u RUNDIR RUNDIR - importas -u CMD_ARGS CMD_ARGS - foreground { mkdir -p -m 0755 ${RUNDIR} } - execl-cmdline -s { ntpd ${CMD_ARGS} } - </pre> - - <p> - where <tt>%%service_admconf%%</tt> contains two named files <tt>RUNDIR</tt> and <tt>CMD_ARGS</tt> written with <tt>/run/openntpd</tt> and <tt>-d -s</tt> respectively. - </p> - -<h2>Limits</h2> - - <p> - <em>src</em> can not exceed more than 100 files. Each file can not contain more than 4095 bytes or more than 50 <em>key=value</em> pairs. - </p> - -</body> -</html> diff --git a/doc/html/execl-subuidgid.html b/doc/html/execl-subuidgid.html deleted file mode 100644 index 89071251295224a34c944b901eb8e91a93b1490a..0000000000000000000000000000000000000000 --- a/doc/html/execl-subuidgid.html +++ /dev/null @@ -1,60 +0,0 @@ -<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-subuidgid</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-subuidgid service supervision execute script execline uid gid substitute" /> - <!-- <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-subuidgid</h1> - - <p> - Substitutes a literal GID UID with the UID GID of the current owner of the process. - </p> - - -<h2>Interface</h2> - - <pre> - execl-subuidgid [ -o owner ] <em>prog</em> - </pre> - - <ul> - <li> - Substitutes the variable UID GID on <em>prog</em>. - </li> - </ul> - -<h2>Options</h2> - - <ul> - <li> - <tt><b>-o <em>owner</em></b></tt> : set UID GID of <em>owner</em> instead of the current one. - </li> - </ul> - -<h2>Usage examples</h2> - - <pre> - execl-subuidgid - if { mkdir -p /run/user } - chown -R $UID:$GID /run/user - </pre> - - <pre> - execl-subuidgid -o root - if { mkdir /run } - chmow -R $UID:$GID /run/user - </pre> - -</body> -</html> diff --git a/doc/html/frontend.html b/doc/html/frontend.html index 0b4c1842b90f0b774ab9067e5db8448227d41c4e..a04e98716107b129ea917bbc489b5f86e11cd143 100644 --- a/doc/html/frontend.html +++ b/doc/html/frontend.html @@ -237,12 +237,21 @@ MYVALUE</pre> <li><h4>@name</h4></li> <h5>Corresponds to the <em>name of the service directory</em> of s6 and s6-rc programs.</h5> <p>Name of the service.</p> - <p><tt>mandatory</tt> : yes (!)</p> + <p><tt>mandatory</tt> : no</p> <p><tt>syntax</tt> : inline</p> <p><tt>valid values</tt> :</p> <ul> - <li>Any name can be set as a <em>value</em>. A good pratice is to use the - same name of the frontend service file.</li> + <li> + This field has <strong>no effect</strong> except for + <tt><a href="#instance">instantiated</a></tt> services. In such case + the name <strong>must</strong> contain the complete name of the + frontend service file.</p> + <p>For example, the following is valid:</p> + <pre>@name = tty@mine-@I</pre> + <p>where:</p> + <pre>@name = mine-@I</pre> + <p>is not for a frontend service file named tty@.</p> + </li> </ul> <br><hr style="border: 1px dashed #000000"> @@ -304,29 +313,7 @@ MYVALUE</pre> to the dependencies of fooA. </li> - <!-- Taking an another example : - FooA depens of FooB which depends of FooC, your service file can just declare FooB and - the parser will automatically add FooB because in your service file of FooB you declare - FooC as dependencies, so - - FooA service file is : @depends=( FooB ) - FooB service file is : @depends=( FooC ) - - Now we have FooA service BooA service and CooA service, FooA depends on BooA which - depends of CooA. - FooA service : @depends = ( BooA ) ; - BooA service : @depends = ( BooB BooC BooD CooA ) ; - CooA service : @depends = ( CooB CooC) ; - - the complete chained dependency should be : - FooA service : @depends = ( BooA BooB BooC BooD CooA CooB CooC ) ; - BooA service : @depends = ( BooB BooC BooD CooA CooB CooC ) - CooA service : @depends = ( CooB CooC) ; - So you're right, the sentence is not clear. - - --> - - </ul> + </ul> <br><hr style="border: 1px dashed #000000"> @@ -837,15 +824,13 @@ for it in your <tt>@execute</tt> field.</p> <li>the name of the file needs to be appended with an '@' (commercial at) character.</li> <li>every value replaced in an instance file needs to be written with '@I'.</li> </ul> - <!-- Apart from the example I think a short explanation of instances would be very helpful. Could be a use case, or just a general situation. --> - <p>Example :</p> + <p>Example :</p> <pre> File name : tty@ Contents : [main] @type = classic - @name = @I @description = "Launch @I" @user = ( root ) @@ -856,7 +841,6 @@ for it in your <tt>@execute</tt> field.</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 @description = "Launch tty1" @user = ( root ) diff --git a/doc/html/index.html b/doc/html/index.html index 3e00176df03ac0879d94325a8382573de6a2c6ac..4fdf12c5a2ebc569ced84b38f93ef4904b3a5ebb 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -81,7 +81,6 @@ <li><a href="66-hpr.html"><tt>66-hpr</tt></a></li> <li><a href="66-shutdownd.html"><tt>66-shutdownd</tt></a></li> <li><a href="66-parser.html"><tt>66-parser</tt></a></li> - <li><a href="66-umountall.html"><tt>66-umountall</tt></a></li> </ul> <h3> User tools </h3> @@ -102,15 +101,8 @@ <h3> Extra tools </h3> <ul> - <li><a href="execl-cmdline.html"><tt>execl-cmdline</tt></a></li> - <li><a href="execl-envfile.html"><tt>execl-envfile</tt></a></li> - <li><a href="execl-subuidgid.html"><tt>execl-subuidgid</tt></a></li> - <li><a href="66-envfile.html"><tt>66-envfile</tt></a> <strong>deprecated</strong></li> - <li><a href="66-getenv.html"><tt>66-getenv</tt></a></li> - <li><a href="66-gnwenv.html"><tt>66-gnwenv</tt></a></li> - <li><a href="66-writenv.html"><tt>66-writenv</tt></a></li> <li><a href="66-echo.html"><tt>66-echo</tt></a></li> - <li><a href="66-which.html"><tt>66-which</tt></a></li> + <li><a href="66-umountall.html"><tt>66-umountall</tt></a></li> </ul> <h2> Why is 66 necessary? </h2> diff --git a/doc/man/66-envfile.1.scd b/doc/man/66-envfile.1.scd deleted file mode 100644 index a10819ad5547d8cb38588d64adf07fcf986d42c0..0000000000000000000000000000000000000000 --- a/doc/man/66-envfile.1.scd +++ /dev/null @@ -1,13 +0,0 @@ -66-envfile(1) - -# NAME - -66-envfile - Read files and add their content to the environment - -# DESCRIPTION - -*66-envfile* is now deprecated in favor of *execl-envfile*(1). - -# SEE ALSO - -*execl-envfile*(1) diff --git a/doc/man/66-frontend.5.scd b/doc/man/66-frontend.5.scd index d59db6d3459db13537c6d6cd899a7a7def2ba775..da37fed22d56c9c91e26e52f3a57caa8aadd4677 100644 --- a/doc/man/66-frontend.5.scd +++ b/doc/man/66-frontend.5.scd @@ -145,11 +145,22 @@ Valid _key_ names: *@name*++ Name of the service.++ - _mandatory_: *yes*++ + _mandatory_: *no*++ _syntax_: *inline*++ _valid values_:++ - Any name can be set as a _value_. A good pratice is to use the same++ - name of the frontend service file. + + This field has *no effect* except for instantiated services. + In such case the name *must* contain the complete name of the + frontend service file. + For example, the following is valid: + + @name = tty@mine-@I + + where: + + @name = mine-@I + + is not for a frontend service file named tty@. Corresponds to the _name_ of the service directory of s6 and s6-rc programs. @@ -666,7 +677,6 @@ Contents: ``` [main] @type = classic -@name = @I @description = "Launch @I" @user = ( root ) @@ -679,7 +689,6 @@ Contents: ``` [main] @type = classic -@name = tty1 @description = "Launch tty1" @user = ( root ) diff --git a/doc/man/66-getenv.1.scd b/doc/man/66-getenv.1.scd deleted file mode 100644 index 6d49e3a811e7575caffe74a8fb1e424c15ef0106..0000000000000000000000000000000000000000 --- a/doc/man/66-getenv.1.scd +++ /dev/null @@ -1,48 +0,0 @@ -66-getenv(1) - -# NAME -66-getenv - Get and display the environment variables of a process name - -# SYNOPSIS - -66-getenv [ *-h* ] [ *-x* ] [ *-d* _delim_ ] _process_ - - -# DESCRIPTION - -66-getenv find the corresponding pid of the _process_ name applying a regex -search. - -It open and read */proc/<pid>/environ* file and displays its contain. - -# OPTIONS - -*-h* - Prints this help. - -*-x* - Match exactly with the process name. It can be a complete command line, in - such case its must be double-quoted. - -*-d* _delim_ - Specify output delimiter. The default is *\n* character. - -# EXIT STATUS - -*0* Success.++ -*111* Failure. - -# EXAMPLE - -``` -66-getenv -x jwm -66-getenv "ck-launch-session jwm" -``` - -# NOTES - -The file */proc/<pid>/environ* contains the initial environment that was set -when the currently executing program was started via *execve*(2). If, after an -*execve*(2), the process modifies its environment (e.g., by calling functions -such as *putenv*(3) or modifying the *environ*(7) variable directly), this file -will *not* reflect those changes—see *proc*(5) for futher informations. diff --git a/doc/man/66-gnwenv.1.scd b/doc/man/66-gnwenv.1.scd deleted file mode 100644 index 0a453b0e548c31a5a0063091786d6a2299048366..0000000000000000000000000000000000000000 --- a/doc/man/66-gnwenv.1.scd +++ /dev/null @@ -1,35 +0,0 @@ -66-gnwenv(1) - -# NAME - -66-gnwenv - Get and write the environment variables of a process - -# SYNOPSIS - -66-gnwenv [ *-h* ] [ *-x* ] [ *-m* _mode_ ] _process_ _dir_ _file_ - -# DESCRIPTION - -66-gnwenv executes into++ -*66-getenv -x process 66-writenv -m mode dir file*++ -It does nothing else: it is just a convenience program. - -*66-getenv*(1) read the environment variable of the _process_, and -*66-writenv*(1) will write these variables into _dir/file_ location. - -# OPTIONS - -*-h* - Prints this help. - -*-x* - Match exactly with the process name. It can be a complete command line, in - such case its must be double-quoted. - -*-m* _mode_ - Create _dir_ with mode _mode_ if it doesn't exist yet. Default is *0755*. - -# EXIT STATUS - -*0* Success.++ -*111* Failure. diff --git a/doc/man/66-parser.1.scd b/doc/man/66-parser.1.scd index 83a915f376a16730fce2987d6d11ba40a7414e31..2703ac10182efea06b8bbca4fa210b306ed5c2f7 100644 --- a/doc/man/66-parser.1.scd +++ b/doc/man/66-parser.1.scd @@ -6,7 +6,7 @@ # SYNOPSIS -66-parser [ *-h* ] [ *-v* _verbosity_ ] [ *-f* ] _service destination_ +66-parser [ *-h* ] [ *-v* _verbosity_ ] [ *-f* ] [ *-c* | *-C* ] _service destination_ # DESCRIPTION diff --git a/doc/man/66-which.1.scd b/doc/man/66-which.1.scd deleted file mode 100644 index 736d0466fc347b0d77763df28cdda6589ce2d379..0000000000000000000000000000000000000000 --- a/doc/man/66-which.1.scd +++ /dev/null @@ -1,81 +0,0 @@ -66-which(1) - -# NAME - -66-which - Check if a command exists in PATH or path exists and is executable - -# SYNOPSIS - -66-which [ *-h* ] [ *-q* | *-a* ] _command(s)_ - -# DESCRIPTION - -66-which is a portable which command that checks if a command exists -and is executable in PATH or at specified path. It behaves slightly -different then the GNU which command. - - -- This tool expect to find valid command name or path, it will check - if they exists and are executable by the current user. - - -- It parse PATH for valid entries, applying a substitution of each -- entry with its realpath and emilinating duplicates. - -- It parses that command given checking if it is a path or a name. - -- It prints each command found with the first PATH entry, otherwise - it print an error. By passing the *-a* option, it - searches and print command with all the PATH entries, even if it - been already found. - -# OPTIONS - -*-h* - Print this help. - -*-a* - Print all. Search and print the command using all the PATH entries, even - after the command has already been found. - -*-q* - Quiet. Do not print anything on stdout. - -# EXIT CODE - -*0* Success; all the commands have been found.++ -*110* Bad usage.++ -*111* System call failed or at least one command hasn't been found. - -# EXAMPLES - -Search for a command by using its name: - - $ 66-which 66-echo - /usr/bin/66-echo - - -Check for a command by using its path: - - $ 66-which /usr/bin/66-echo - /usr/bin/66-echo - -Usage of *66-which* in a script: - - #!/usr/bin/execlineb -P - - if { 66-which -q vgchange } - vgchange -ay - -# NOTES - -*66-which* need at least one valid entry in PATH that exists on the -system. *66-which* is often used in critical scripts, like the ones booting -the system, so it's important to check if PATH contains valid entries for the -current system. - -*66-which* correctly handle the tilde *~* character for paths. -Beware that same shell, like bash, replaces this character with the -current user home path. To pass the correct string to *66-which*, -containing the tilde character, use quoting like this: *66-which* -'~/.bin/gvr'. diff --git a/doc/man/66-writenv.1.scd b/doc/man/66-writenv.1.scd deleted file mode 100644 index 13a573999e4f20dda2cb4ed367bdcb0b66f06bd3..0000000000000000000000000000000000000000 --- a/doc/man/66-writenv.1.scd +++ /dev/null @@ -1,25 +0,0 @@ -66-writenv(1) - -# NAME - -66-writenv - Store environment variables at a specific file location. - -# SYNOPSYS - -66-writenv [ *-h* ] [ *-m* _mode_ ] _dir_ _file_ - -This tool write its environment variables into _dir/file_ under the classic -format *key=value* pair and thoses one per line. _dir_ must be an absolute path. - -# OPTIONS - -*-h* - Prints this help. - -*-m* _mode_ - Create _dir_ with mode _mode_ if it doesn't exist yet. Default is *0755*. - -# EXIT STATUS - -*0* Successful execution -*111* Failure diff --git a/doc/man/execl-cmdline.1.scd b/doc/man/execl-cmdline.1.scd deleted file mode 100644 index 628bb7ae4a7250fc167bde31df6fc53868041c3b..0000000000000000000000000000000000000000 --- a/doc/man/execl-cmdline.1.scd +++ /dev/null @@ -1,74 +0,0 @@ -execl-cmdline(1) - -# NAME - -execl-cmdline - Parse a command line into an execline script. - -# SYNOPSYS - -As *execlineb* script: - -``` - execl-cmdline -S { command } -``` - -# DESCRIPTION - -*execl-cmdline* reads the _command_ and removes all whitespace or 'no word' -before executing. - -OPTIONS - -*-s* - Splits a command considered by *execline* scripting language as one word - into separate words. - -# EXIT STATUS - -*execl-cmdline* exits with the exit code of the _command_. - -# NOTES - -*execl-cmdline* should be used at the end of *execline* scripts. If you want to -run another program after the call of *execl-cmdline* you would need to use an -*if* command, *foreground*, *background* or the likes. - -# EXAMPLE - -The following _command_: - -``` - execl-cmdline { /usr/bin/ntpd -d "" -S } -``` - -will result in: - -``` - - /usr/bin/ntpd "-d" "-S" - -``` - -This _command_: - -``` - - execl-cmdline -S { /usr/bin/ntpd "-d -S" } - -``` - -will result in: - -``` - - /usr/bin/ntpd "-d" "-S" - -``` - -To run another program after the call of *execl-cmdline* program: - -``` - - foreground { execl-cmdline { /usr/bin/ntpd -d "" -S } } - -``` diff --git a/doc/man/execl-envfile.1.scd b/doc/man/execl-envfile.1.scd deleted file mode 100644 index 93d8334b0fcd15c667a2d7c6848717bf61751f7b..0000000000000000000000000000000000000000 --- a/doc/man/execl-envfile.1.scd +++ /dev/null @@ -1,66 +0,0 @@ -execl-envfile(1) - -# NAME - -execl-envfile - A blend of *s6-envdir* and *importas* program. - -# SYNOPSIS - -execl-envfile [ *-h* ] [ *-l* ] _src_ _prog_ - -# DESCRIPTION - -It reads files containing variable assignments on the given file/directory, adds the -variables to the environment, then executes a program. - -This tool expects to find a regular file or a directory in _src_ containing -one or multiple _key=value_ pair(s). It will parse that file, -import the _key=value_ and then exec the given _prog_ with the modified -environment. In case of directory for each file found it apply the same process. - -- It opens and reads the file. -- It parses the file. -- It imports the _key=value_ pair(s). -- It substitutes each corresponding _key_ with _value_ from that file. -- It unexports the variable if requested. -- It execs _prog_ with the modified environment. - -# OPTIONS - -*-h* - Prints this help. - -*-f* _file_ - Only parses the _file_ found in _src_. *deprecated option* - -*-l* - Loose. Do nothing and executes _prog_ directly if _src_ does not contain - any regular file(s) or _src_ doesn't exist. - -# EXAMPLE - -``` - #!/usr/bin/execlineb -P - fdmove -c 2 1 - execl-envfile /etc/66/conf/ntpd - foreground { mkdir -p -m 0755 ${RUNDIR} } - execl-cmdline -s { ntpd ${CMD_ARGS} } -``` - -The strict equivalent with s6-envdir and importas command will be: - -``` - #!/usr/bin/execlineb -P - fdmove -c 2 1 - s6-envdir /etc/66/conf - importas -u RUNDIR RUNDIR - importas -u CMD_ARGS CMD_ARGS - foreground { mkdir -p -m 0755 ${RUNDIR} } - execl-cmdline -s { ntpd ${CMD_ARGS} } -``` - -where */etc/66/conf* directory contains two named files *RUNDIR* and *CMD_ARGS* written with */run/openntpd* and *-d -s* respectively. - -# SEE ALSO - -*execl-envfile*(5) diff --git a/doc/man/execl-envfile.5.scd b/doc/man/execl-envfile.5.scd deleted file mode 100644 index b30b285d81a558144fedc3a95c73d3099a2507c3..0000000000000000000000000000000000000000 --- a/doc/man/execl-envfile.5.scd +++ /dev/null @@ -1,36 +0,0 @@ -execl-envfile(5) - -# NAME - -execl-envfile - _key=value_ format for configuration and environment files - -# SYNTAX - -_file_ is a text file containing lines of pairs with the syntax being: - key = value -Whitespace is permitted before and after _key_, and before or after _value_. -Quoting is also possible. - -Quoting is also possible. In this case, the quoting field is treated as one -word. - -Empty lines, or lines containing only whitespace, are ignored. Lines beginning -with *#* (also after whitespace) are ignored and typically used for -comments. Comments are *not* possible at the end of lines: - -``` -key = value # comment not valid -``` - -Empty _value_ is *not* permitted. -If _val_ begin by a *!* character: - key=*!*value -the _key_ will be removed from the environment after the substitution. - -# LIMITS -_src_ cannot exceed more than 100 files. Each file cannot contain more than -4095 bytes or more than 50 _key=value_ pairs. - -# SEE ALSO - -*execl-envfile*(1) diff --git a/doc/man/execl-subuidgid.1.scd b/doc/man/execl-subuidgid.1.scd deleted file mode 100644 index 10eab4771e85a062a9c6166ca3e19478c6528922..0000000000000000000000000000000000000000 --- a/doc/man/execl-subuidgid.1.scd +++ /dev/null @@ -1,30 +0,0 @@ -execl-subuidgid(1) - -# NAME - -execl-subuidgid - Substitute GID UID with the current owner GID UID - -# SYNOPSIS - -execl-subuidgid [ *-o* _owner_ ] _prog_ - -# DESCRIPTION - -*execl-subuidgid* substitutes the variable UID GID on _prog_. - -# OPTIONS - -*-o* _owner_ - Set UID GID of _owner_ instead of the current one. - -# EXAMPLES - -``` -execl-subuidgid -if { mkdir -p /run/user } -chown -R $UID:$GID /run/user - -execl-subuidgid -o root -if { mkdir /run } -chmow -R $UID:$GID /run/user -``` diff --git a/package/deps.mak b/package/deps.mak index 125324257bca9c0138f320c24af8d3714bddad14..75f4c3e6ec85b7cd9f7ea860322714342defe0b5 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -2,7 +2,7 @@ # This file has been generated by tools/gen-deps.sh # -src/include/66/66.h: 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/environ.h src/include/66/parser.h src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/state.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h +src/include/66/66.h: 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/environ.h src/include/66/hpr.h src/include/66/parser.h src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/state.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h src/include/66/backup.h: src/include/66/ssexec.h src/include/66/constants.h: src/include/66/config.h src/include/66/db.h: src/include/66/ssexec.h @@ -14,7 +14,7 @@ src/include/66/svc.h: src/include/66/resolve.h src/include/66/ssexec.h src/include/66/tree.h: src/include/66/ssexec.h src/include/66/utils.h: src/include/66/resolve.h src/include/66/ssexec.h src/66/66-all.o src/66/66-all.lo: src/66/66-all.c src/include/66/config.h src/include/66/constants.h src/include/66/tree.h src/include/66/utils.h -src/66/66-boot.o src/66/66-boot.lo: src/66/66-boot.c src/include/66/config.h src/include/66/constants.h src/include/66/environ.h +src/66/66-boot.o src/66/66-boot.lo: src/66/66-boot.c src/include/66/config.h src/include/66/constants.h src/66/66-dbctl.o src/66/66-dbctl.lo: src/66/66-dbctl.c src/include/66/ssexec.h src/66/66-disable.o src/66/66-disable.lo: src/66/66-disable.c src/include/66/ssexec.h src/66/66-enable.o src/66/66-enable.lo: src/66/66-enable.c src/include/66/ssexec.h @@ -22,46 +22,36 @@ src/66/66-env.o src/66/66-env.lo: src/66/66-env.c src/include/66/ssexec.h src/66/66-hpr.o src/66/66-hpr.lo: src/66/66-hpr.c src/include/66/config.h src/include/66/hpr.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/environ.h src/include/66/resolve.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/ssexec.h -src/66/66-parser.o src/66/66-parser.lo: src/66/66-parser.c src/include/66/parser.h src/include/66/utils.h +src/66/66-parser.o src/66/66-parser.lo: src/66/66-parser.c src/include/66/constants.h src/include/66/parser.h src/include/66/utils.h src/66/66-scanctl.o src/66/66-scanctl.lo: src/66/66-scanctl.c 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/environ.h src/include/66/utils.h src/66/66-shutdown.o src/66/66-shutdown.lo: src/66/66-shutdown.c src/include/66/config.h src/include/66/hpr.h -src/66/66-shutdownd.o src/66/66-shutdownd.lo: src/66/66-shutdownd.c src/include/66/config.h src/include/66/constants.h src/include/66/environ.h +src/66/66-shutdownd.o src/66/66-shutdownd.lo: src/66/66-shutdownd.c src/include/66/config.h src/include/66/constants.h src/66/66-start.o src/66/66-start.lo: src/66/66-start.c src/include/66/ssexec.h src/66/66-stop.o src/66/66-stop.lo: src/66/66-stop.c src/include/66/ssexec.h src/66/66-svctl.o src/66/66-svctl.lo: src/66/66-svctl.c src/include/66/ssexec.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/enum.h src/include/66/resolve.h src/include/66/state.h src/include/66/tree.h src/include/66/utils.h +src/66/66-treeinfo.o src/66/66-treeinfo.lo: src/66/66-treeinfo.c src/include/66/constants.h src/include/66/enum.h src/include/66/environ.h src/include/66/resolve.h src/include/66/tree.h src/include/66/utils.h src/extra-tools/66-echo.o src/extra-tools/66-echo.lo: src/extra-tools/66-echo.c -src/extra-tools/66-envfile.o src/extra-tools/66-envfile.lo: src/extra-tools/66-envfile.c -src/extra-tools/66-getenv.o src/extra-tools/66-getenv.lo: src/extra-tools/66-getenv.c -src/extra-tools/66-gnwenv.o src/extra-tools/66-gnwenv.lo: src/extra-tools/66-gnwenv.c src/extra-tools/66-umountall.o src/extra-tools/66-umountall.lo: src/extra-tools/66-umountall.c -src/extra-tools/66-which.o src/extra-tools/66-which.lo: src/extra-tools/66-which.c -src/extra-tools/66-writenv.o src/extra-tools/66-writenv.lo: src/extra-tools/66-writenv.c -src/extra-tools/execl-cmdline.o src/extra-tools/execl-cmdline.lo: src/extra-tools/execl-cmdline.c -src/extra-tools/execl-envfile.o src/extra-tools/execl-envfile.lo: src/extra-tools/execl-envfile.c src/include/66/constants.h src/include/66/environ.h src/include/66/parser.h -src/extra-tools/execl-subuidgid.o src/extra-tools/execl-subuidgid.lo: src/extra-tools/execl-subuidgid.c src/include/66/environ.h src/include/66/utils.h -src/extra-tools/execl-testncreate.o src/extra-tools/execl-testncreate.lo: src/extra-tools/execl-testncreate.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/ssexec.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 -src/lib66/db_cmd_master.o src/lib66/db_cmd_master.lo: src/lib66/db_cmd_master.c src/include/66/constants.h src/include/66/db.h src/include/66/parser.h src/include/66/utils.h -src/lib66/db_compile.o src/lib66/db_compile.lo: src/lib66/db_compile.c src/include/66/constants.h src/include/66/db.h src/include/66/ssexec.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/ssexec.h src/include/66/utils.h +src/lib66/db_compile.o src/lib66/db_compile.lo: src/lib66/db_compile.c src/include/66/constants.h src/include/66/db.h src/include/66/utils.h src/lib66/db_find_compiled_state.o src/lib66/db_find_compiled_state.lo: src/lib66/db_find_compiled_state.c src/include/66/constants.h src/include/66/utils.h -src/lib66/db_get_permissions.o src/lib66/db_get_permissions.lo: src/lib66/db_get_permissions.c src/include/66/constants.h src/include/66/utils.h src/lib66/db_ok.o src/lib66/db_ok.lo: src/lib66/db_ok.c src/include/66/constants.h src/lib66/db_switch_to.o src/lib66/db_switch_to.lo: src/lib66/db_switch_to.c src/include/66/backup.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/ssexec.h src/include/66/utils.h -src/lib66/db_update.o src/lib66/db_update.lo: src/lib66/db_update.c src/include/66/constants.h src/include/66/db.h src/include/66/ssexec.h src/include/66/utils.h -src/lib66/environ.o src/lib66/environ.lo: src/lib66/environ.c src/include/66/config.h src/include/66/constants.h src/include/66/environ.h src/include/66/parser.h src/include/66/utils.h +src/lib66/db_update.o src/lib66/db_update.lo: src/lib66/db_update.c src/include/66/db.h src/include/66/ssexec.h src/include/66/utils.h +src/lib66/environ.o src/lib66/environ.lo: src/lib66/environ.c src/include/66/constants.h src/include/66/utils.h src/lib66/get_enum.o src/lib66/get_enum.lo: src/lib66/get_enum.c src/include/66/enum.h src/lib66/get_uidgid.o src/lib66/get_uidgid.lo: src/lib66/get_uidgid.c src/lib66/get_userhome.o src/lib66/get_userhome.lo: src/lib66/get_userhome.c src/include/66/utils.h src/lib66/hpr_shutdown.o src/lib66/hpr_shutdown.lo: src/lib66/hpr_shutdown.c src/include/66/hpr.h src/lib66/hpr_wall.o src/lib66/hpr_wall.lo: src/lib66/hpr_wall.c src/include/66/hpr.h -src/lib66/instance.o src/lib66/instance.lo: src/lib66/instance.c src/include/66/utils.h +src/lib66/instance.o src/lib66/instance.lo: src/lib66/instance.c src/include/66/enum.h src/include/66/utils.h src/lib66/parser.o src/lib66/parser.lo: src/lib66/parser.c src/include/66/enum.h src/include/66/parser.h src/include/66/utils.h src/lib66/parser_enabled.o src/lib66/parser_enabled.lo: src/lib66/parser_enabled.c src/include/66/constants.h src/include/66/environ.h src/include/66/parser.h src/include/66/resolve.h src/include/66/utils.h -src/lib66/parser_utils.o src/lib66/parser_utils.lo: src/lib66/parser_utils.c src/include/66/config.h src/include/66/constants.h src/include/66/enum.h src/include/66/environ.h src/include/66/parser.h src/include/66/utils.h +src/lib66/parser_utils.o src/lib66/parser_utils.lo: src/lib66/parser_utils.c src/include/66/config.h src/include/66/constants.h src/include/66/enum.h src/include/66/parser.h src/include/66/utils.h src/lib66/parser_write.o src/lib66/parser_write.lo: src/lib66/parser_write.c src/include/66/constants.h src/include/66/enum.h src/include/66/environ.h src/include/66/parser.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/utils.h src/lib66/rc_init.o src/lib66/rc_init.lo: src/lib66/rc_init.c src/include/66/constants.h src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/state.h src/include/66/utils.h src/lib66/rc_manage.o src/lib66/rc_manage.lo: src/lib66/rc_manage.c src/include/66/constants.h src/include/66/db.h src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/state.h src/include/66/utils.h @@ -72,9 +62,9 @@ src/lib66/resolve_graph.o src/lib66/resolve_graph.lo: src/lib66/resolve_graph.c src/lib66/scandir_ok.o src/lib66/scandir_ok.lo: src/lib66/scandir_ok.c src/include/66/utils.h src/lib66/scandir_send_signal.o src/lib66/scandir_send_signal.lo: src/lib66/scandir_send_signal.c src/include/66/utils.h src/lib66/set_livedir.o src/lib66/set_livedir.lo: src/lib66/set_livedir.c src/include/66/config.h src/include/66/utils.h -src/lib66/set_livescan.o src/lib66/set_livescan.lo: src/lib66/set_livescan.c src/include/66/config.h src/include/66/constants.h src/include/66/utils.h -src/lib66/set_livestate.o src/lib66/set_livestate.lo: src/lib66/set_livestate.c src/include/66/config.h src/include/66/constants.h src/include/66/utils.h -src/lib66/set_livetree.o src/lib66/set_livetree.lo: src/lib66/set_livetree.c src/include/66/config.h src/include/66/constants.h src/include/66/utils.h +src/lib66/set_livescan.o src/lib66/set_livescan.lo: src/lib66/set_livescan.c src/include/66/constants.h src/include/66/utils.h +src/lib66/set_livestate.o src/lib66/set_livestate.lo: src/lib66/set_livestate.c src/include/66/constants.h src/include/66/utils.h +src/lib66/set_livetree.o src/lib66/set_livetree.lo: src/lib66/set_livetree.c src/include/66/constants.h src/include/66/utils.h 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/ss_utils.o src/lib66/ss_utils.lo: src/lib66/ss_utils.c src/include/66/utils.h @@ -97,7 +87,7 @@ src/lib66/svc_send.o src/lib66/svc_send.lo: src/lib66/svc_send.c src/include/66/ 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/ssexec.h src/include/66/utils.h src/lib66/svc_unsupervise.o src/lib66/svc_unsupervise.lo: src/lib66/svc_unsupervise.c src/include/66/resolve.h src/include/66/ssexec.h src/include/66/state.h src/include/66/svc.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_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.o src/lib66/tree_copy.lo: src/lib66/tree_copy.c src/include/66/constants.h src/include/66/tree.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/ssexec.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_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 @@ -143,28 +133,12 @@ src/lib66/tree_switch_current.o src/lib66/tree_switch_current.lo: src/lib66/tree 66-tree: src/66/66-tree.o ${LIB66} -ls6rc -ls6 -loblibs -lskarnet 66-echo: EXTRA_LIBS := 66-echo: src/extra-tools/66-echo.o -lskarnet -66-envfile: EXTRA_LIBS := -66-envfile: src/extra-tools/66-envfile.o -lskarnet -66-getenv: EXTRA_LIBS := -66-getenv: src/extra-tools/66-getenv.o -loblibs -lskarnet -66-gnwenv: EXTRA_LIBS := -66-gnwenv: src/extra-tools/66-gnwenv.o -loblibs -lskarnet 66-umountall: EXTRA_LIBS := 66-umountall: src/extra-tools/66-umountall.o -lskarnet -66-which: EXTRA_LIBS := -66-which: src/extra-tools/66-which.o -lskarnet -loblibs -66-writenv: EXTRA_LIBS := -66-writenv: src/extra-tools/66-writenv.o -lskarnet -execl-cmdline: EXTRA_LIBS := -execl-cmdline: src/extra-tools/execl-cmdline.o -lexecline -loblibs -lskarnet -execl-envfile: EXTRA_LIBS := -execl-envfile: src/extra-tools/execl-envfile.o ${LIB66} -lexecline -loblibs -lskarnet ${LIBEXECLINE} -execl-subuidgid: EXTRA_LIBS := -execl-subuidgid: src/extra-tools/execl-subuidgid.o ${LIB66} -lexecline -loblibs -lskarnet ${LIBEXECLINE} 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/environ.o src/lib66/get_enum.o src/lib66/get_uidgid.o src/lib66/get_userhome.o src/lib66/hpr_shutdown.o src/lib66/hpr_wall.o src/lib66/instance.o src/lib66/parser.o src/lib66/parser_enabled.o src/lib66/parser_utils.o src/lib66/parser_write.o src/lib66/rc_init.o src/lib66/rc_manage.o src/lib66/rc_send.o src/lib66/rc_unsupervise.o src/lib66/resolve.o src/lib66/resolve_graph.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_livestate.o src/lib66/set_livetree.o src/lib66/set_ownerhome.o src/lib66/set_ownersysdir.o src/lib66/ss_utils.o src/lib66/ssexec_dbctl.o src/lib66/ssexec_enable.o src/lib66/ssexec_env.o src/lib66/ssexec_disable.o src/lib66/ssexec_free.o src/lib66/ssexec_help.o src/lib66/ssexec_init.o src/lib66/ssexec_main.o src/lib66/ssexec_start.o src/lib66/ssexec_stop.o src/lib66/ssexec_svctl.o src/lib66/state.o src/lib66/sv_alltype_zero.o src/lib66/svc_init.o src/lib66/svc_init_pipe.o src/lib66/svc_send.o src/lib66/svc_switch_to.o src/lib66/svc_unsupervise.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 +lib66.a.xyzzy: src/lib66/backup_cmd_switcher.o src/lib66/backup_make_new.o src/lib66/backup_realpath_sym.o src/lib66/db_compile.o src/lib66/db_find_compiled_state.o src/lib66/db_ok.o src/lib66/db_switch_to.o src/lib66/db_update.o src/lib66/environ.o src/lib66/get_enum.o src/lib66/get_uidgid.o src/lib66/get_userhome.o src/lib66/hpr_shutdown.o src/lib66/hpr_wall.o src/lib66/instance.o src/lib66/parser.o src/lib66/parser_enabled.o src/lib66/parser_utils.o src/lib66/parser_write.o src/lib66/rc_init.o src/lib66/rc_manage.o src/lib66/rc_send.o src/lib66/rc_unsupervise.o src/lib66/resolve.o src/lib66/resolve_graph.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_livestate.o src/lib66/set_livetree.o src/lib66/set_ownerhome.o src/lib66/set_ownersysdir.o src/lib66/ss_utils.o src/lib66/ssexec_dbctl.o src/lib66/ssexec_enable.o src/lib66/ssexec_env.o src/lib66/ssexec_disable.o src/lib66/ssexec_free.o src/lib66/ssexec_help.o src/lib66/ssexec_init.o src/lib66/ssexec_main.o src/lib66/ssexec_start.o src/lib66/ssexec_stop.o src/lib66/ssexec_svctl.o src/lib66/state.o src/lib66/sv_alltype_zero.o src/lib66/svc_init.o src/lib66/svc_init_pipe.o src/lib66/svc_send.o src/lib66/svc_switch_to.o src/lib66/svc_unsupervise.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/environ.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/hpr_shutdown.lo src/lib66/hpr_wall.lo src/lib66/instance.lo src/lib66/parser.lo src/lib66/parser_enabled.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/rc_init.lo src/lib66/rc_manage.lo src/lib66/rc_send.lo src/lib66/rc_unsupervise.lo src/lib66/resolve.lo src/lib66/resolve_graph.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_livestate.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/ss_utils.lo src/lib66/ssexec_dbctl.lo src/lib66/ssexec_enable.lo src/lib66/ssexec_env.lo src/lib66/ssexec_disable.lo src/lib66/ssexec_free.lo src/lib66/ssexec_help.lo src/lib66/ssexec_init.lo src/lib66/ssexec_main.lo src/lib66/ssexec_start.lo src/lib66/ssexec_stop.lo src/lib66/ssexec_svctl.lo src/lib66/state.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_init.lo src/lib66/svc_init_pipe.lo src/lib66/svc_send.lo src/lib66/svc_switch_to.lo src/lib66/svc_unsupervise.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 +lib66.a.xyzzy: src/lib66/backup_cmd_switcher.lo src/lib66/backup_make_new.lo src/lib66/backup_realpath_sym.lo src/lib66/db_compile.lo src/lib66/db_find_compiled_state.lo src/lib66/db_ok.lo src/lib66/db_switch_to.lo src/lib66/db_update.lo src/lib66/environ.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/hpr_shutdown.lo src/lib66/hpr_wall.lo src/lib66/instance.lo src/lib66/parser.lo src/lib66/parser_enabled.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/rc_init.lo src/lib66/rc_manage.lo src/lib66/rc_send.lo src/lib66/rc_unsupervise.lo src/lib66/resolve.lo src/lib66/resolve_graph.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_livestate.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/ss_utils.lo src/lib66/ssexec_dbctl.lo src/lib66/ssexec_enable.lo src/lib66/ssexec_env.lo src/lib66/ssexec_disable.lo src/lib66/ssexec_free.lo src/lib66/ssexec_help.lo src/lib66/ssexec_init.lo src/lib66/ssexec_main.lo src/lib66/ssexec_start.lo src/lib66/ssexec_stop.lo src/lib66/ssexec_svctl.lo src/lib66/state.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_init.lo src/lib66/svc_init_pipe.lo src/lib66/svc_send.lo src/lib66/svc_switch_to.lo src/lib66/svc_unsupervise.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 := -ls6rc -ls6 -loblibs -lexecline -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/environ.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/hpr_shutdown.lo src/lib66/hpr_wall.lo src/lib66/instance.lo src/lib66/parser.lo src/lib66/parser_enabled.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/rc_init.lo src/lib66/rc_manage.lo src/lib66/rc_send.lo src/lib66/rc_unsupervise.lo src/lib66/resolve.lo src/lib66/resolve_graph.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_livestate.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/ss_utils.lo src/lib66/ssexec_dbctl.lo src/lib66/ssexec_enable.lo src/lib66/ssexec_env.lo src/lib66/ssexec_disable.lo src/lib66/ssexec_free.lo src/lib66/ssexec_help.lo src/lib66/ssexec_init.lo src/lib66/ssexec_main.lo src/lib66/ssexec_start.lo src/lib66/ssexec_stop.lo src/lib66/ssexec_svctl.lo src/lib66/state.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_init.lo src/lib66/svc_init_pipe.lo src/lib66/svc_send.lo src/lib66/svc_switch_to.lo src/lib66/svc_unsupervise.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 +lib66.so.xyzzy: src/lib66/backup_cmd_switcher.lo src/lib66/backup_make_new.lo src/lib66/backup_realpath_sym.lo src/lib66/db_compile.lo src/lib66/db_find_compiled_state.lo src/lib66/db_ok.lo src/lib66/db_switch_to.lo src/lib66/db_update.lo src/lib66/environ.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/hpr_shutdown.lo src/lib66/hpr_wall.lo src/lib66/instance.lo src/lib66/parser.lo src/lib66/parser_enabled.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/rc_init.lo src/lib66/rc_manage.lo src/lib66/rc_send.lo src/lib66/rc_unsupervise.lo src/lib66/resolve.lo src/lib66/resolve_graph.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_livestate.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/ss_utils.lo src/lib66/ssexec_dbctl.lo src/lib66/ssexec_enable.lo src/lib66/ssexec_env.lo src/lib66/ssexec_disable.lo src/lib66/ssexec_free.lo src/lib66/ssexec_help.lo src/lib66/ssexec_init.lo src/lib66/ssexec_main.lo src/lib66/ssexec_start.lo src/lib66/ssexec_stop.lo src/lib66/ssexec_svctl.lo src/lib66/state.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_init.lo src/lib66/svc_init_pipe.lo src/lib66/svc_send.lo src/lib66/svc_switch_to.lo src/lib66/svc_unsupervise.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 b543db89cc1568565de7c3de21a38a201221b800..f341068acfdf55323d1364267bbbc4201fdd2fc5 100644 --- a/package/modes +++ b/package/modes @@ -1,37 +1,30 @@ -66-scandir 0755 -66-scanctl 0755 -66-init 0755 -66-tree 0755 -66-dbctl 0755 -66-enable 0755 -66-envfile 0755 -66-disable 0755 -66-parser 0755 -66-start 0755 -66-stop 0755 -66-svctl 0755 -66-all 0755 -66-info 0755 -66-env 0755 -66-boot 0755 -66-shutdown 0755 -66-shutdownd 0755 -66-hpr 0755 -execl-cmdline 0755 -execl-envfile 0755 -execl-subuidgid 0755 -66-writenv 0755 -66-getenv 0755 -66-gnwenv 0755 -66-umountall 0755 -66-echo 0755 -66-which 0755 -halt 0755 -init 0755 -init.conf 0644 -ishell 0755 -poweroff 0755 -rc.init 0755 -rc.shutdown 0755 -reboot 0755 -shutdown 0755 +66-scandir 0755 +66-scanctl 0755 +66-init 0755 +66-tree 0755 +66-dbctl 0755 +66-enable 0755 +66-disable 0755 +66-parser 0755 +66-start 0755 +66-stop 0755 +66-svctl 0755 +66-all 0755 +66-info 0755 +66-env 0755 +66-boot 0755 +66-shutdown 0755 +66-shutdownd 0755 +66-hpr 0755 +66-umountall 0755 +66-echo 0755 +halt 0755 +init 0755 +init.conf 0644 +ishell 0755 +poweroff 0755 +rc.init 0755 +rc.shutdown 0755 +rc.shutdown.final 0755 +reboot 0755 +shutdown 0755 diff --git a/package/targets.mak b/package/targets.mak index 79aef9f99981f81cbe3fcafb8fc18a097b8b7ef0..8c864254297aa5a6eaf06cef6efafec28d5f23d6 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -5,7 +5,6 @@ BIN_TARGETS := \ 66-tree \ 66-dbctl \ 66-enable \ -66-envfile \ 66-disable \ 66-parser \ 66-start \ @@ -18,14 +17,7 @@ BIN_TARGETS := \ 66-shutdown \ 66-shutdownd \ 66-hpr \ -execl-cmdline \ -execl-envfile \ -execl-subuidgid \ -66-writenv \ -66-getenv \ -66-gnwenv \ 66-umountall \ -66-echo \ -66-which +66-echo LIB_DEFS := 66=66 diff --git a/skel/init.conf b/skel/init.conf index bc11261d56e7108e1509eb1b6be7aec8c3bcfc02..76d1d3eda8c38da20ef49a2aed98924e6fcbd071 100644 --- a/skel/init.conf +++ b/skel/init.conf @@ -4,6 +4,7 @@ PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin TREE=boot RCINIT=@SKEL@/rc.init RCSHUTDOWN=@SKEL@/rc.shutdown +RCSHUTDOWNFINAL=@SKEL@/rc.shutdown.final UMASK=0022 RESCAN=0 ISHELL=@SKEL@/ishell diff --git a/skel/rc.shutdown.final b/skel/rc.shutdown.final new file mode 100755 index 0000000000000000000000000000000000000000..2c9bf04677803bc3ed3402e23385754ab8155e93 --- /dev/null +++ b/skel/rc.shutdown.final @@ -0,0 +1,18 @@ +#!@EXECLINE_SHEBANGPREFIX@/execlineb -S0 + +## Things to do *right before* the machine gets rebooted or +## powered off, at the very end of the shutdown sequence, +## when all the filesystems are unmounted. + +## This is a last resort hook; normally nothing should be +## done here (your rc.shutdown script should have taken care +## of everything) and you should leave this script empty. + +## Some distributions, however, may need to perform some +## actions after unmounting the filesystems: typically if +## an additional teardown action is required on a filesystem +## after unmounting it, or if the system needs to be +## pivot_rooted before it can be shut down, etc. + +## Those are all exceptional cases. If you don't know for +## certain that you need to do something here, you don't. diff --git a/src/66/66-all.c b/src/66/66-all.c index 838f115972a57ecc59315b564e61d8833b58b5e7..2e864372d1a544d58d316094289290b8098295c4 100644 --- a/src/66/66-all.c +++ b/src/66/66-all.c @@ -20,15 +20,13 @@ #include <oblibs/error2.h> #include <oblibs/obgetopt.h> -#include <oblibs/stralist.h> #include <oblibs/types.h> #include <oblibs/string.h> #include <oblibs/files.h> -#include <oblibs/directory.h> +#include <oblibs/sastr.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> #include <skalibs/djbunix.h> #include <66/constants.h> @@ -64,7 +62,7 @@ int doit(char const *tree,char const *treename,char const *live, unsigned int wh int wstat ; pid_t pid ; - genalloc ga = GENALLOC_ZERO ; //stralist + stralloc dirlist = STRALLOC_ZERO ; char ownerstr[UID_FMT] ; size_t ownerlen = uid_fmt(ownerstr,owner) ; @@ -80,15 +78,14 @@ int doit(char const *tree,char const *treename,char const *live, unsigned int wh src[livelen + SS_STATE_LEN + 1 + ownerlen] = '/' ; memcpy(src + livelen + SS_STATE_LEN + 1 + ownerlen + 1,treename,treenamelen) ; src[livelen + SS_STATE_LEN + 1 + ownerlen + 1 + treenamelen] = 0 ; - - if (!dir_get(&ga,src,"init",S_IFREG)) - { - VERBO1 strerr_warnwu3x("Empty tree: ",treename,": nothing to do") ; - goto freed ; - } + if (!sastr_dir_get(&dirlist,src,"init",S_IFREG)) + strerr_diefu2sys(111,"get init file from directory: ",src) ; + + if (dirlist.len) { - char const *newargv[10 + genalloc_len(stralist,&ga)] ; + size_t i = 0, len = sastr_len(&dirlist) ; + char const *newargv[10 + len + 1] ; unsigned int m = 0 ; char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; @@ -109,8 +106,9 @@ int doit(char const *tree,char const *treename,char const *live, unsigned int wh newargv[m++] = "-t" ; newargv[m++] = treename ; - for (unsigned int i = 0 ; i < genalloc_len(stralist,&ga) ; i++) - newargv[m++] = gaistr(&ga,i) ; + len = dirlist.len ; + for (;i < len; i += strlen(dirlist.s + i) + 1) + newargv[m++] = dirlist.s+i ; newargv[m++] = 0 ; @@ -122,11 +120,12 @@ int doit(char const *tree,char const *treename,char const *live, unsigned int wh } if (wstat) goto err ; } - freed: - genalloc_deepfree(stralist,&ga,stra_free) ; + else VERBO1 strerr_warni3x("Empty tree: ",treename," -- nothing to do") ; + + stralloc_free(&dirlist) ; return 1 ; err: - genalloc_deepfree(stralist,&ga,stra_free) ; + stralloc_free(&dirlist) ; return 0 ; } @@ -155,7 +154,7 @@ int main(int argc, char const *const *argv,char const *const *envp) int r, what, wstat, shut = 0, fd ; pid_t pid ; uid_t owner ; - + size_t statesize, statelen, pos = 0 ; char const *treename = NULL ; stralloc base = STRALLOC_ZERO ; @@ -164,7 +163,7 @@ int main(int argc, char const *const *argv,char const *const *envp) stralloc tree = STRALLOC_ZERO ; stralloc live = STRALLOC_ZERO ; stralloc contents = STRALLOC_ZERO ; - genalloc in = GENALLOC_ZERO ; //stralist + stralloc ugly = STRALLOC_ZERO ; what = 1 ; @@ -221,9 +220,6 @@ int main(int argc, char const *const *argv,char const *const *envp) if (!r) retstralloc(111,"main") ; if (r < 0 ) strerr_dief3x(111,"livetree: ",livetree.s," must be an absolute path") ; - size_t statesize ; - /** /system/state */ - size_t statelen ; char state[base.len + SS_SYSTEM_LEN + SS_STATE_LEN + 1] ; memcpy(state,base.s,base.len) ; memcpy(state + base.len,SS_SYSTEM,SS_SYSTEM_LEN) ; @@ -235,30 +231,29 @@ int main(int argc, char const *const *argv,char const *const *envp) if (r < 0) strerr_dief2x(111,"conflict format for: ",state) ; if (!r) strerr_diefu2sys(111,"find: ",state) ; - statesize = file_get_size(state) ; - - r = openreadfileclose(state,&contents,statesize) ; - if(!r) strerr_diefu2sys(111,"open: ", state) ; - - /** ensure that we have an empty line at the end of the string*/ - if (!stralloc_cats(&contents,"\n")) retstralloc(111,"main") ; - if (!stralloc_0(&contents)) retstralloc(111,"main") ; - /** only one tree?*/ if (treename) { - if (!stra_add(&in,treename)) strerr_diefu3x(111,"add: ", treename," as tree to start") ; + if (!stralloc_cats(&contents,treename)) strerr_diefu3x(111,"add: ", treename," as tree to start") ; + if (!stralloc_0(&contents)) retstralloc(111,"main") ; } else { - if (!clean_val(&in,contents.s)) - strerr_diefu2x(111,"clean: ",contents.s) ; - } + statesize = file_get_size(state) ; + + r = openreadfileclose(state,&contents,statesize) ; + if(!r) strerr_diefu2sys(111,"open: ", state) ; - if (!in.len) - { - strerr_warni1x("nothing to do") ; - goto end ; + /** ensure that we have an empty line at the end of the string*/ + if (!stralloc_cats(&contents,"\n")) retstralloc(111,"main") ; + if (!stralloc_0(&contents)) retstralloc(111,"main") ; + + if (!sastr_clean_element(&contents)) + { + strerr_warni1x("nothing to do") ; + goto end ; + } + } if (shut) @@ -283,11 +278,11 @@ int main(int argc, char const *const *argv,char const *const *envp) else redir_fd() ; } - for (unsigned int i = 0 ; i < genalloc_len(stralist,&in) ; i++) + for (;pos < contents.len; pos += strlen(contents.s + pos) + 1) { tree.len = 0 ; - char *treename = gaistr(&in,i) ; + char *treename = contents.s + pos ; if(!stralloc_cats(&tree,treename)) retstralloc(111,"main") ; if(!stralloc_0(&tree)) retstralloc(111,"main") ; @@ -297,7 +292,29 @@ int main(int argc, char const *const *argv,char const *const *envp) if (!tree_get_permissions(tree.s,owner)) strerr_dief2x(110,"You're not allowed to use the tree: ",tree.s) ; - + /* we need to make an ugly check here, a tree might be empty. + * 66-init will not complain about this but doit function will do. + * So, we need to scan the tree before trying to start any service from it. + * This check is a temporary one because the tree dependencies feature + * will come on a near future and it will change this default behavior */ + size_t newlen = tree.len ; + if (!stralloc_cats(&tree,SS_SVDIRS SS_SVC)) retstralloc(111,"main") ; + if (!stralloc_0(&tree)) retstralloc(111,"main") ; + + if (!sastr_dir_get(&ugly,tree.s,"",S_IFDIR)) strerr_diefu2x(111,"get classic services from: ",tree.s) ; + if (!ugly.len) + { + tree.len = newlen ; + ugly.len = 0 ; + if (!stralloc_cats(&tree,SS_SVDIRS SS_DB SS_SRC)) retstralloc(111,"main") ; + if (!stralloc_0(&tree)) retstralloc(111,"main") ; + if (!sastr_dir_get(&ugly,tree.s,SS_MASTER+1,S_IFDIR)) strerr_diefu2sys(111,"get rc services from: ",tree.s) ; + if (!ugly.len) + { + strerr_warni3x("empty tree: ",treename," -- nothing to do") ; + goto end ; + } + } if (what) { char const *newargv[9] ; @@ -348,7 +365,7 @@ int main(int argc, char const *const *argv,char const *const *envp) stralloc_free(&livetree) ; stralloc_free(&scandir) ; stralloc_free(&contents) ; - genalloc_deepfree(stralist,&in,stra_free) ; - + stralloc_free(&ugly) ; + return 0 ; } diff --git a/src/66/66-boot.c b/src/66/66-boot.c index 1e40f5fce82354d2eb228160b333d107c9ca11e6..2b5b71e1fd08ec7228f6de49fbd572d982e179ed 100644 --- a/src/66/66-boot.c +++ b/src/66/66-boot.c @@ -19,21 +19,21 @@ #include <errno.h> #include <sys/stat.h> #include <sys/mount.h> +#include <sys/reboot.h> #include <oblibs/error2.h> #include <oblibs/files.h> #include <oblibs/string.h> #include <oblibs/obgetopt.h> +#include <oblibs/environ.h> +#include <oblibs/sastr.h> #include <skalibs/buffer.h> #include <skalibs/djbunix.h> -#include <skalibs/diuint32.h> -#include <skalibs/genalloc.h> #include <skalibs/stralloc.h> #include <skalibs/types.h> #include <66/config.h> -#include <66/environ.h> #include <66/constants.h> unsigned int VERBOSITY = 1 ; @@ -48,7 +48,7 @@ static char const *banner = "\n[Starts stage1 process...]" ; static char const *slashdev = 0 ; static char const *envdir = 0 ; static char const *fifo = 0 ; -static char const *log = 0 ; +static char const *log_user = SS_LOGGER_RUNNER ; static char const *cver = 0 ; static char tpath[MAXENV+1] ; static char trcinit[MAXENV+1] ; @@ -68,7 +68,7 @@ static void sulogin(char const *msg,char const *arg) fd_close(0) ; if (dup2(fdin,0) == -1) strerr_diefu1x(111,"duplicate stdin -- you are on your own") ; fd_close(fdin) ; - if (*msg) strerr_warnwu2sys(msg,arg) ; + if (*msg) strerr_warnwu2x(msg,arg) ; pid = child_spawn0(newarg[0],newarg,genv) ; if (waitpid_nointr(pid,&wstat, 0) < 0) strerr_diefu1sys(111,"wait for sulogin -- you are on your own") ; @@ -101,10 +101,9 @@ static void parse_conf(void) static char const *valid[] = { "VERBOSITY", "PATH", "LIVE", "TREE", "RCINIT", "UMASK", "RESCAN", 0 } ; int r ; - unsigned int i = 0, j = 0 ; + unsigned int j = 0 ; stralloc src = STRALLOC_ZERO ; - stralloc saconf = STRALLOC_ZERO ; - genalloc gaconf = GENALLOC_ZERO ; + stralloc val = STRALLOC_ZERO ; if (skel[0] != '/') sulogin("skeleton directory must be an aboslute path: ",skel) ; size_t skelen = strlen(skel) ; memcpy(confile,skel,skelen) ; @@ -114,51 +113,50 @@ static void parse_conf(void) size_t filesize=file_get_size(confile) ; r = openreadfileclose(confile,&src,filesize) ; if(!r) sulogin("open configuration file: ",confile) ; - if (!stralloc_0(&src)) sulogin("append stralloc configuration file","") ; + if (!stralloc_0(&src)) sulogin("append stralloc of file: ",confile) ; - r = env_split(&gaconf,&saconf,&src) ; - if (!r) sulogin("parse configuration file: ",confile) ; - - for (;i < genalloc_len(diuint32,&gaconf) ; i++) + for (char const *const *p = valid;*p;p++,j++) { - char *key = saconf.s + genalloc_s(diuint32,&gaconf)[i].left ; - char *val = saconf.s + genalloc_s(diuint32,&gaconf)[i].right ; - j = 0 ; - for (char const *const *p = valid;*p;p++,j++) + if (!stralloc_copy(&val,&src)) sulogin("copy stralloc of file: ",confile) ; + if (!environ_get_val_of_key(&val,*p)) continue ; + /** value may be empty, in this case we use the default one */ + if (!sastr_clean_element(&val)) + { + strerr_warnwu3x("get value of: ",*p," -- keeps the default") ; + continue ; + } + if (!sastr_rebuild_in_oneline(&val)) sulogin("rebuild line of value: ",val.s) ; + if (!stralloc_0(&val)) sulogin("append stralloc of value: ",val.s) ; + + switch (j) { - if (!strcmp(*p,key)) - { - switch (j) - { - case 0: if (!uint0_scan(val, &VERBOSITY)) sulogin("invalid VERBOSITY value: ","") ; - break ; - case 1: memcpy(tpath,val,strlen(val)) ; - tpath[strlen(val)] = 0 ; - path = tpath ; - break ; - case 2: memcpy(tlive,val,strlen(val)) ; - tlive[strlen(val)] = 0 ; - live = tlive ; - if (live[0] != '/') sulogin ("LIVE must be an absolute path","") ; - break ; - case 3: memcpy(ttree,val,strlen(val)) ; - ttree[strlen(val)] = 0 ; - tree = ttree ; - break ; - case 4: memcpy(trcinit,val,strlen(val)) ; - trcinit[strlen(val)] = 0 ; - rcinit = trcinit ; - if (rcinit[0] != '/') sulogin ("RCINIT must be an absolute path","") ; - break ; - case 5: if (!uint0_oscan(val, &mask)) sulogin("invalid MASK value","") ; break ; - case 6: if (!uint0_scan(val, &rescan)) sulogin("invalid RESCAN value","") ; break ; - default: break ; - } - } + case 0: if (!uint0_scan(val.s, &VERBOSITY)) sulogin("parse VERBOSITY value: ",val.s) ; + break ; + case 1: memcpy(tpath,val.s,val.len) ; + tpath[val.len] = 0 ; + path = tpath ; + break ; + case 2: memcpy(tlive,val.s,val.len) ; + tlive[val.len] = 0 ; + live = tlive ; + if (live[0] != '/') sulogin ("LIVE must be an absolute path: ",val.s) ; + break ; + case 3: memcpy(ttree,val.s,val.len) ; + ttree[val.len] = 0 ; + tree = ttree ; + break ; + case 4: memcpy(trcinit,val.s,val.len) ; + trcinit[val.len] = 0 ; + rcinit = trcinit ; + if (rcinit[0] != '/') sulogin ("RCINIT must be an absolute path: ",val.s) ; + break ; + case 5: if (!uint0_oscan(val.s, &mask)) sulogin("invalid MASK value: ",val.s) ; break ; + case 6: if (!uint0_scan(val.s, &rescan)) sulogin("invalid RESCAN value: ",val.s) ; break ; + default: break ; } + } - genalloc_free(diuint32,&gaconf) ; - stralloc_free(&saconf) ; + stralloc_free(&val) ; stralloc_free(&src) ; } @@ -254,7 +252,7 @@ int main(int argc, char const *const *argv,char const *const *envp) case 'e' : envdir = l.arg ; break ; case 'd' : slashdev = l.arg ; break ; case 'b' : banner = l.arg ; break ; - case 'l' : log = l.arg ; break ; + case 'l' : log_user = l.arg ; break ; default : exitusage(USAGE) ; } } @@ -318,10 +316,9 @@ int main(int argc, char const *const *argv,char const *const *envp) if (setenv("PATH", path, 1) == -1) sulogin("set initial PATH: ",path) ; /** create scandir */ { - int m = log ? 6 : 4 ; - char const *t[] = { "-b", "-c", "-s", skel, log ? "-L" : 0, log ? log : 0 } ; + char const *t[] = { "-b", "-c", "-s", skel, "-L", log_user } ; strerr_warni2x("Create live scandir at: ",live) ; - make_cmdline(SS_EXTBINPREFIX "66-scandir",t,m,"create live scandir at: ",live,envp) ; + make_cmdline(SS_EXTBINPREFIX "66-scandir",t,6,"create live scandir at: ",live,envp) ; } /** initiate earlier service */ { @@ -330,8 +327,10 @@ int main(int argc, char const *const *argv,char const *const *envp) make_cmdline(SS_EXTBINPREFIX "66-init",t,3,"initiate earlier service of tree: ",tree,envp) ; } - if (envdir) - if (!env_get_from_src(&envmodifs,envdir)) sulogin("get environment from: ",envdir) ; + if (envdir) { + int e = environ_get_envfile(&envmodifs,envdir) ; + if (e <= 0){ environ_get_envfile_error(e,envdir) ; sulogin("","") ; } + } { strerr_warni3x("Starts boot logger at: ",live,"/log/0") ; @@ -360,6 +359,7 @@ int main(int argc, char const *const *argv,char const *const *envp) pid = fork() ; if (pid == -1) sulogin("fork: ",rcinit) ; if (!pid) run_stage2(newenvp, 2, envmodifs.s,envmodifs.len) ; + if (reboot(RB_DISABLE_CAD) == -1) sulogin("trap ctrl-alt-del","") ; if (fd_copy(2, 1) == -1) sulogin("copy stderr to stdout","") ; fd_close(fdin) ; xpathexec_r(newargv, newenvp, 2, envmodifs.s, envmodifs.len) ; diff --git a/src/66/66-info.c b/src/66/66-info.c index b0b14ad64521e0b89696872e97de00dd39388738..6a6555796f9679df04fb723596a3bdb7db15357a 100644 --- a/src/66/66-info.c +++ b/src/66/66-info.c @@ -20,11 +20,11 @@ #include <oblibs/obgetopt.h> #include <oblibs/error2.h> -#include <oblibs/stralist.h> #include <oblibs/string.h> #include <oblibs/files.h> #include <oblibs/directory.h> #include <oblibs/types.h> +#include <oblibs/sastr.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> @@ -54,7 +54,7 @@ static char OWNERSTR[UID_FMT] ; static int force_color = 0 ; #define MAXSIZE 4096 -#define DBG(...) bprintf(buffer_1, __VA_ARGS__) ;\ +#define DBG_INFO(...) bprintf(buffer_1, __VA_ARGS__) ;\ buffer_putflush(buffer_1,"\n",1) ; @@ -223,7 +223,7 @@ int info_print_tree(char const *treename,int init,int current,int enabled) if (!bprintf(buffer_1,"%s%s%s%*s%s%s","Initialized: ",init ? color->blue : color->yellow, init ? "yes":"no",indent,"",color->off,"| ")) return 0 ; if (!bprintf(buffer_1,"%s%s%s%s","Current: ",current ? color->blink_blue : color->yellow ,current ? "yes":"no",color->off)) return 0 ; if (buffer_putsflush(buffer_1,"\n") < 0) return 0 ; - if (!bprintf(buffer_1,"%s%9s%s%s%s%s","Contains:"," | ","Enabled: ",enabled ? color->blue : color->yellow ,enabled ? "yes":"no",color->off)) return 0 ; + if (!bprintf(buffer_1,"%s%9s%s%s%s%s","Contains:"," | ","Enabled: ",enabled == 1 ? color->blue : color->yellow ,enabled ? "yes":"no",color->off)) return 0 ; if (buffer_putsflush(buffer_1,"\n") < 0) return 0 ; return 1 ; } @@ -300,51 +300,55 @@ static void info_print_graph(ss_resolve_t *res, depth_t *depth, int last) if (buffer_putsflush(buffer_1,"\n") < 0) return ; } -int info_cmpnsort(genalloc *ga) +int info_cmpnsort(stralloc *sa) { - unsigned int len = genalloc_len(stralist,ga) ; - if (!len) return 0 ; - char names[len][4096] ; + size_t pos = 0 ; + if (!sa->len) return 0 ; + size_t salen = sa->len ; + size_t nel = sastr_len(sa), idx = 0, a = 0, b = 0 ; + char names[nel][4096] ; char tmp[4096] ; - for (unsigned int i = 0 ; i < genalloc_len(stralist,ga) ; i++) + + for (; pos < salen && idx < nel ; pos += strlen(sa->s + pos) + 1,idx++) { - memcpy(names[i],gaistr(ga,i),gaistrlen(ga,i)) ; + memcpy(names[idx],sa->s + pos,strlen(sa->s + pos)) ; + names[idx][strlen(sa->s+pos)] = 0 ; } - genalloc_deepfree(stralist,ga,stra_free) ; - for (unsigned int i = 0 ; i < len - 1 ; i++) + for (; a < nel - 1 ; a++) { - for (unsigned int j = i+1 ; j < len ; j++) + for (b = a + 1 ; b < idx ; b++) { - if (strcmp(names[i],names[j]) > 0) + if (strcmp(names[a],names[b]) > 0) { - strcpy(tmp,names[i]) ; - strcpy(names[i],names[j]); - strcpy(names[j],tmp); + strcpy(tmp,names[a]) ; + strcpy(names[a],names[b]); + strcpy(names[b],tmp); } } } - - for (unsigned int i = 0 ; i < len ; i++) + sa->len = 0 ; + for (a = 0 ; a < nel ; a++) { - if (!stra_add(ga,names[i])) return 0 ; + if (!sastr_add_string(sa,names[a])) return 0 ; } return 1 ; } int info_walk(ss_resolve_t *res,char const *src,int reverse, depth_t *depth) { - genalloc gadeps = GENALLOC_ZERO ; + size_t pos = 0 ; + stralloc sadeps = STRALLOC_ZERO ; ss_resolve_t dres = RESOLVE_ZERO ; if((!res->ndeps) || (depth->level > MAXDEPTH)) goto freed ; - - if (!clean_val(&gadeps,res->sa.s + res->deps)) goto err ; - if (reverse) genalloc_reverse(stralist,&gadeps) ; - for(unsigned int i = 0 ; i < res->ndeps ; i++ ) + + if (!sastr_clean_string(&sadeps,res->sa.s + res->deps)) goto err ; + if (reverse) stralloc_reverse(&sadeps) ; + for(; pos < sadeps.len ; pos += strlen(sadeps.s + pos) +1 ) { - int last = i + 1 < res->ndeps ? 0 : 1 ; - char *name = gaistr(&gadeps,i) ; + int last = pos + 1 < res->ndeps ? 0 : 1 ; + char *name = sadeps.s + pos ; if (!ss_resolve_check(src,name)) goto err ; if (!ss_resolve_read(&dres,src,name)) goto err ; @@ -379,11 +383,11 @@ int info_walk(ss_resolve_t *res,char const *src,int reverse, depth_t *depth) } freed: ss_resolve_free(&dres) ; - genalloc_deepfree(stralist,&gadeps,stra_free) ; + stralloc_free(&sadeps) ; return 1 ; err: ss_resolve_free(&dres) ; - genalloc_deepfree(stralist,&gadeps,stra_free) ; + stralloc_free(&sadeps) ; return 0 ; } @@ -392,8 +396,9 @@ int info_walk(ss_resolve_t *res,char const *src,int reverse, depth_t *depth) int graph_display(char const *tree,char const *name,unsigned int what) { int e ; + size_t pos = 0, i = 0 ; ss_resolve_t res = RESOLVE_ZERO ; - genalloc tokeep = GENALLOC_ZERO ; //stralist + stralloc tokeep = STRALLOC_ZERO ; ss_resolve_graph_t graph = RESOLVE_GRAPH_ZERO ; stralloc inres = STRALLOC_ZERO ; e = 0 ; @@ -417,18 +422,18 @@ int graph_display(char const *tree,char const *name,unsigned int what) if (!what) { - if (!dir_get(&tokeep,srcres,SS_MASTER+1,S_IFREG)) goto err ; - if (genalloc_len(stralist,&tokeep)) + if (!sastr_dir_get(&tokeep,srcres,SS_MASTER+1,S_IFREG)) goto err ; + if (tokeep.len) { - for (unsigned int i = 0 ; i < genalloc_len(stralist,&tokeep) ; i++) + for(; pos < tokeep.len ; pos += strlen(tokeep.s + pos) +1 ) { - - if (!ss_resolve_check(src,gaistr(&tokeep,i))) goto err ; - if (!ss_resolve_read(&res,src,gaistr(&tokeep,i))) goto err ; + char *name = tokeep.s + pos ; + if (!ss_resolve_check(src,name)) goto err ; + if (!ss_resolve_read(&res,src,name)) goto err ; if (!ss_resolve_graph_build(&graph,&res,src,REVERSE)) goto err ; } if (!ss_resolve_graph_publish(&graph,REVERSE)) goto err ; - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&graph.sorted) ; i++) + for (; i < genalloc_len(ss_resolve_t,&graph.sorted) ; i++) { char *string = genalloc_s(ss_resolve_t,&graph.sorted)[i].sa.s ; char *name = string + genalloc_s(ss_resolve_t,&graph.sorted)[i].name ; @@ -457,7 +462,7 @@ int graph_display(char const *tree,char const *name,unsigned int what) } ss_resolve_free(&res) ; - genalloc_deepfree(stralist,&tokeep,stra_free) ; + stralloc_free(&tokeep) ; ss_resolve_graph_free(&graph) ; stralloc_free(&inres) ; return 1 ; @@ -466,7 +471,7 @@ int graph_display(char const *tree,char const *name,unsigned int what) e = -1 ; err: ss_resolve_free(&res) ; - genalloc_deepfree(stralist,&tokeep,stra_free) ; + stralloc_free(&tokeep) ; ss_resolve_graph_free(&graph) ; stralloc_free(&inres) ; return e ; @@ -475,8 +480,8 @@ int graph_display(char const *tree,char const *name,unsigned int what) int tree_args(int argc, char const *const *argv) { int r ; - size_t newlen ; - genalloc gatree = GENALLOC_ZERO ;// stralist, all tree + size_t newlen, pos = 0 ; + stralloc satree = STRALLOC_ZERO ;//all tree stralloc tree = STRALLOC_ZERO ; stralloc sacurrent = STRALLOC_ZERO ; stralloc currname = STRALLOC_ZERO ; @@ -542,15 +547,15 @@ int tree_args(int argc, char const *const *argv) if (todisplay) if (!dir_search(src.s,argv[0],S_IFDIR)) strerr_dief2x(110,"unknown tree: ",argv[0]) ; - if (!dir_get(&gatree, src.s,SS_BACKUP + 1, S_IFDIR)) goto err ; - if (genalloc_len(stralist,&gatree)) + if (!sastr_dir_get(&satree, src.s,SS_BACKUP + 1, S_IFDIR)) goto err ; + if (satree.len) { - if (!info_cmpnsort(&gatree)) strerr_diefu1x(111,"sort list of tree") ; - for (unsigned int i = 0 ; i < genalloc_len(stralist,&gatree) ; i++) + if (!info_cmpnsort(&satree)) strerr_diefu1x(111,"sort list of tree") ; + for(; pos < satree.len ; pos += strlen(satree.s + pos) +1 ) { tree.len = 0 ; - char *treename = gaistr(&gatree,i) ; + char *treename = satree.s + pos ; if (todisplay) if (!obstr_equal(treename,argv[0])) continue ; @@ -594,7 +599,7 @@ int tree_args(int argc, char const *const *argv) stralloc_free(&src) ; stralloc_free(&sacurrent) ; stralloc_free(&currname) ; - genalloc_deepfree(stralist,&gatree,stra_free) ; + stralloc_free(&satree) ; return 1 ; @@ -604,7 +609,7 @@ int tree_args(int argc, char const *const *argv) stralloc_free(&src) ; stralloc_free(&sacurrent) ; stralloc_free(&currname) ; - genalloc_deepfree(stralist,&gatree,stra_free) ; + stralloc_free(&satree) ; return 0 ; } @@ -612,10 +617,10 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) { int r, found ; unsigned int nlog = 0 ; - + size_t pos = 0 ; stralloc treename = STRALLOC_ZERO ; stralloc tree = STRALLOC_ZERO ; - genalloc gatree = GENALLOC_ZERO ; + stralloc satree = STRALLOC_ZERO ; stralloc src = STRALLOC_ZERO ; stralloc conf = STRALLOC_ZERO ; stralloc env = STRALLOC_ZERO ; @@ -679,15 +684,15 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) if (!stralloc_0(&src)) goto err ; - if (!dir_get(&gatree, src.s,SS_BACKUP+1, S_IFDIR)) + if (!sastr_dir_get(&satree, src.s,SS_BACKUP+1, S_IFDIR)) strerr_diefu2x(111,"get tree from directory: ",src.s) ; - if (genalloc_len(stralist,&gatree)) + if (satree.len) { - for (unsigned int i = 0 ; i < genalloc_len(stralist,&gatree) ; i++) + for(; pos < satree.len ; pos += strlen(satree.s + pos) +1 ) { src.len = newlen ; - char *name = gaistr(&gatree,i) ; + char *name = satree.s + pos ; if (!stralloc_cats(&src,name)) goto err ; if (!stralloc_cats(&src,SS_SVDIRS)) goto err ; @@ -821,7 +826,7 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) end: stralloc_free(&tree) ; stralloc_free(&treename) ; - genalloc_deepfree(stralist,&gatree,stra_free) ; + stralloc_free(&satree) ; ss_resolve_free(&res) ; stralloc_free(&src) ; stralloc_free(&conf) ; @@ -831,7 +836,7 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) err: stralloc_free(&tree) ; stralloc_free(&treename) ; - genalloc_deepfree(stralist,&gatree,stra_free) ; + stralloc_free(&satree) ; ss_resolve_free(&res) ; stralloc_free(&src) ; stralloc_free(&conf) ; diff --git a/src/66/66-parser.c b/src/66/66-parser.c index 846bdc65fa3420a54a3d94721cb84bed4c6c5c15..4bf607de84386bbdfc521e095fd795222917428c 100644 --- a/src/66/66-parser.c +++ b/src/66/66-parser.c @@ -16,6 +16,7 @@ #include <stdlib.h> #include <stdio.h> #include <errno.h> +#include <stdint.h> #include <oblibs/error2.h> #include <oblibs/files.h> @@ -30,6 +31,7 @@ #include <66/utils.h> #include <66/parser.h> +#include <66/constants.h> #define USAGE "66-parser [ -h ] [ -v verbosity ] [ -f ] [ -c|C ] service destination" @@ -50,14 +52,9 @@ static inline void info_help (void) strerr_diefu1sys(111, "write to stdout") ; } -static void check_dir(char const *dir,int force,int main) +static void check_dir(char const *dir,uint8_t force,int main) { int r ; - size_t dirlen = strlen(dir) ; - char tmp[dirlen+1] ; - if (!dirname(tmp,dir)) strerr_diefu1x(111,"set directory name") ; - char name[dirlen+1] ; - if (!basename(name,dir)) strerr_diefu1x(111,"set name") ; r = scan_mode(dir,S_IFDIR) ; if (r < 0){ errno = ENOTDIR ; strerr_dief2sys(111,"conflicting format of: ",dir) ; } @@ -69,7 +66,7 @@ static void check_dir(char const *dir,int force,int main) } else if (r && !force && main) strerr_dief3x(111,"destination: ",dir," already exist") ; if (!r) - if (!dir_create_under(tmp,name, 0755)) strerr_diefu2sys(111,"create: ",dir) ; + if (!dir_create_parent(dir, 0755)) strerr_diefu2sys(111,"create: ",dir) ; } int main(int argc, char const *const *argv,char const *const *envp) @@ -85,7 +82,7 @@ int main(int argc, char const *const *argv,char const *const *envp) char name[4095+1] ; char srcdir[4095+1] ; int type ; - unsigned int force = 0 , conf = 0 ; + uint8_t force = 0 , conf = 0 ; PROG = "66-parser" ; { subgetopt_t l = SUBGETOPT_ZERO ; @@ -131,11 +128,11 @@ int main(int argc, char const *const *argv,char const *const *envp) check_dir(dir,force,0) ; if (!stralloc_cats(&insta,name) || !stralloc_0(&insta)) retstralloc(111,"main") ; - r = insta_check(insta.s) ; + r = instance_check(insta.s) ; if (!r) strerr_dief2x(111,"invalid instance name: ",insta.s) ; if (r > 0) { - if (!insta_create(&src,&insta,srcdir,r)) + if (!instance_create(&src,insta.s,SS_INSTANCE,srcdir,r)) strerr_diefu2x(111,"create instance service: ",name) ; memcpy(name,insta.s,insta.len) ; name[insta.len] = 0 ; diff --git a/src/66/66-scandir.c b/src/66/66-scandir.c index 390f8ec034eea0abe333f06c246fd315b5fd62cb..05243175028cb631dacc677b46c43556e946382a 100644 --- a/src/66/66-scandir.c +++ b/src/66/66-scandir.c @@ -17,6 +17,7 @@ #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> +#include <sys/stat.h> //#include <stdio.h> #include <oblibs/obgetopt.h> @@ -25,6 +26,7 @@ #include <oblibs/types.h> #include <oblibs/files.h> #include <oblibs/string.h> +#include <oblibs/environ.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> @@ -61,7 +63,7 @@ static gid_t GIDOWNER ; static char GIDSTR[GID_FMT] ; static char TMPENV[MAXENV+1] ; static char const *skel = SS_SKEL_DIR ; -static char const *log_user = "root" ; +static char const *log_user = SS_LOGGER_RUNNER ; static unsigned int BOOT = 0 ; unsigned int VERBOSITY = 1 ; unsigned int NOTIF = 0 ; @@ -191,7 +193,7 @@ static void inline auto_rm(char const *str) r = scan_mode(str,S_IFDIR) ; if (r > 0) { - VERBO2 strerr_warni3x("removing ",str," ...") ; + VERBO1 strerr_warni3x("removing ",str," ...") ; if (rm_rf(str) < 0) strerr_diefu2sys(111,"remove: ",str) ; } } @@ -264,15 +266,13 @@ void write_bootlog(char const *live, char const *scandir) * /run/66/log*/ memcpy(path,live,livelen) ; memcpy(path+livelen,"log",3) ; - path[livelen + 3] = 0 ; - log_perm(log_user,&uid,&gid) ; - VERBO3 strerr_warnt4x("create directory: ",path,"/",OWNERSTR) ; - r = dir_create_under(path,OWNERSTR,02750) ; - if (r < 0) strerr_diefu3sys(111,"create: ",path,OWNERSTR) ; - /** chown /run/66/log/<uid>*/ path[livelen + 3] = '/' ; memcpy(path + livelen + 4,OWNERSTR,ownerlen) ; path[livelen + 4 + ownerlen] = 0 ; + VERBO3 strerr_warnt2x("create directory: ",path) ; + r = dir_create_parent(path,02750) ; + if (!r) strerr_diefu2sys(111,"create: ",path) ; + log_perm(log_user,&uid,&gid) ; if (chown(path,uid,gid) < 0) strerr_diefu2sys(111,"chown: ",path) ; auto_chmod(path,02755) ; @@ -549,7 +549,7 @@ int main(int argc, char const *const *argv, char const *const *envp) if (envdir.s[0] != '/') strerr_dief3x(110,"environment: ",envdir.s," must be an absolute path") ; - if (!build_env(envdir.s,envp,newenv,TMPENV)) strerr_diefu2x(111,"build environment with: ",envdir.s) ; + if (!environ_get_envfile_n_merge(envdir.s,envp,newenv,TMPENV)) strerr_diefu2x(111,"build environment with: ",envdir.s) ; genv = newenv ; } else genv = envp ; diff --git a/src/66/66-shutdownd.c b/src/66/66-shutdownd.c index bf44212a032d8a1ba05898bc99c5ede09bcce382..7822fd13f91ff89c8d55ff5a86d3be12c8fcaadc 100644 --- a/src/66/66-shutdownd.c +++ b/src/66/66-shutdownd.c @@ -26,6 +26,9 @@ #include <stdio.h> #include <sys/wait.h> +#include <oblibs/environ.h> +#include <oblibs/files.h> + #include <skalibs/posixplz.h> #include <skalibs/uint32.h> #include <skalibs/types.h> @@ -40,7 +43,6 @@ #include <skalibs/djbunix.h> #include <skalibs/iopause.h> #include <skalibs/skamisc.h> -#include <skalibs/diuint32.h> #include <execline/config.h> @@ -48,7 +50,6 @@ #include <66/config.h> #include <66/constants.h> -#include <66/environ.h> #define STAGE4_FILE "stage4" #define DOTPREFIX ".66-shutdownd:" @@ -104,47 +105,39 @@ ssize_t file_get_size(const char* filename) return st.st_size; } -static void parse_conf(char const *confile,char *rcshut,size_t filesize) +static inline void auto_conf(char *confile,size_t conflen) +{ + memcpy(confile,conf,conflen) ; + confile[conflen] = '/' ; + memcpy(confile + conflen + 1, SS_BOOT_CONF, SS_BOOT_CONF_LEN) ; + confile[conflen + 1 + SS_BOOT_CONF_LEN] = 0 ; +} + +static void parse_conf(char const *confile,char *rcshut,char const *key) { int r ; - unsigned int i = 0 ; stralloc src = STRALLOC_ZERO ; - stralloc saconf = STRALLOC_ZERO ; - genalloc gaconf = GENALLOC_ZERO ; + size_t filesize = file_get_size(confile) ; r = openreadfileclose(confile,&src,filesize) ; if(!r) strerr_diefu2sys(111,"open configuration file: ",confile) ; if (!stralloc_0(&src)) strerr_diefu1sys(111,"append stralloc configuration file") ; - r = env_split(&gaconf,&saconf,&src) ; - if (!r) strerr_diefu2sys(111,"parse configuration file: ",confile) ; - - for (;i < genalloc_len(diuint32,&gaconf) ; i++) + if (environ_get_val_of_key(&src,key)) { - char *key = saconf.s + genalloc_s(diuint32,&gaconf)[i].left ; - char *val = saconf.s + genalloc_s(diuint32,&gaconf)[i].right ; - if (!strcmp(key,"RCSHUTDOWN")) - { - memcpy(rcshut,val,strlen(val)) ; - rcshut[strlen(val)] = 0 ; - } + memcpy(rcshut,src.s,src.len) ; + rcshut[src.len] = 0 ; } - genalloc_free(diuint32,&gaconf) ; - stralloc_free(&saconf) ; stralloc_free(&src) ; } static inline void run_rcshut (char const *const *envp) { pid_t pid ; - size_t filesize, conflen = strlen(conf) ; + size_t conflen = strlen(conf) ; + char rcshut[4096] ; char confile[conflen + 1 + SS_BOOT_CONF_LEN] ; - memcpy(confile,conf,conflen) ; - confile[conflen] = '/' ; - memcpy(confile + conflen + 1, SS_BOOT_CONF, SS_BOOT_CONF_LEN) ; - confile[conflen + 1 + SS_BOOT_CONF_LEN] = 0 ; - filesize=file_get_size(confile) ; - char rcshut[filesize+1] ; - parse_conf(confile,rcshut,filesize) ; + auto_conf(confile,conflen) ; + parse_conf(confile,rcshut,"RCSHUTDOWN") ; char const *rcshut_argv[3] = { rcshut, confile, 0 } ; pid = child_spawn0(rcshut_argv[0], rcshut_argv, envp) ; if (pid) @@ -214,6 +207,11 @@ static inline void prepare_stage4 (char what) buffer b ; int fd ; char buf[512] ; + char shutfinal[4096] ; //huge path allowed + size_t conflen = strlen(conf) ; + char confile[conflen + 1 + SS_BOOT_CONF_LEN] ; + auto_conf(confile,conflen) ; + parse_conf(confile,shutfinal,"RCSHUTDOWNFINAL") ; unlink_void(STAGE4_FILE ".new") ; fd = open_excl(STAGE4_FILE ".new") ; if (fd == -1) strerr_diefu3sys(111, "open ", STAGE4_FILE ".new", " for writing") ; @@ -223,6 +221,9 @@ static inline void prepare_stage4 (char what) "#!" SS_EXECLINE_SHEBANGPREFIX "execlineb -P\n\n" EXECLINE_EXTBINPREFIX "foreground { " SS_BINPREFIX "66-umountall }\n" + EXECLINE_EXTBINPREFIX "foreground { ") < 0 + || buffer_put(&b,shutfinal,strlen(shutfinal)) < 0 + || buffer_puts(&b," }\n" SS_BINPREFIX "66-hpr -f -") < 0 || buffer_put(&b, &what, 1) < 0 || buffer_putsflush(&b, "\n") < 0) strerr_diefu2sys(111, "write to ", STAGE4_FILE ".new") ; diff --git a/src/66/66-tree.c b/src/66/66-tree.c index e18d5b0984e5cb3673e8b2352228d3babf5c24d9..f37d0a47026cab7e0d90f99263fb6c72cd337d79 100644 --- a/src/66/66-tree.c +++ b/src/66/66-tree.c @@ -47,6 +47,7 @@ unsigned int VERBOSITY = 1 ; static stralloc reslive = STRALLOC_ZERO ; +static char const *cleantree = 0 ; static inline void info_help (void) { @@ -72,140 +73,118 @@ static inline void info_help (void) strerr_diefu1sys(111, "write to stdout") ; } -void cleanup(char const *tree){ +static void cleanup(char const *tree){ VERBO3 strerr_warnt3x("removing ",tree," ...") ; rm_rf(tree) ; } -int sanitize_extra(char const *dst) +static void auto_string(char *string,char const *str,size_t baselen) { - int r ; - size_t dstlen, slash ; - dstlen = strlen(dst) - 1 ;//-1 remove last slash - char parentdir[dstlen + 1] ; - memcpy(parentdir,dst,dstlen) ; - slash = get_rlen_until(dst,'/',dstlen) ; - parentdir[slash] = '\0' ; - r = dir_create_under(parentdir,dst+slash+1,0755) ; - - return r ; + size_t slen = strlen(str) ; + memcpy(string + baselen,str,slen) ; + string[baselen+slen] = 0 ; +} + +static void auto_dir(char const *dst,mode_t mode) +{ + VERBO3 strerr_warnt2x("create directory: ",dst) ; + if (!dir_create_parent(dst,mode)) + { + if (cleantree) cleanup(cleantree) ; + strerr_diefu2sys(111,"create directory: ",dst) ; + } +} + +static void auto_create(char *string,char const *str,size_t baselen,mode_t mode) +{ + auto_string(string,str,baselen) ; + auto_dir(string,mode) ; +} + +static void auto_check(char *dst,char const *str,size_t baselen,mode_t mode) +{ + auto_string(dst,str,baselen) ; + if (!scan_mode(dst,mode)) auto_dir(dst,0755) ; } static void inline auto_stralloc(stralloc *sa,char const *str) { if (!stralloc_cats(sa,str)) strerr_diefu1sys(111,"append stralloc") ; } + static void inline auto_stralloc0(stralloc *sa) { if (!stralloc_0(sa)) strerr_diefu1sys(111,"append stralloc") ; sa->len-- ; } + +static void inline auto_stralloc_0(stralloc *sa,char const *str) +{ + auto_stralloc(sa,str) ; + auto_stralloc0(sa) ; +} + int sanitize_tree(stralloc *dstree, char const *base, char const *tree,uid_t owner) { ssize_t r ; size_t baselen = strlen(base) ; char dst[baselen + SS_SYSTEM_LEN + 1] ; - - memcpy(dst,base,baselen) ; - dst[baselen] = 0 ; - + auto_string(dst,base,0) ; + /** base is /var/lib/66 or $HOME/.66*/ /** this verification is made in case of * first use of 66-*** tools */ r = scan_mode(dst,S_IFDIR) ; - if (r < 0) - { - VERBO3 strerr_warnwu2x("invalid directorey: ",dst) ; - return -1 ; - } + if (r < 0) strerr_diefu2x(111,"invalid directory: ",dst) ; + if(!r) { VERBO3 strerr_warnt3x("create directory: ",dst,SS_SYSTEM) ; - r = dir_create_under(dst,SS_SYSTEM,0755) ; - if (!r){ - VERBO3 strerr_warnwu3sys("create ",dst,SS_SYSTEM) ; - return -1 ; - } + auto_create(dst,SS_SYSTEM,baselen,0755) ; /** create extra directory for service part */ if (!owner) { - if (sanitize_extra(SS_LOGGER_SYSDIR) < 0) - { VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; } - if (sanitize_extra(SS_SERVICE_SYSDIR) < 0) - { VERBO3 strerr_warnwu2sys("create directory: ",SS_SERVICE_SYSDIR) ; return -1 ; } - if (sanitize_extra(SS_SERVICE_ADMDIR) < 0) - { VERBO3 strerr_warnwu2sys("create directory: ",SS_SERVICE_ADMDIR) ; return -1 ; } - if (sanitize_extra(SS_SERVICE_ADMCONFDIR) < 0) - { VERBO3 strerr_warnwu2sys("create directory: ",SS_SERVICE_ADMCONFDIR) ; return -1 ; } + auto_dir(SS_LOGGER_SYSDIR,0755) ; + auto_dir(SS_SERVICE_SYSDIR,0755) ; + auto_dir(SS_SERVICE_ADMDIR,0755) ; + auto_dir(SS_SERVICE_ADMCONFDIR,0755) ; } else { size_t extralen ; stralloc extra = STRALLOC_ZERO ; if (!set_ownerhome(&extra,owner)) - { - VERBO3 strerr_warnwu1sys("set home directory") ; - return -1 ; - } + strerr_diefu1sys(111,"set home directory") ; + extralen = extra.len ; - if (!stralloc_cats(&extra,SS_LOGGER_USERDIR)) retstralloc(0,"sanitize_tree") ; - if (!stralloc_0(&extra)) retstralloc(0,"sanitize_tree") ; - if (sanitize_extra(extra.s) < 0) - { VERBO3 strerr_warnwu2sys("create directory: ",extra.s) ; return -1 ; } + auto_stralloc_0(&extra,SS_LOGGER_USERDIR) ; + auto_dir(extra.s,0755) ; extra.len = extralen ; - if (!stralloc_cats(&extra,SS_SERVICE_USERDIR)) retstralloc(0,"sanitize_tree") ; - if (!stralloc_0(&extra)) retstralloc(0,"sanitize_tree") ; - if (sanitize_extra(extra.s) < 0) - { VERBO3 strerr_warnwu2sys("create directory: ",extra.s) ; return -1 ; } + auto_stralloc_0(&extra,SS_SERVICE_USERDIR) ; + auto_dir(extra.s,0755) ; extra.len = extralen ; - if (!stralloc_cats(&extra,SS_SERVICE_USERCONFDIR)) retstralloc(0,"sanitize_tree") ; - if (!stralloc_0(&extra)) retstralloc(0,"sanitize_tree") ; - if (sanitize_extra(extra.s) < 0) - { VERBO3 strerr_warnwu2sys("create directory: ",extra.s) ; return -1 ; } + auto_stralloc_0(&extra,SS_SERVICE_USERCONFDIR) ; + auto_dir(extra.s,0755) ; stralloc_free(&extra) ; } } - if (!dir_search(dst,SS_TREE_CURRENT,S_IFDIR)) - { - VERBO3 strerr_warnt3x("create directory: ",dst,SS_TREE_CURRENT) ; - r = dir_create_under(dst,SS_TREE_CURRENT,0755) ; - if (!r){ - VERBO3 strerr_warnwu3sys("create ",dst,SS_TREE_CURRENT) ; - return -1 ; - } - } - memcpy(dst + baselen, SS_SYSTEM, SS_SYSTEM_LEN) ; - dst[baselen + SS_SYSTEM_LEN] = 0 ; - if (!dir_search(dst,SS_BACKUP + 1,S_IFDIR)) - { - VERBO3 strerr_warnt3x("create directory: ",dst,SS_BACKUP) ; - if(!dir_create_under(dst,SS_BACKUP + 1,0755)) - { - VERBO3 strerr_warnwu3sys("create ",dst,SS_BACKUP) ; - return -1 ; - } - } - if (!dir_search(dst,SS_STATE + 1,S_IFREG)) + auto_check(dst,SS_TREE_CURRENT,baselen,0755) ; + auto_string(dst,SS_SYSTEM,baselen) ; + auto_check(dst,SS_BACKUP,baselen + SS_SYSTEM_LEN,0755) ; + auto_string(dst,SS_STATE,baselen + SS_SYSTEM_LEN) ; + if (!scan_mode(dst,S_IFREG)) { - VERBO3 strerr_warnt3x("create file: ",dst,SS_STATE) ; + auto_string(dst,SS_SYSTEM,baselen) ; if(!file_create_empty(dst,SS_STATE + 1,0644)) - { - VERBO3 strerr_warnwu3sys("create ",dst,SS_STATE) ; - return -1 ; - } - } - - r = dir_search(dst,tree,S_IFDIR) ; - if (r < 0){ - VERBO3 strerr_warnw3x(dst,tree," is not a directory") ; - return -1 ; + strerr_diefu3sys(111,"create ",dst,SS_STATE) ; } - + auto_string(dst,"/",baselen + SS_SYSTEM_LEN) ; + auto_string(dst,tree,baselen + SS_SYSTEM_LEN + 1) ; + r = scan_mode(dst,S_IFDIR) ; + if (r == -1) strerr_dief2x(111,"invalid directory: ",dst) ; /** we have one, keep it*/ if (!stralloc_cats(dstree,dst)) retstralloc(0,"sanitize_tree") ; - if (!stralloc_cats(dstree,"/")) retstralloc(0,"sanitize_tree") ; - if (!stralloc_cats(dstree,tree)) retstralloc(0,"sanitize_tree") ; if (!stralloc_0(dstree)) retstralloc(0,"sanitize_tree") ; if (!r) return 0 ; @@ -213,11 +192,11 @@ int sanitize_tree(stralloc *dstree, char const *base, char const *tree,uid_t own return 1 ; } -int create_tree(char const *tree,char const *treename) +void create_tree(char const *tree,char const *treename) { size_t newlen = 0 ; size_t treelen = strlen(tree) ; - + char dst[treelen + SS_DB_LEN + SS_SRC_LEN + 13 + 1] ; ss_resolve_t res = RESOLVE_ZERO ; ss_resolve_init(&res) ; @@ -233,172 +212,100 @@ int create_tree(char const *tree,char const *treename) res.type = BUNDLE ; res.disen = 1 ; - VERBO3 strerr_warnt3x("create directory: ",dst,SS_SVDIRS) ; - if(!dir_create_under(dst,SS_SVDIRS + 1,0755)) - { - VERBO3 strerr_warnwu3sys("create ",dst,SS_SVDIRS) ; - return 0 ; - } - VERBO3 strerr_warnt3x("create directory: ",dst,SS_RULES) ; - if (!dir_create_under(dst,SS_RULES + 1,0755)){ - VERBO3 strerr_warnwu3sys("create ",dst,SS_RULES) ; - return 0 ; - } - - memcpy(dst + newlen,SS_SVDIRS,SS_SVDIRS_LEN) ; + auto_create(dst,SS_SVDIRS,newlen,0755) ; + auto_create(dst,SS_RULES,newlen,0755) ; + auto_string(dst,SS_SVDIRS,newlen) ; newlen = newlen + SS_SVDIRS_LEN ; + auto_create(dst,SS_DB,newlen,0755) ; + auto_create(dst,SS_SVC,newlen,0755) ; + auto_create(dst,SS_RESOLVE,newlen,0755) ; dst[newlen] = 0 ; - - VERBO3 strerr_warnt3x("create directory: ",dst,SS_DB) ; - if (!dir_create_under(dst,SS_DB + 1,0755)) - { - VERBO3 strerr_warnwu3sys("create ",dst,SS_DB) ; - return 0 ; - } - VERBO3 strerr_warnt3x("create directory: ",dst,SS_SVC) ; - if (!dir_create_under(dst,SS_SVC + 1,0755)) - { - VERBO3 strerr_warnwu3sys("create ",dst,SS_DB) ; - return 0 ; - } - - VERBO3 strerr_warnt3x("create directory: ",dst,SS_RESOLVE) ; - if (!dir_create_under(dst,SS_RESOLVE + 1,0755)) - { - VERBO3 strerr_warnwu3sys("create ",dst,SS_RESOLVE) ; - return 0 ; - } - VERBO3 strerr_warnt1x("write resolve file of inner bundle") ; if (!ss_resolve_write(&res,dst,SS_MASTER+1)) { - VERBO3 strerr_warnwu1sys("write resolve file of inner bundle") ; ss_resolve_free(&res) ; - return 0 ; + cleanup(cleantree) ; + strerr_diefu1sys(111,"write resolve file of inner bundle") ; } ss_resolve_free(&res) ; char sym[newlen + 1 + SS_SYM_SVC_LEN + 1] ; char dstsym[newlen + SS_SVC_LEN + 1] ; - - memcpy(sym,dst,newlen) ; - sym[newlen] = '/' ; - - memcpy(sym + newlen + 1, SS_SYM_SVC, SS_SYM_SVC_LEN) ; - sym[newlen + 1 + SS_SYM_SVC_LEN] = 0 ; - - - memcpy(dstsym,dst,newlen) ; - memcpy(dstsym + newlen, SS_SVC, SS_SVC_LEN) ; - dstsym[newlen + SS_SVC_LEN] = 0 ; + auto_string(sym,dst,0) ; + auto_string(sym,"/",newlen) ; + auto_string(sym,SS_SYM_SVC,newlen + 1) ; + + auto_string(dstsym,dst,0) ; + auto_string(dstsym,SS_SVC,newlen) ; VERBO3 strerr_warnt4x("point symlink: ",sym," to ",dstsym) ; if (symlink(dstsym,sym) < 0) { - VERBO3 strerr_warnwu2sys("symlink: ", sym) ; - return 0 ; + cleanup(cleantree) ; + strerr_diefu2sys(111,"symlink: ", sym) ; } - memcpy(sym + newlen + 1, SS_SYM_DB, SS_SYM_DB_LEN) ; - sym[newlen + 1 + SS_SYM_DB_LEN] = 0 ; - - - memcpy(dstsym,dst,newlen) ; - memcpy(dstsym + newlen, SS_DB, SS_DB_LEN) ; - dstsym[newlen + SS_DB_LEN] = 0 ; - + auto_string(sym,SS_SYM_DB,newlen + 1) ; + auto_string(dstsym,SS_DB,newlen) ; VERBO3 strerr_warnt4x("point symlink: ",sym," to ",dstsym) ; if (symlink(dstsym,sym) < 0) { - VERBO3 strerr_warnwu2sys("symlink: ", sym) ; - return 0 ; + cleanup(cleantree) ; + strerr_diefu2sys(111,"symlink: ", sym) ; } - - memcpy(dst + newlen,SS_DB,SS_DB_LEN) ; + + auto_string(dst,SS_DB,newlen) ; newlen = newlen + SS_DB_LEN ; - dst[newlen] = 0 ; - - VERBO3 strerr_warnt3x("create directory: ",dst,SS_SRC) ; - if (!dir_create_under(dst,SS_SRC,0755)) - { - VERBO3 strerr_warnwu3sys("create ",dst,SS_SRC) ; - return 0 ; - } - - memcpy(dst + newlen,SS_SRC,SS_SRC_LEN) ; + auto_create(dst,SS_SRC,newlen,0755) ; + auto_string(dst,SS_SRC,newlen) ; newlen = newlen + SS_SRC_LEN ; - dst[newlen] = 0 ; - - - VERBO3 strerr_warnt3x("create directory: ",dst,SS_MASTER) ; - if(!dir_create_under(dst,SS_MASTER + 1,0755)) - { - VERBO3 strerr_warnwu3sys("create ",dst,SS_MASTER) ; - return 0 ; - } - - memcpy(dst + newlen,SS_MASTER,SS_MASTER_LEN) ; + auto_create(dst,SS_MASTER,newlen,0755) ; + auto_string(dst,SS_MASTER,newlen) ; newlen = newlen + SS_MASTER_LEN ; - dst[newlen] = 0 ; - VERBO3 strerr_warnt3x("create file: ",dst,"/contents") ; if (!file_create_empty(dst,"contents",0644)) { - VERBO3 strerr_warnwu3sys("create ",dst,"/contents") ; - return 0 ; + cleanup(cleantree) ; + strerr_diefu3sys(111,"create ",dst,"/contents") ; } - memcpy(dst + newlen,"/type",5) ; - newlen = newlen + 5 ; - dst[newlen] = 0 ; - + auto_string(dst,"/type",newlen) ; VERBO3 strerr_warnt2x("create file: ",dst) ; if(!openwritenclose_unsafe(dst,"bundle\n",7)) { - VERBO3 strerr_warnwu2sys("write ",dst) ; - return 0 ; + cleanup(cleantree) ; + strerr_diefu2sys(111,"write ",dst) ; } - - return 1 ; + } -int create_backupdir(char const *base, char const *treename) +void create_backupdir(char const *base, 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) ; - treetmp[baselen] = '/' ; - memcpy(treetmp + baselen + 1, SS_SYSTEM, SS_SYSTEM_LEN) ; - memcpy(treetmp + baselen + 1 + SS_SYSTEM_LEN, SS_BACKUP, SS_BACKUP_LEN) ; - treetmp[baselen + 1 + SS_SYSTEM_LEN + SS_BACKUP_LEN] = '/' ; - 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 ; + auto_string(treetmp,base,0) ; + auto_string(treetmp,"/",baselen) ; + auto_string(treetmp,SS_SYSTEM,baselen + 1) ; + auto_string(treetmp,SS_BACKUP,baselen + 1 + SS_SYSTEM_LEN) ; + auto_string(treetmp,"/",baselen + 1 + SS_SYSTEM_LEN + SS_BACKUP_LEN) ; + auto_string(treetmp,treename,baselen + 1 + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1) ; + r = scan_mode(treetmp,S_IFDIR) ; - if (r || (r < 0)) + if (r || (r == -1)) { VERBO3 strerr_warnt2x("remove existing backup: ",treetmp) ; if (rm_rf(treetmp) < 0) { - VERBO3 strerr_warnwu2sys("remove: ",treetmp) ; - return 0 ; - } - } - if (!r) - { - VERBO3 strerr_warnt2x("create directory: ",treetmp) ; - if (!dir_create(treetmp,0755)) - { - VERBO3 strerr_warnwu2sys("create directory: ",treetmp) ; - return 0 ; + cleanup(cleantree) ; + strerr_diefu2sys(111,"remove: ",treetmp) ; } } - - return 1 ; + if (!r) auto_dir(treetmp,0755) ; } int set_rules(char const *tree,uid_t *uids, size_t uidn,unsigned int what) @@ -409,10 +316,9 @@ int set_rules(char const *tree,uid_t *uids, size_t uidn,unsigned int what) char pack[256] ; char tmp[treelen + SS_RULES_LEN + 1] ; - memcpy(tmp,tree,treelen) ; - memcpy(tmp + treelen,SS_RULES,SS_RULES_LEN) ; - tmp[treelen + SS_RULES_LEN] = 0 ; - + auto_string(tmp,tree,0) ; + auto_string(tmp,SS_RULES,treelen) ; + if (!uidn && what) { uids[0] = 1 ; @@ -449,7 +355,7 @@ int set_rules(char const *tree,uid_t *uids, size_t uidn,unsigned int what) tmp[treelen + SS_RULES_LEN + 1 + uint_fmt(pack,uids[i + 1])] = 0 ; VERBO3 strerr_warnt2x("unlink: ",tmp) ; r = unlink(tmp) ; - if (r<0) return 0 ; + if (r == -1) return 0 ; } VERBO3 strerr_warnt4x("user: ",pack," is denied for tree: ",tree) ; } @@ -471,10 +377,9 @@ void tree_unsupervise(stralloc *live, char const *tree, char const *treename,uid /** set what we need */ char prefix[treenamelen + 2] ; - memcpy(prefix,treename,treenamelen) ; - memcpy(prefix + treenamelen,"-",1) ; - prefix[treenamelen + 1] = 0 ; - + auto_string(prefix,treename,0) ; + auto_string(prefix,"-",treenamelen) ; + auto_stralloc(&scandir,live->s) ; r = set_livescan(&scandir,owner) ; if (!r) strerr_diefu1sys(111,"set livescan directory") ; @@ -504,7 +409,7 @@ void tree_unsupervise(stralloc *live, char const *tree, char const *treename,uid } { - size_t i = 0, len = byte_count(list.s,list.len,'\0') ; + size_t i = 0, len = sastr_len(&list) ; char const *newargv[9 + len + 1] ; unsigned int m = 0 ; char fmt[UINT_FMT] ; @@ -650,24 +555,19 @@ int main(int argc, char const *const *argv,char const *const *envp) VERBO2 strerr_warni3x("sanitize ",tree," ..." ) ; r = sanitize_tree(&dstree,base.s,tree,owner) ; - if (r < 0){ - strerr_diefu2x(111,"sanitize ",tree) ; - } if(!r && create) { + /** set cleanup */ + cleantree = dstree.s ; VERBO2 strerr_warni3x("creating ",dstree.s," ..." ) ; - if (!create_tree(dstree.s,tree)) - { - cleanup(dstree.s) ; - strerr_diefu2x(111,"create tree: ",dstree.s) ; - } + create_tree(dstree.s,tree) ; + VERBO2 strerr_warni3x("creating backup directory for ", tree," ...") ; - if (!create_backupdir(base.s,tree)) - { - cleanup(dstree.s) ; - strerr_diefu2x(111,"create backup directory for: ",tree) ; - } + create_backupdir(base.s,tree) ; + /** unset cleanup */ + cleantree = 0 ; + VERBO2 strerr_warni3x("set permissions rules for ",dstree.s," ..." ) ; if (!set_rules(dstree.s,auids,auidn,1))//1 allow { @@ -677,9 +577,9 @@ int main(int argc, char const *const *argv,char const *const *envp) size_t dblen = dstree.len - 1 ; char newdb[dblen + SS_SVDIRS_LEN + 1] ; - memcpy(newdb,dstree.s,dblen) ; - memcpy(newdb + dblen, SS_SVDIRS, SS_SVDIRS_LEN) ; - newdb[dblen + SS_SVDIRS_LEN] = 0 ; + auto_string(newdb,dstree.s,0) ; + auto_string(newdb,SS_SVDIRS,dblen) ; + VERBO2 strerr_warni5x("compile ",newdb,"/db/",tree," ..." ) ; if (!db_compile(newdb,dstree.s,tree,envp)) { @@ -689,6 +589,7 @@ int main(int argc, char const *const *argv,char const *const *envp) r = 1 ; create = 0 ; VERBO1 strerr_warni2x("Created successfully tree: ",tree) ; + } if ((!r && !create) || (!r && enable)) strerr_diefu2x(111,"find tree: ",dstree.s) ; @@ -698,17 +599,24 @@ int main(int argc, char const *const *argv,char const *const *envp) { VERBO2 strerr_warni3x("enable ",dstree.s," ..." ) ; r = tree_cmd_state(VERBOSITY,"-a",tree) ; - - if (r != 1) strerr_diefu6x(111,"add: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; - VERBO1 strerr_warni2x("Enabled successfully tree: ",tree) ; + if (!r) strerr_diefu6x(111,"add: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; + else if (r == 1) + { + VERBO1 strerr_warni2x("Enabled successfully tree: ",tree) ; + } + else VERBO1 strerr_warni2x("Already enabled tree: ",tree) ; } if (disable) { VERBO2 strerr_warni3x("disable ",dstree.s," ..." ) ; r = tree_cmd_state(VERBOSITY,"-d",tree) ; - if (r != 1) strerr_diefu6x(111,"remove: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; - VERBO1 strerr_warni2x("Disabled successfully tree: ",tree) ; + if (!r) strerr_diefu6x(111,"remove: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; + else if (r == 1) + { + VERBO1 strerr_warni2x("Disabled successfully tree: ",tree) ; + } + else VERBO1 strerr_warni2x("Already disabled tree: ",tree) ; } if (auidn) @@ -737,26 +645,21 @@ int main(int argc, char const *const *argv,char const *const *envp) size_t treelen = strlen(tree) ; size_t baselen = base.len ; char treetmp[baselen + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + treelen + 1] ; - memcpy(treetmp, base.s, baselen) ; - memcpy(treetmp + baselen, SS_SYSTEM, SS_SYSTEM_LEN) ; - memcpy(treetmp + baselen + SS_SYSTEM_LEN, SS_BACKUP, SS_BACKUP_LEN) ; - memcpy(treetmp + baselen + SS_SYSTEM_LEN + SS_BACKUP_LEN, "/", 1) ; - memcpy(treetmp + baselen + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1, tree, treelen) ; - treetmp[baselen + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + treelen ] = 0 ; - + auto_string(treetmp,base.s,0) ; + auto_string(treetmp,SS_SYSTEM,baselen) ; + auto_string(treetmp,SS_BACKUP,baselen + SS_SYSTEM_LEN) ; + auto_string(treetmp,"/",baselen + SS_SYSTEM_LEN + SS_BACKUP_LEN) ; + auto_string(treetmp,tree,baselen + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1) ; + r = scan_mode(treetmp,S_IFDIR) ; if (r || (r < 0)) { VERBO2 strerr_warni3x("delete backup of tree ",treetmp," ...") ; - if (rm_rf(treetmp) < 0) - { - VERBO3 strerr_warnwu2sys("delete: ",treetmp) ; - return 0 ; - } + if (rm_rf(treetmp) < 0) strerr_diefu2sys(111,"delete: ",treetmp) ; } VERBO2 strerr_warni6x("disable: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; - r = tree_cmd_state(VERBOSITY,"-d",tree) ; - if (r != 1) strerr_diefu6x(111,"delete: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; + if (!tree_cmd_state(VERBOSITY,"-d",tree)) + strerr_diefu6x(111,"disable: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; VERBO1 strerr_warni2x("Deleted successfully: ",tree) ; } @@ -764,13 +667,12 @@ int main(int argc, char const *const *argv,char const *const *envp) if (snap) { char tmp[dstree.len + 1] ; - memcpy(tmp,dstree.s,dstree.len) ; - tmp[dstree.len] = 0 ; + auto_string(tmp,dstree.s,0) ; + r = get_rlen_until(dstree.s,'/',dstree.len) ; dstree.len = r + 1; - - if (!stralloc_cats(&dstree,clone.s)) retstralloc(111,"main") ; - if (!stralloc_0(&dstree)) retstralloc(111,"main") ; + + auto_stralloc_0(&dstree,clone.s) ; r = scan_mode(dstree.s,S_IFDIR) ; if ((r < 0) || r) strerr_dief2x(111,dstree.s,": already exist") ; VERBO2 strerr_warni5x("clone ",dstree.s," as ",tmp," ..." ) ; diff --git a/src/extra-tools/66-envfile.c b/src/extra-tools/66-envfile.c deleted file mode 100644 index 30e5f0ac72559145b33edf30ed654d6c47e9594e..0000000000000000000000000000000000000000 --- a/src/extra-tools/66-envfile.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 66-envfile.c - * - * Copyright (c) 2018-2019 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 <skalibs/djbunix.h> -#include <skalibs/strerr2.h> - -int main (int argc, char const *const *argv, char const *const *envp) -{ - PROG = "66-envfile" ; - int i = 0 ; - strerr_warnw1x("the 66-envfile is obsolescent, please use execl-envfile instead") ; - argv++ ; - char const *cmd[argc] ; - cmd[0] = "execl-envfile" ; - for(; i < argc ;i++) - cmd[i+1] = argv[i] ; - cmd[i+1] = 0 ; - pathexec_run(cmd[0],cmd,envp) ; -} diff --git a/src/extra-tools/66-getenv.c b/src/extra-tools/66-getenv.c deleted file mode 100644 index a4bec9d91f18bc664b04b3fd91696b6ff45d1834..0000000000000000000000000000000000000000 --- a/src/extra-tools/66-getenv.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * 66-getenv.c - * - * Copyright (c) 2018-2019 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 <unistd.h>//read -#include <stdlib.h>//malloc -#include <fcntl.h> -#include <sys/stat.h> -#include <errno.h> -#include <regex.h> - -#include <oblibs/sastr.h> - -#include <skalibs/sgetopt.h> -#include <skalibs/stralloc.h> -#include <skalibs/buffer.h> -#include <skalibs/strerr2.h> -#include <skalibs/types.h> - -#define MAXBUF 1024*64*2 - -static char const *delim = "\n" ; -static char const *pattern = 0 ; -static unsigned int EXACT = 0 ; - -#define USAGE "66-getenv [ -h ] [ -x ] [ -d delim ] process" -#define dieusage() strerr_dieusage(100, USAGE) - -static inline void info_help (void) -{ - static char const *help = -"66-getenv <options> process\n" -"\n" -"options :\n" -" -h: print this help\n" -" -d: specify output delimiter\n" -" -x: match exactly with the process name\n" -; - - if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; -} - -static int read_line(stralloc *dst, char const *line) -{ - char b[MAXBUF] ; - int fd ; - unsigned int n = 0, m = MAXBUF ; - - fd = open(line, O_RDONLY) ; - if (fd == -1) return 0 ; - - for(;;) - { - ssize_t r = read(fd,b+n,m-n); - if (r == -1) - { - if (errno == EINTR) continue ; - break ; - } - n += r ; - // buffer is full - if (n == m) - { - --n ; - break ; - } - // end of file - if (r == 0) break ; - } - close(fd) ; - - if(n) - { - int i = n ; - // remove trailing zeroes - while (i && b[i-1] == '\0') --i ; - while (i--) - if (b[i] == '\n' || b[i] == '\0') b[i] = ' ' ; - - if (b[n-1] == ' ') b[n-1] = '\0' ; - } - b[n] = '\0'; - - if (!stralloc_cats(dst,b) || - !stralloc_0(dst)) strerr_diefu1sys(111,"append stralloc") ; - return n ; -} - -static regex_t *regex_cmp (void) -{ - regex_t *preg = 0 ; - size_t plen = strlen(pattern) ; - char re[plen + 4 + 1] ; - char errbuf[256] ; - int r ; - - preg = malloc (sizeof (regex_t)) ; - if (!preg) strerr_diefu1sys(111,"allocate preg") ; - if (EXACT) - { - memcpy(re,"^(",2) ; - memcpy(re + 2,pattern,plen) ; - memcpy(re + 2 + plen,")$",2) ; - re[2 + plen + 2] = 0 ; - } - else - { - memcpy(re,pattern,plen) ; - re[plen] = 0 ; - } - - r = regcomp (preg, re, REG_EXTENDED | REG_NOSUB) ; - if (r) - { - regerror (r, preg, errbuf, sizeof(errbuf)) ; - strerr_diefu1x(111,errbuf) ; - } - - return preg ; -} - -void get_procs () -{ - char *proc = "/proc" ; - char *cmdline = "/cmdline" ; - char *environ = "/environ" ; - size_t proclen = 5, linelen = 8, i = 0, len ; - char myself [PID_FMT] ; - myself[pid_fmt(myself,getpid())] = 0 ; - regex_t *preg ; - preg = regex_cmp() ; - stralloc satmp = STRALLOC_ZERO ; - stralloc saproc = STRALLOC_ZERO ; - - if (!sastr_dir_get(&satmp,proc,"",S_IFDIR)) strerr_diefu1sys(111,"get content of /proc") ; - - i = 0, len = satmp.len ; - for (;i < len; i += strlen(satmp.s + i) + 1) - { - char *name = satmp.s + i ; - char c = name[0] ; - // keep only pid directories - if ( c >= '0' && c <= '9' ) - if (!stralloc_catb(&saproc,name,strlen(name) + 1)) strerr_diefu1sys(111,"append stralloc") ; - } - - i = 0, len = saproc.len ; - for (;i < len; i += strlen(saproc.s + i) + 1) - { - satmp.len = 0 ; - int found = 1 ; - char *name = saproc.s + i ; - size_t namelen = strlen(name) ; - if (!strcmp(name,myself)) continue ; - char tmp[proclen + 1 + namelen + linelen + 1] ; - memcpy(tmp,proc,proclen) ; - tmp[proclen] = '/' ; - memcpy(tmp + proclen + 1,name,namelen) ; - memcpy(tmp + proclen + 1 + namelen,cmdline,linelen) ; - tmp[proclen + 1 + namelen + linelen] = 0 ; - if (!read_line(&satmp,tmp)) continue ; - - if (regexec (preg, satmp.s, 0, NULL, 0) != 0) - found = 0 ; - - satmp.len = 0 ; - memcpy(tmp + proclen + 1 + namelen,environ,linelen) ; - tmp[proclen + 1 + namelen + linelen] = 0 ; - if (!read_line(&satmp,tmp)) continue ; - - if (found) - { - size_t j = 0 ; - for(;j < satmp.len; j++) - { - char ch[2] = { satmp.s[j], 0 } ; - if (satmp.s[j] == ' ' || satmp.s[j] == '\0') - { - if (buffer_putsflush(buffer_1, delim) < 0) strerr_diefu1sys(111, "write to stdout") ; - } - else if (buffer_puts(buffer_1, ch) < 0) strerr_diefu1sys(111, "write to stdout") ; - } - break ; - } - } - stralloc_free(&satmp) ; - stralloc_free(&saproc) ; - regfree(preg) ; -} - -int main (int argc, char const *const *argv, char const *const *envp) -{ - PROG = "66-getenv" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "hxd:", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'h' : info_help() ; return 0 ; - case 'x' : EXACT = 1 ; break ; - case 'd' : delim = l.arg ; break ; - default : dieusage() ; - } - } - argc -= l.ind ; argv += l.ind ; - } - if (argc < 1) dieusage() ; - pattern = *argv ; - - get_procs() ; - - return 0 ; -} diff --git a/src/extra-tools/66-gnwenv.c b/src/extra-tools/66-gnwenv.c deleted file mode 100644 index 1c54e5e1d381c834b072f9acf1d0a30e09b964ef..0000000000000000000000000000000000000000 --- a/src/extra-tools/66-gnwenv.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 66-gnwenv.c - * - * Copyright (c) 2018-2019 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 <sys/types.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> -#include <sys/wait.h> - -#include <oblibs/string.h> - -#include <skalibs/types.h> -#include <skalibs/buffer.h> -#include <skalibs/sgetopt.h> -#include <skalibs/strerr2.h> -#include <skalibs/env.h> -#include <skalibs/djbunix.h> - -#define MAX_ENV 4095 -static char const *pattern = 0 ; -static unsigned int EXACT = 0 ; - -#define USAGE "66-gnwenv [ -h ] [ -x ] [ -m mode ] process dir file" -#define dieusage() strerr_dieusage(100, USAGE) - -static inline void info_help (void) -{ - static char const *help = -"66-gnwenv <options> process dir file\n" -"\n" -"options :\n" -" -h: print this help\n" -" -m: create dir with given mode\n" -" -x: match exactly with the process name\n" -; - - if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; -} - -static void string_env(char *tmp,char const *s,size_t len) -{ - ssize_t r = 0 , pos = 0 ; - - while ((pos < len) && (r != -1)) - { - r = get_len_until(s+pos,'\n') ; - memcpy(tmp+pos,s+pos,r) ; - tmp[pos+r] = 0 ; - pos += ++r ;/**+1 to skip the \n character*/ - } -} - -int main (int argc, char const *const *argv, char const *const *envp) -{ - int r = 0 , pf, rm = 0, m = 0, fd[2], did = 0 ; - ssize_t slen = 0 ; - - unsigned int mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ; - - char const *dir = 0 , *file = 0 ; - char const *newargv[6+1] ; - char const *newread[6+1] ; - char md[UINT32_FMT] ; - char buf[MAX_ENV+1] ; - char tmp[MAX_ENV+1] ; - - PROG = "66-gnwenv" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "hxm:", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'h' : info_help() ; return 0 ; - case 'x' : EXACT = 1 ; break ; - case 'm' : if (!uint0_oscan(l.arg, &mode)) dieusage() ; did = 1 ; break ; - default : dieusage() ; - } - } - argc -= l.ind ; argv += l.ind ; - } - if (argc < 3) dieusage() ; - pattern = argv[0] ; - dir = argv[1] ; - if (dir[0] != '/') strerr_dief2x(111,dir," must be an absolute path") ; - file = argv[2] ; - - newread[rm++] = "66-getenv" ; - if (EXACT) - newread[rm++] = "-x" ; - newread[rm++] = pattern ; - newread[rm++] = dir ; - newread[rm++] = file ; - newread[rm++] = 0 ; - - if (pipe(fd) < 0) strerr_diefu1sys(111,"pipe") ; - pf = fork() ; - if (pf < 0) strerr_diefu1sys(111,"fork") ; - if (!pf) - { - dup2(fd[1],1) ; - pathexec(newread) ; - } - else - { - wait(NULL) ; - slen = read(fd[0],buf,MAX_ENV) ; - if (!slen) return 0 ; - buf[slen] = 0 ; - } - r = get_nbline(buf,slen) ; - - string_env(tmp,buf,slen) ; - - md[uint32_fmt(md,mode)] = 0 ; - - newargv[m++] = "66-writenv" ; - if (did) - { - newargv[m++] = "-m" ; - newargv[m++] = md ; - } - newargv[m++] = dir ; - newargv[m++] = file ; - newargv[m++] = 0 ; - - char const *v[r + 1] ; - if (!env_make (v, r ,tmp, slen)) strerr_diefu1sys(111,"make environment") ; - v[r] = 0 ; - - xpathexec_fromenv (newargv, v, r) ; -} - - - diff --git a/src/extra-tools/66-umountall.c b/src/extra-tools/66-umountall.c index 9e80473d7be36ecaefe6923e4ceda599ee87fb78..2b9321b0960de375553368109026d505d6999fdf 100644 --- a/src/extra-tools/66-umountall.c +++ b/src/extra-tools/66-umountall.c @@ -16,69 +16,70 @@ * All credits goes to Laurent Bercot <ska-remove-this-if-you-are-not-a-bot@skarnet.org> * */ +#include <errno.h> #include <string.h> +#include <stdio.h> +#include <mntent.h> #include <sys/mount.h> -#include <skalibs/bytestr.h> -#include <skalibs/buffer.h> #include <skalibs/strerr2.h> #include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> #include <skalibs/skamisc.h> -#define BUFSIZE 4096 -#define MAXLINES 512 +#define MAXLINES 99 + +#define EXCLUDEN 3 + +static char const *exclude_type[EXCLUDEN] = { "devtmpfs", "proc", "sysfs" } ; int main (int argc, char const *const *argv) { - stralloc mountpoints[MAXLINES] ; - char buf[BUFSIZE] ; - buffer b ; + size_t mountpoints[MAXLINES] ; + unsigned int got[EXCLUDEN] = { 0, 0, 0 } ; stralloc sa = STRALLOC_ZERO ; unsigned int line = 0 ; + FILE *fp ; int e = 0 ; - int r ; - int fd ; + + PROG = "s6-linux-init-umountall" ; - PROG = "66-umountall" ; - /* - We need to go through /proc/mounts *in reverse order*, because later mounts - may depend on earlier mounts. - The getmntent() family of functions has obviously not been designed for that - use case at all, and it is actually more difficult to use it than to do the - /proc/mounts parsing by hand. So, we do it by hand with skalibs functions. - That's how you can tell a good API from a terrible one. - */ + fp = setmntent("/proc/mounts", "r") ; + if (!fp) strerr_diefu1sys(111, "open /proc/mounts") ; - fd = open_readb("/proc/mounts") ; - if (fd < 0) strerr_diefu1sys(111, "open /proc/mounts") ; - memset(mountpoints, 0, sizeof(mountpoints)) ; - buffer_init(&b, &buffer_read, fd, buf, BUFSIZE) ; for (;;) { - size_t n, p ; - if (line >= MAXLINES) strerr_dief1x(111, "/proc/mounts too big") ; - sa.len = 0 ; - r = skagetln(&b, &sa, '\n') ; - if (r <= 0) break ; - p = byte_chr(sa.s, sa.len, ' ') ; - if (p >= sa.len) strerr_dief1x(111, "bad /proc/mounts format") ; - p++ ; - n = byte_chr(sa.s + p, sa.len - p, ' ') ; - if (n == sa.len - p) strerr_dief1x(111, "bad /proc/mounts format") ; - if (!stralloc_catb(&mountpoints[line], sa.s + p, n) || !stralloc_0(&mountpoints[line])) - strerr_diefu1sys(111, "store mount point") ; - line++ ; + struct mntent *p ; + unsigned int i = 0 ; + errno = 0 ; + p = getmntent(fp) ; + if (!p) break ; + for (; i < EXCLUDEN ; i++) + { + if (!strcmp(p->mnt_type, exclude_type[i])) + { + got[i]++ ; + break ; + } + } + if (i < EXCLUDEN && got[i] == 1) continue ; + if (line >= MAXLINES) + strerr_dief1x(100, "too many mount points") ; + mountpoints[line++] = sa.len ; + if (!stralloc_cats(&sa, p->mnt_dir) || !stralloc_0(&sa)) + strerr_diefu1sys(111, "add mount point to list") ; } - fd_close(fd) ; - stralloc_free(&sa) ; - if (r < 0) strerr_diefu1sys(111, "read /proc/mounts") ; + if (errno) strerr_diefu1sys(111, "read /proc/mounts") ; + endmntent(fp) ; while (line--) - if (umount(mountpoints[line].s) == -1) + { + if (umount(sa.s + mountpoints[line]) == -1) { e++ ; - strerr_warnwu2sys("umount ", mountpoints[line].s) ; + strerr_warnwu2sys("umount ", sa.s + mountpoints[line]) ; } + } + stralloc_free(&sa) ; + return e ; } diff --git a/src/extra-tools/66-which.c b/src/extra-tools/66-which.c deleted file mode 100644 index 3b4255f9af3b66dbbb367e6359e6a47585d27543..0000000000000000000000000000000000000000 --- a/src/extra-tools/66-which.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 66-which.c - * - * Copyright (c) 2019 Dyne.org Foundation, Amsterdam - * Copyright (c) 2019 Eric Vidal <eric@obarun.org> - * - * Written by: - * - Danilo Spinella <danyspin97@protonmail.com> - * - 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 <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include <skalibs/genalloc.h> -#include <skalibs/sgetopt.h> -#include <skalibs/buffer.h> -#include <skalibs/bytestr.h> -#include <skalibs/strerr2.h> -#include <skalibs/config.h> -#include <oblibs/error2.h> -#include <oblibs/string.h> - -#define USAGE "66-which [ -h ] [ -a | -q ] commands..." - -static inline void info_help (void) -{ - static char const *help = -"66-which <options> commands...\n" -"\n" -"options :\n" -" -h: print this help\n" -" -a: print all matching executable in PATH\n" -" -q: quiet, do not print anything to stdout\n" -; - if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; -} - -int check_executable(char const* filepath) { - struct stat sb ; - return (stat(filepath, &sb) == 0 && sb.st_mode & S_IXUSR - && !S_ISDIR(sb.st_mode)) ? 1 : 0 ; -} -int parse_path(genalloc* folders, char* path) { - char* rp = NULL ; - size_t i, len, s ; - int found ; - stralloc filepath = STRALLOC_ZERO ; - while (path) { - s = str_chr(path, ':') ; - if (!stralloc_copyb(&filepath, path, s) - || !stralloc_0(&filepath)) - strerr_diefu1sys(111, "append stralloc with PATH") ; - rp = realpath(filepath.s, NULL); - if (rp != NULL) { - char const** ss = genalloc_s(char const*, folders); - found = 0; - len = genalloc_len(char const*, folders); - for ( i = 0 ; i < len ; i++) { - if (obstr_equal(ss[i], rp)) { - found = 1 ; - break ; - } - } - if (!found) { - if (!genalloc_append(char const*, folders, &rp)) - strerr_diefu1sys(111, "append genalloc") ; - } else { - free(rp); - } - } - if (s == strlen(path)) break ; - path += s + 1; - } - stralloc_free(&filepath) ; - return genalloc_len(char const*, folders) ; -} - -int handle_string(char const* name, char const* env_path, genalloc_ref paths, - int quiet, int printall) { - size_t len = genalloc_len(char const*, paths) ; - int found = 0 ; - - stralloc filepath = STRALLOC_ZERO ; - char const** ss = genalloc_s(char const*, paths) ; - - for (size_t i = 0 ; i < len ; i++) { - if (!stralloc_copys(&filepath, ss[i]) - || !stralloc_cats(&filepath, "/") - || !stralloc_cats(&filepath, name) - || !stralloc_0(&filepath)) - retstralloc(111, "filepath"); - - if (check_executable(filepath.s)) { - if (!quiet && (buffer_puts(buffer_1small, filepath.s) < 0 - || buffer_put(buffer_1small, "\n", 1) < 0 - || !buffer_flush(buffer_1small))) - strerr_diefu1sys(111, "write to stdout") ; - found = 1; - if (!printall) break ; - } - } - - if (found == 0 && !quiet) - strerr_warnw5x("no ",name," in (",env_path,")") ; - - stralloc_free(&filepath); - return found == 1 ? 0 : 111; -} - -int handle_path(char const* path, int quiet) { - char* rp = realpath(path, NULL) ; - if (rp != NULL && check_executable(rp)) { - if (!quiet && (buffer_puts(buffer_1small, rp) < 0 - || buffer_put(buffer_1small, "\n", 1) < 0 - || !buffer_flush(buffer_1small))) - strerr_diefu1sys(111, "write to stdout") ; - return 0 ; - } - - size_t len = strlen(path) ; - char base[len+1] ; - char dir[len+1] ; - if (!basename(base, path)) - strerr_diefu1sys(111, "get basename") ; - if (!dirname(dir, path)) - strerr_diefu1sys(111, "get dirname") ; - - if (!quiet) strerr_warnw5x("no ",base," in (",dir,")") ; - - return 111 ; -} - -int main (int argc, char const *const *argv) -{ - int printall = 0 ; - int quiet = 0 ; - char* path = 0 ; - int ret = 0; - genalloc paths = GENALLOC_ZERO ; // char const * - PROG = "66-which" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "haq", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'h': info_help() ; return 0 ; - case 'a': printall = 1 ; break ; - case 'q': quiet = 1 ; break ; - default : strerr_dieusage(110, USAGE) ; - } - } - argc -= l.ind ; argv += l.ind ; - } - - if (printall && quiet) strerr_dieusage(110, USAGE) ; - - path = getenv("PATH") ; - if (!path) path = SKALIBS_DEFAULTPATH ; - - if (argc < 0) strerr_dieusage(110, USAGE) ; - if (!parse_path(&paths, path)) - strerr_diefu1sys(111, "PATH is empty or contains non valid values") ; - - for ( ; *argv ; argv++) { - if ((*argv)[0] == '/' - || (*argv)[0] == '~' || ((*argv)[0] == '~' && (*argv)[1] == '/') - || (*argv)[0] == '.' || ((*argv)[0] == '.' && (*argv)[1] == '/') - || ((*argv)[0] == '.' || ((*argv)[1] == '.' && (*argv)[2] == '/'))) - ret = handle_path(*argv, quiet); - else - ret = handle_string(*argv, path, &paths, quiet, printall); - } - - genalloc_free(char const *, &paths) ; - return ret ; -} diff --git a/src/extra-tools/66-writenv.c b/src/extra-tools/66-writenv.c deleted file mode 100644 index 050e2633fbd7e25a39ca35237c006b0dcd056788..0000000000000000000000000000000000000000 --- a/src/extra-tools/66-writenv.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 66-writenv.c - * - * Copyright (c) 2018-2019 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 <sys/stat.h> -#include <unistd.h>//fsync,close -#include <errno.h> - -#include <skalibs/types.h> -#include <skalibs/bytestr.h> -#include <skalibs/buffer.h> -#include <skalibs/sgetopt.h> -#include <skalibs/strerr2.h> -#include <skalibs/djbunix.h> - -#define MAX_ENV 4095 -#define USAGE "66-writenv [ - h ] [ -m mode ] dir file" -#define dieusage() strerr_dieusage(100, USAGE) - -static inline void info_help (void) -{ - static char const *help = -"66-writenv <options> dir file\n" -"\n" -"options :\n" -" -h: print this help\n" -" -m: create dir with given mode\n" -; - - if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; -} - -int main (int argc, char const *const *argv, char const *const *envp) -{ - unsigned int mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ; - size_t dirlen, filen ; - buffer b ; - int fd ; - char const *dir = 0 , *file = 0 ; - char buf[MAX_ENV+1] ; - PROG = "66-writenv" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "hm:", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'h' : info_help() ; return 0 ; - case 'm' : if (!uint0_oscan(l.arg, &mode)) dieusage() ; break ; - default : dieusage() ; - } - } - argc -= l.ind ; argv += l.ind ; - } - if (argc < 2) dieusage() ; - dir = argv[0] ; - if (dir[0] != '/') strerr_dief2x(111,dir," must be an absolute path") ; - file = argv[1] ; - - if (mkdir(dir, mode) < 0) - { - struct stat st ; - if (errno != EEXIST) strerr_diefu2sys(111, "mkdir ", dir) ; - if (stat(dir, &st) < 0) - strerr_diefu2sys(111, "stat ", dir) ; - if (!S_ISDIR(st.st_mode)) - { - errno = ENOTDIR ; - strerr_diefu2sys(111, "mkdir ", dir) ; - } - } - dirlen = strlen(dir) ; - filen = strlen(file) ; - char fn[dirlen + 1 + filen + 1] ; - memcpy(fn,dir,dirlen) ; - fn[dirlen] = '/' ; - memcpy(fn + dirlen + 1, file ,filen) ; - fn[dirlen + 1 + filen] = 0 ; - fd = open_trunc(fn) ; - if (fd < 0) strerr_diefu2sys(111,"open trunc: ",fn) ; - buffer_init(&b,&buffer_write,fd,buf,MAX_ENV) ; - for (; *envp ; envp++) - { - if ((buffer_put(&b, *envp,strlen(*envp)) < 0) || - (buffer_put(&b, "\n",1) < 0)) { close(fd) ; strerr_diefu1sys(111,"write buffer") ; } - } - if(!buffer_flush(&b)){ close(fd) ; strerr_diefu1sys(111,"flush") ; } - if (fsync(fd) < 0){ close(fd) ; strerr_diefu1sys(111,"sync") ; } - close(fd) ; - return 0 ; -} diff --git a/src/extra-tools/deps-exe/66-envfile b/src/extra-tools/deps-exe/66-envfile deleted file mode 100644 index e7187fe2cfb010b60c595e7919426c2a13324a70..0000000000000000000000000000000000000000 --- a/src/extra-tools/deps-exe/66-envfile +++ /dev/null @@ -1 +0,0 @@ --lskarnet diff --git a/src/extra-tools/deps-exe/66-getenv b/src/extra-tools/deps-exe/66-getenv deleted file mode 100644 index aa08a1493330806f8a201d878aa14bb087db05a3..0000000000000000000000000000000000000000 --- a/src/extra-tools/deps-exe/66-getenv +++ /dev/null @@ -1,3 +0,0 @@ --loblibs --lskarnet - diff --git a/src/extra-tools/deps-exe/66-gnwenv b/src/extra-tools/deps-exe/66-gnwenv deleted file mode 100644 index aa08a1493330806f8a201d878aa14bb087db05a3..0000000000000000000000000000000000000000 --- a/src/extra-tools/deps-exe/66-gnwenv +++ /dev/null @@ -1,3 +0,0 @@ --loblibs --lskarnet - diff --git a/src/extra-tools/deps-exe/66-which b/src/extra-tools/deps-exe/66-which deleted file mode 100644 index e5530f04bdc50365c259443d7af683830ee6bc28..0000000000000000000000000000000000000000 --- a/src/extra-tools/deps-exe/66-which +++ /dev/null @@ -1,2 +0,0 @@ --lskarnet --loblibs diff --git a/src/extra-tools/deps-exe/66-writenv b/src/extra-tools/deps-exe/66-writenv deleted file mode 100644 index e7187fe2cfb010b60c595e7919426c2a13324a70..0000000000000000000000000000000000000000 --- a/src/extra-tools/deps-exe/66-writenv +++ /dev/null @@ -1 +0,0 @@ --lskarnet diff --git a/src/extra-tools/deps-exe/execl-cmdline b/src/extra-tools/deps-exe/execl-cmdline deleted file mode 100644 index c6b27401245136c5d4e0f2b82c6d623381aefe8b..0000000000000000000000000000000000000000 --- a/src/extra-tools/deps-exe/execl-cmdline +++ /dev/null @@ -1,3 +0,0 @@ --lexecline --loblibs --lskarnet diff --git a/src/extra-tools/deps-exe/execl-envfile b/src/extra-tools/deps-exe/execl-envfile deleted file mode 100644 index 77b1d97fdc3b7efce73a9a3efb7a8691bb92c0ea..0000000000000000000000000000000000000000 --- a/src/extra-tools/deps-exe/execl-envfile +++ /dev/null @@ -1,5 +0,0 @@ -${LIB66} --lexecline --loblibs --lskarnet -${LIBEXECLINE} diff --git a/src/extra-tools/deps-exe/execl-subuidgid b/src/extra-tools/deps-exe/execl-subuidgid deleted file mode 100644 index 77b1d97fdc3b7efce73a9a3efb7a8691bb92c0ea..0000000000000000000000000000000000000000 --- a/src/extra-tools/deps-exe/execl-subuidgid +++ /dev/null @@ -1,5 +0,0 @@ -${LIB66} --lexecline --loblibs --lskarnet -${LIBEXECLINE} diff --git a/src/extra-tools/execl-cmdline.c b/src/extra-tools/execl-cmdline.c deleted file mode 100644 index ee2026bc035f4af5a5cd163f85549c7b0e2b58da..0000000000000000000000000000000000000000 --- a/src/extra-tools/execl-cmdline.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * execl-cmdline.c - * - * Copyright (c) 2018-2019 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 <oblibs/string.h> -#include <oblibs/stralist.h> -#include <oblibs/error2.h> - -#include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> -#include <skalibs/env.h> -#include <skalibs/djbunix.h> -#include <skalibs/sgetopt.h> -#include <skalibs/buffer.h> - -#include <execline/execline.h> - -#define USAGE "execl-cmdline [ -s ] { command... }" - -static inline void info_help (void) -{ - static char const *help = -"execl-envfile <options> { command... }\n" -"\n" -"options :\n" -" -h: print this help\n" -" -s: split command\n" -; - - if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; -} - -int clean_val_doublequoted(genalloc *ga,char const *line) -{ - size_t slen = strlen(line) ; - size_t tl ; - char s[slen+1] ; - memcpy(s,line,slen) ; - s[slen] = 0 ; - int f = 0, r = 0 , prev = 0 ; - r = get_len_until(s,'"') ; - if (r < 0) - { - if (!clean_val(ga,s)) return 0 ; - return 1 ; - } - for (int i = 0 ; i < slen ; i++) - { - if (s[i] == '"') - { - if (f) - { - char t[slen+1] ; - tl = i-1 ; - memcpy(t,s+prev,tl-prev+1) ; - t[tl-prev+1] = 0 ; - if (!stra_add(ga,t)) return 0 ; - f = 0 ; prev = i+1 ; - } - else - { - if (i > 0) - { - char t[slen+1] ; - tl = i ; - if (prev == tl){ f++ ; continue ; } - memcpy(t,s+prev,tl-prev) ; - t[tl-prev] = 0 ; - if (!clean_val(ga,t)) return 0 ; - f++ ; prev = i+1 ; - } - else f++ ; - } - } - else - if (i+1 == slen) - { - char t[slen+1] ; - tl = i - 1 ; - memcpy(t,s+prev,slen-prev) ; - t[slen-prev] = 0 ; - if (!clean_val(ga,t)) return 0 ; - break ; - } - } - if (f) strerr_dief2x(111,"odd number of double quote in: ",line) ; - - return 1 ; -} - -int main(int argc, char const **argv, char const *const *envp) -{ - - int r, argc1, split ; - - PROG = "execl-cmdline" ; - - stralloc tmodifs = STRALLOC_ZERO ; - stralloc modifs = STRALLOC_ZERO ; - genalloc ga = GENALLOC_ZERO ; - - r = argc1 = split = 0 ; - - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "hs", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'h' : info_help() ; return 0 ; - case 's' : split = 1 ; break ; - default : exitusage(USAGE) ; - } - } - argc -= l.ind ; argv += l.ind ; - } - if (!argc) exitusage(USAGE) ; - argc1 = el_semicolon(argv) ; - if (argc1 >= argc) strerr_dief1x(100, "unterminated block") ; - argv[argc1] = 0 ; - - char const **newargv = argv ; - for (int i = 0; i < argc1 ; i++, newargv++) - { - if (!*newargv[0]) - continue ; - - if (!stralloc_cats(&tmodifs,*newargv)) retstralloc(111,"tmodifs") ; - if (split) - { - if (!stralloc_cats(&tmodifs," ")) retstralloc(111,"tmodifs") ; - } - else if (!stralloc_0(&tmodifs)) retstralloc(111,"tmodifs_0") ; - r++; - } - - if (split) - { - if (!clean_val_doublequoted(&ga,tmodifs.s)) strerr_diefu2x(111,"clean val: ",tmodifs.s) ; - for (unsigned int i = 0 ; i < genalloc_len(stralist,&ga) ; i++) - { - stralloc_cats(&modifs,gaistr(&ga,i)) ; - stralloc_0(&modifs) ; - } - r = genalloc_len(stralist,&ga) ; - genalloc_deepfree(stralist,&ga,stra_free) ; - } - else if (!stralloc_copy(&modifs,&tmodifs)) retstralloc(111,"copy") ; - - stralloc_free(&tmodifs) ; - - char const *newarg[r + 1] ; - if (!env_make(newarg, r, modifs.s, modifs.len)) strerr_diefu1sys(111, "env_make") ; - newarg[r] = 0 ; - - xpathexec_run(newarg[0],newarg,envp) ; -} diff --git a/src/extra-tools/execl-envfile.c b/src/extra-tools/execl-envfile.c deleted file mode 100644 index f50afcaaa36868266d71ebd81460dcb4aac7ffbf..0000000000000000000000000000000000000000 --- a/src/extra-tools/execl-envfile.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - * execl-envfile.c - * - * Copyright (c) 2018-2019 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 <stdio.h> - -#include <oblibs/string.h> -#include <oblibs/stralist.h> -#include <oblibs/error2.h> -#include <oblibs/types.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 <66/environ.h> -#include <66/constants.h> - -static stralloc SAENV = STRALLOC_ZERO ; -static genalloc GAENV = GENALLOC_ZERO ; //diuint32, pos in senv - -#define USAGE "execl-envfile [ -h help ] [ -l ] src prog" - -static inline void info_help (void) -{ - static char const *help = -"execl-envfile <options> src prog\n" -"\n" -"options :\n" -" -h: print this help\n" -" -f: file to parse(deprecated)\n" -" -l: loose\n" -; - - if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; -} - -int loop_stra(stralloc *sa,char const *search) -{ - size_t i = 0, len = sa->len ; - for (;i < len; i += strlen(sa->s + i) + 1) - if (!strcmp(sa->s+i,search)) return 1 ; - - return 0 ; -} - -int main (int argc, char const *const *argv, char const *const *envp) -{ - int r, unexport ; - int insist = 1 ; - size_t pathlen, i ; - char const *path = 0 ; - char const *file = 0 ; - char tpath[MAXENV + 1] ; - char tfile[MAXENV+1] ; - stralloc src = STRALLOC_ZERO ; - stralloc modifs = STRALLOC_ZERO ; - stralloc dst = STRALLOC_ZERO ; - genalloc toparse = GENALLOC_ZERO ; //stralist - - exlsn_t info = EXLSN_ZERO ; - - r = i = unexport = 0 ; - insist = 1 ; - - PROG = "execl-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 ; break ; - case 'l' : insist = 0 ; break ; - default : exitusage(USAGE) ; - } - } - argc -= l.ind ; argv += l.ind ; - } - - if (argc < 2) exitusage(USAGE) ; - - path = *argv ; - argv++; - argc--; - - /** Mark -f as deprecated */ - if (file) - { - strerr_warnw1x("-f options is deprecated") ; - if (path[0] != '/') strerr_dief3x(111,"path of: ",path,": must be absolute") ; - } - else - { - r = scan_mode(path,S_IFREG) ; - if (!r) strerr_diefu2sys(111,"find: ",path) ; - if (r < 0) - { - r = scan_mode(path,S_IFDIR) ; - if (!r) strerr_diefu2sys(111,"find: ",path) ; - if (r < 0) strerr_dief2x(111,"invalid format of: ", path) ; - if (path[0] == '.') - { - if (!dir_beabsolute(tpath,path)) - strerr_diefu2sys(111,"find absolute path of: ",path) ; - } - else if (path[0] != '/') strerr_dief3x(111,"path of: ",path,": must be absolute") ; - else - { - pathlen = strlen(path) ; - memcpy(tpath,path,pathlen); - tpath[pathlen] = 0 ; - } - path = tpath ; - } - else - { - if (!basename(tfile,path)) strerr_diefu2x(111,"get file name of: ",path) ; - file = tfile ; - if (!dirname(tpath,path)) strerr_diefu2x(111,"get parent path of: ",path) ; - path = tpath ; - } - } - - r = dir_get(&toparse,path,"",S_IFREG) ; - if (!r && insist) strerr_diefu2sys(111,"get file from: ",path) ; - else if ((!r && !insist) || !genalloc_len(stralist,&toparse)) - { - xpathexec_run(argv[0],argv,envp) ; - } - - if (file) - { - r = stra_findidx(&toparse,file) ; - if (r < 0) - { - if (insist) strerr_diefu2x(111,"find: ",file) ; - else - { - xpathexec_run(argv[0],argv,envp) ; - } - } - - if (!file_readputsa(&src,path,file)) strerr_diefu4sys(111,"read file: ",path,"/",file) ; - if (!env_parsenclean(&modifs,&src)) strerr_diefu4x(111,"parse and clean environment of: ",path,"/",file) ; - if (!env_split(&GAENV,&SAENV,&src)) strerr_diefu4x(111,"split environment of: ",path,"/",file) ; - if (genalloc_len(diuint32,&GAENV) > MAXVAR) strerr_dief4x(111,"to many variables in file: ",path,"/",file) ; - } - else - { - for (i = 0 ; i < genalloc_len(stralist,&toparse) ; i++) - { - src.len = 0 ; - size_t n = genalloc_len(diuint32,&GAENV) + MAXVAR ; - if (i > MAXFILE) strerr_dief2x(111,"to many file to parse in: ",path) ; - if (!file_readputsa(&src,path,gaistr(&toparse,i))) strerr_diefu4sys(111,"read file: ",path,"/",gaistr(&toparse,i)) ; - if (!env_parsenclean(&modifs,&src)) strerr_diefu4x(111,"parse and clean environment of: ",path,"/",gaistr(&toparse,i)) ; - if (!env_split(&GAENV,&SAENV,&src)) strerr_diefu4x(111,"split environment of: ",path,"/",gaistr(&toparse,i)) ; - if (genalloc_len(diuint32,&GAENV) > n) strerr_dief4x(111,"to many variables in file: ",path,"/",gaistr(&toparse,i)) ; - } - } - - genalloc_deepfree(stralist,&toparse,stra_free) ; - stralloc_free(&src) ; - - /** be able to freed the stralloc before existing */ - char tmp[modifs.len+1] ; - memcpy(tmp,modifs.s,modifs.len) ; - tmp[modifs.len] = 0 ; - - size_t n = env_len(envp) + 1 + byte_count(modifs.s,modifs.len,'\0') ; - if (n > MAXENV) strerr_dief1x(111,"environment string too long") ; - char const *newenv[n + 1] ; - if (!env_merge (newenv, n ,envp,env_len(envp),tmp, modifs.len)) strerr_diefu1sys(111,"build environment") ; - - 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 ((SAENV.s+val)[0] == SS_VAR_UNEXPORT) - { - val++ ; - unexport = 1 ; - } - if(!loop_stra(&info.vars,SAENV.s + key)) - if (!env_substitute(SAENV.s + key,SAENV.s + val,&info,newenv,unexport)) - strerr_diefu4x(111,"substitute value of: ",SAENV.s + key," by: ",SAENV.s + val) ; - } - genalloc_free(diuint32,&GAENV) ; - stralloc_free(&SAENV) ; - - modifs.len = 0 ; - 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/execl-subuidgid.c b/src/extra-tools/execl-subuidgid.c deleted file mode 100644 index 8eb60e834be597c43808b637e23e2956041daedc..0000000000000000000000000000000000000000 --- a/src/extra-tools/execl-subuidgid.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * execl-subuidgid.c - * - * Copyright (c) 2018-2019 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 <unistd.h> -#include <sys/types.h> -#include <stdio.h> -#include <oblibs/error2.h> - -#include <skalibs/types.h> -#include <skalibs/buffer.h> -#include <skalibs/stralloc.h> -#include <skalibs/strerr2.h> -#include <skalibs/env.h> -#include <skalibs/sgetopt.h> -#include <skalibs/djbunix.h> - -#include <execline/execline.h> -#include <66/environ.h> -#include <66/utils.h> - -#define USAGE "execl-subuidgid [ -h ] [ -o owner ] prog..." - -static inline void info_help (void) -{ - static char const *help = -"execl-subuidgid <options> prog\n" -"\n" -"options :\n" -" -h: print this help\n" -" -o: owner to use\n" -; - - if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; -} - -int main (int argc, char const **argv, char const *const *envp) -{ - uid_t uid ; - gid_t gid ; - int r ; - char const *owner = 0 ; - stralloc sa = STRALLOC_ZERO ; - stralloc dst = STRALLOC_ZERO ; - exlsn_t info = EXLSN_ZERO; - char cuid[UID_FMT], cgid[GID_FMT] ; - - PROG = "execl-subuidgid" ; - - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "ho:", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'h' : info_help(); return 0 ; - case 'o' : owner = l.arg ; break ; - default : exitusage(USAGE) ; - } - } - argc -= l.ind ; argv += l.ind ; - } - if (owner) - { - if (!youruid(&uid,owner)) strerr_diefu2sys(111,"get uid of: ",owner) ; - } - else uid = getuid() ; - - if (!yourgid(&gid,uid)) strerr_diefu1sys(111,"get gid") ; - cuid[uid_fmt(cuid,uid)] = 0 ; - cgid[gid_fmt(cgid,gid)] = 0 ; - - if (!env_addkv("UID",cuid,&info)) strerr_diefu1sys(111,"set UID") ; - if (!env_addkv("GID",cgid,&info)) strerr_diefu1sys(111,"set GID") ; - - if (!env_string(&sa,argv,(unsigned int) argc)) strerr_diefu1sys(111,"environment string") ; - - r = el_substitute (&dst, sa.s, sa.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(&sa) ; - - { - char const *v[r + 1]; - if (!env_make (v, r, dst.s, dst.len)) strerr_diefu1sys (111, "env_make") ; - v[r] = 0 ; - pathexec_r (v, envp, env_len (envp), info.modifs.s, info.modifs.len) ; - } - - return 0 ; -} diff --git a/src/include/66/66.h b/src/include/66/66.h index fcbee9ac0d1a2e58386a04813a1cea3b280ba608..f40ba1d177382e9d26e162b66f5c756a2061da92 100644 --- a/src/include/66/66.h +++ b/src/include/66/66.h @@ -21,6 +21,7 @@ #include <66/db.h> #include <66/enum.h> #include <66/environ.h> +#include <66/hpr.h> #include <66/parser.h> #include <66/rc.h> #include <66/resolve.h> diff --git a/src/include/66/backup.h b/src/include/66/backup.h index d9421af80e7758633187c44e36ffc0cdef9009a2..ca2c8e1e38a5f703ad503f367d06bd1525ed77c1 100644 --- a/src/include/66/backup.h +++ b/src/include/66/backup.h @@ -12,17 +12,16 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef BACKUP_H -#define BACKUP_H +#ifndef SS_BACKUP_H +#define SS_BACKUP_H #include <skalibs/stralloc.h> #include <66/ssexec.h> extern int backup_make_new(ssexec_t *info,unsigned int type) ; - extern int backup_cmd_switcher(unsigned int verbosity,char const *cmd, ssexec_t *info) ; extern int backup_switcher(int argc, char const *const *argv,ssexec_t *info) ; - extern int backup_realpath_sym(stralloc *sa,ssexec_t *info,unsigned int type) ; + #endif diff --git a/src/include/66/constants.h b/src/include/66/constants.h index 95aad7a75c61166c84224bbc0f88fbc215fe477b..8bcf5f012b533e60bd9e81394be93ca1d58b8bea 100644 --- a/src/include/66/constants.h +++ b/src/include/66/constants.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef CONSTANTS_H -#define CONSTANTS_H +#ifndef SS_CONSTANTS_H +#define SS_CONSTANTS_H #include <66/config.h> @@ -94,16 +94,21 @@ #define SS_BOOT_CONF_LEN (sizeof SS_BOOT_CONF - 1) #define SS_BOOT_PATH "/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin" #define SS_BOOT_PATH_LEN (sizeof SS_BOOT_PATH - 1) -#define SS_BOOT_TREE "init" +#define SS_BOOT_TREE "boot" #define SS_BOOT_TREE_LEN (sizeof SS_BOOT_TREE - 1) #define SS_BOOT_RCINIT "rc.init" #define SS_BOOT_RCINIT_LEN (sizeof SS_BOOT_RCINIT - 1) #define SS_BOOT_RCSHUTDOWN "rc.shutdown" #define SS_BOOT_RCSHUTDOWN_LEN (sizeof SS_BOOT_RCSHUTDOWN - 1) +#define SS_BOOT_RCSHUTDOWNFINAL "rc.shutdown.final" +#define SS_BOOT_RCSHUTDOWNFINAL_LEN (sizeof SS_BOOT_RCSHUTDOWNFINAL -1) #define SS_BOOT_UMASK 0022 #define SS_BOOT_RESCAN 0 #define SS_BOOT_LOGFIFO "scandir/0/scandir-log/fifo" #define SS_BOOT_LOGFIFO_LEN (sizeof SS_BOOT_LOGFIFO - 1) #define SS_BOOT_SHUTDOWND "66-shutdownd" #define SS_BOOT_SHUTDOWND_LEN (sizeof SS_BOOT_SHUTDOWND - 1) + +/** Instance */ +#define SS_INSTANCE "@I" #endif diff --git a/src/include/66/db.h b/src/include/66/db.h index de55f840d4f19190353126513e6c1b037b9f43b8..237114888f61c19c537a245de8c0d799d86f01ff 100644 --- a/src/include/66/db.h +++ b/src/include/66/db.h @@ -12,30 +12,17 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef DB_H -#define DB_H +#ifndef SS_DB_H +#define SS_DB_H #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <66/ssexec.h> -extern int db_cmd_master(unsigned int verbosity,char const *cmd) ; -extern int db_update_master(int argc, char const *const *argv) ; -extern int db_bundle_modif(genalloc *bundle,unsigned int verbosity, char const *src, unsigned int action) ; -//extern int db_bundle_contents(graph_t *g, char const *name, char const *src, unsigned int verbosity, unsigned int action) ; -extern int db_write_contents(genalloc *ga, char const *bundle,char const *dir) ; -extern int db_write_master(ssexec_t *info, genalloc *ga, char const *dir,int both) ; - extern int db_compile(char const *workdir, char const *tree, char const *treename,char const *const *envp) ; - extern int db_find_compiled_state(char const *livetree, char const *treename) ; - -extern int db_get_permissions(stralloc *uid, char const *tree) ; - extern int db_update(char const *newdb, ssexec_t *info,char const *const *envp) ; - extern int db_ok(char const *livetree, char const *treename) ; - extern int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) ; #endif diff --git a/src/include/66/enum.h b/src/include/66/enum.h index 2388db0a319f44ba67610127d25414902dd6a29f..022cd2d76a49d57f5d6bfab9069b8272e323c572 100644 --- a/src/include/66/enum.h +++ b/src/include/66/enum.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef ENUM_H -#define ENUM_H +#ifndef SS_ENUM_H +#define SS_ENUM_H #include <sys/types.h> @@ -117,7 +117,7 @@ struct key_all_s static key_description_t const main_section_list[] = { { .name = "@type", .expected = LINE, .mandatory = NEED }, - { .name = "@name", .expected = LINE, .mandatory = NEED }, + { .name = "@name", .expected = LINE, .mandatory = OPTS }, { .name = "@description", .expected = QUOTE, .mandatory = OPTS }, { .name = "@depends", .expected = BRACKET, .mandatory = OPTS }, { .name = "@contents", .expected = BRACKET, .mandatory = BUNDLE }, diff --git a/src/include/66/environ.h b/src/include/66/environ.h index 00216352692caf79f0989d01ac7110a00d67bde7..7c57b9387086fda2bc38ce8d7ecfc7e563b976a8 100644 --- a/src/include/66/environ.h +++ b/src/include/66/environ.h @@ -12,37 +12,14 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef ENVIRON_H -#define ENVIRON_H +#ifndef SS_ENVIRON_H +#define SS_ENVIRON_H -#include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> - -#define MAXVAR 50 -#define MAXFILE 100 -#define MAXENV 4095 - -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 } +#include <sys/types.h> +#include <skalibs/stralloc.h> -extern int env_clean(stralloc *src) ; -extern int env_split_one(char *line,genalloc *ga,stralloc *sa) ; -extern int env_split(genalloc *gaenv,stralloc *saenv,stralloc *src) ; -extern int env_parsenclean(stralloc *modifs,stralloc *src) ; -extern int make_env_from_line(char const **v,stralloc *sa) ; -extern int env_substitute(char const *key, char const *val,exlsn_t *info, char const *const *envp,int unexport) ; -extern int env_addkv (const char *key, const char *val, exlsn_t *info) ; -extern size_t build_env(char const *src,char const *const *envp,char const **newenv, char *tmpenv) ; -extern int env_get_from_src(stralloc *modifs,char const *src) ; extern int env_resolve_conf(stralloc *env,uid_t owner) ; extern int env_merge_conf(char const *dst,char const *file,stralloc *srclist,stralloc *modifs,unsigned int force) ; + #endif diff --git a/src/include/66/hpr.h b/src/include/66/hpr.h index 816eef0cabe39630460a25b502bc0e7b5273a851..f53a212abe5622d687cdf80d56cbad6383962b17 100644 --- a/src/include/66/hpr.h +++ b/src/include/66/hpr.h @@ -16,8 +16,8 @@ * All credits goes to Laurent Bercot <ska-remove-this-if-you-are-not-a-bot@skarnet.org> * */ -#ifndef HPR_H -#define HPR_H +#ifndef SS_HPR_H +#define SS_HPR_H #include <stddef.h> diff --git a/src/include/66/parser.h b/src/include/66/parser.h index 62f05c484cb5fa59a7bf69a2888da52b079c7292..698a4ed118645bd88017d1dfd33efa769db3c58f 100644 --- a/src/include/66/parser.h +++ b/src/include/66/parser.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef PARSER_H -#define PARSER_H +#ifndef SS_PARSER_H +#define SS_PARSER_H #include <66/enum.h> @@ -22,6 +22,8 @@ #include <oblibs/oblist.h> #include <oblibs/stralist.h> +#include <oblibs/mill.h> + #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> @@ -32,7 +34,7 @@ extern stralloc keep ; extern stralloc deps ; -extern genalloc gadeps ; +//extern genalloc gadeps ; extern genalloc gasv ; typedef enum actions_e actions_t, *actions_t_ref ; @@ -54,7 +56,7 @@ struct sv_exec_s { /**build=45->auto,build=46->custom*/ int build ; - uid_t runas ; + unsigned int runas ; unsigned int shebang ; unsigned int exec ; } ; @@ -101,7 +103,7 @@ typedef struct sv_name_s sv_name_t, *sv_name_t_ref ; struct sv_name_s { int itype ;/**int type =30->classic,31->bundle,32->longrun,33->oneshot*/ - unsigned int name ;//pos in keep + int name ;//pos in keep unsigned int description ;//pos in keep unsigned int idga ; //pos in genalloc gadeps unsigned int nga ; //len of idga in genalloc gadeps @@ -183,7 +185,7 @@ struct sv_alltype_s #define SV_NAME_ZERO \ { \ -1 ,\ - 0 ,\ + -1 ,\ 0 ,\ 0 ,\ 0 ,\ @@ -244,76 +246,20 @@ struct section_s .idx = { 0 } , \ .file = 0 } - -typedef struct parse_mill_inner_s parse_mill_inner_t, *parse_mill_inner_t_ref ; -struct parse_mill_inner_s -{ - char curr ; - uint32_t nline ; - uint8_t nopen ; //number of open found - uint8_t nclose ; //number of close found - uint8_t jumped ;//jump was made or not 1->no,0->yes - uint8_t flushed ;//flush was made or not 1->no,0->yes - -} ; -#define PARSE_MILL_INNER_ZERO { .curr = 0, \ - .nline = 1, \ - .nopen = 0, \ - .nclose = 0, \ - .jumped = 0, \ - .flushed = 0 } - -typedef struct parse_mill_s parse_mill_t,*parse_mill_t_ref ; -struct parse_mill_s -{ - char const open ; - char const close ; - uint8_t force ; //1 -> only one open and close - char const *skip ; - size_t skiplen ; - char const *end ; - size_t endlen ; - char const *jump ;//skip the complete line - size_t jumplen ; - uint8_t check ;//check if nopen == openclose, 0 -> no,1->yes - uint8_t flush ;//set nopen,nclose,sa.len to 0 at every new line - uint8_t forceskip ;//force to skip even if nopen is positive - parse_mill_inner_t inner ; -} ; - -typedef enum parse_enum_e parse_enum_t,*parse_enum_t_ref ; -enum parse_enum_e -{ - IGN = 0 , - KEEP , - JUMP , - EXIT , - END -} ; - -/** Main */ -extern int parser(sv_alltype *service,stralloc *src,char const *file) ; -extern int parse_config(parse_mill_t *p,char const *file, stralloc *src, stralloc *kp,size_t *pos) ; -extern char next(stralloc *s,size_t *pos) ; -extern uint8_t cclass (parse_mill_t *p) ; /** freed */ extern void sv_alltype_free(sv_alltype *sv) ; extern void keynocheck_free(keynocheck *nocheck) ; extern void section_free(section_t *sec) ; extern void freed_parser(void) ; /** enable phase */ -extern int parse_service_get_list(stralloc *result, stralloc *list) ; -extern int parse_service_before(ssexec_t *info, stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,unsigned int force,unsigned int exist) ; -extern int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,unsigned int force) ; +extern int parser(sv_alltype *service,stralloc *src,char const *svname) ; +extern int parse_service_check_enabled(ssexec_t *info, char const *svname,uint8_t force,uint8_t *exist) ; +extern int parse_service_before(ssexec_t *info, stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,uint8_t force,uint8_t *exist) ; +extern int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,uint8_t force) ; extern int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *service,unsigned int *nbsv,uid_t owner) ; -/** utilities */ -extern int parse_line(stralloc *src,size_t *pos) ; -extern int parse_quote(stralloc *src,size_t *pos) ; -extern int parse_bracket(stralloc *src,size_t *pos) ; -extern int parse_env(stralloc *src,size_t *pos) ; /** split */ -extern int get_section_range(section_t *sasection,stralloc *src) ; -extern int get_key_range(genalloc *ga, section_t *sasection,char const *file,int *svtype) ; +extern int section_get_range(section_t *sasection,stralloc *src) ; +extern int key_get_range(genalloc *ga, section_t *sasection,int *svtype) ; extern int get_mandatory(genalloc *nocheck,int idsec,int idkey) ; extern int nocheck_toservice(keynocheck *nocheck,int svtype, sv_alltype *service) ; /** store */ @@ -321,26 +267,19 @@ extern int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) ; extern int keep_runfinish(sv_exec *exec,keynocheck *nocheck) ; extern int keep_logger(sv_execlog *log,keynocheck *nocheck) ; /** helper */ -extern int read_svfile(stralloc *sasv,char const *name,char const *src) ; -extern ssize_t get_sep_before (char const *line, char const sepstart, char const sepend) ; -extern void section_setsa(int id, stralloc_ref *p,section_t *sa) ; -extern int section_skip(char const *s,size_t pos,int nline) ; -extern int section_valid(int id, uint32_t nline, size_t pos,stralloc *src, char const *file) ; -extern int clean_value(stralloc *sa) ; -extern void parse_err(int ierr,int idsec,int idkey) ; extern int add_pipe(sv_alltype *sv, stralloc *sa) ; /** write */ -extern int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned int force,unsigned int conf) ; -extern int write_classic(sv_alltype *sv, char const *dst, unsigned int force, unsigned int conf) ; -extern int write_longrun(sv_alltype *sv,char const *dst, unsigned int force, unsigned int conf) ; -extern int write_oneshot(sv_alltype *sv,char const *dst, unsigned int conf) ; +extern int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, uint8_t force,uint8_t conf) ; +extern int write_classic(sv_alltype *sv, char const *dst, uint8_t force, uint8_t conf) ; +extern int write_longrun(sv_alltype *sv,char const *dst, uint8_t force, uint8_t conf) ; +extern int write_oneshot(sv_alltype *sv,char const *dst, uint8_t conf) ; extern int write_bundle(sv_alltype *sv, char const *dst) ; -extern int write_common(sv_alltype *sv, char const *dst,unsigned int conf) ; -extern int write_exec(sv_alltype *sv, sv_exec *exec,char const *name,char const *dst,int mode) ; +extern int write_common(sv_alltype *sv, char const *dst,uint8_t conf) ; +extern int write_exec(sv_alltype *sv, sv_exec *exec,char const *name,char const *dst,mode_t mode) ; extern int write_uint(char const *dst, char const *name, uint32_t ui) ; -extern int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *dst, int mode, unsigned int force) ; +extern int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *dst, mode_t mode, uint8_t force) ; extern int write_consprod(sv_alltype *sv,char const *prodname,char const *consname,char const *proddst,char const *consdst) ; -extern int write_dependencies(unsigned int nga,unsigned int idga,char const *dst,char const *filename, genalloc *ga) ; +extern int write_dependencies(unsigned int nga,unsigned int idga,char const *dst,char const *filename) ; extern int write_env(char const *name,stralloc *sa,char const *dst) ; #endif diff --git a/src/include/66/rc.h b/src/include/66/rc.h index 1485c4fc6b53ca9ed202ad8118d3a21e6325f8ee..0be2cbeac44ec742fff1b7fc16b7d54d6eb14e35 100644 --- a/src/include/66/rc.h +++ b/src/include/66/rc.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef RC_H -#define RC_H +#ifndef SS_RC_H +#define SS_RC_H #include <66/ssexec.h> diff --git a/src/include/66/resolve.h b/src/include/66/resolve.h index c02bb62b34b1bce4af4297694e29de96e4118ffa..40c03e1544e7359573aedf09e7b4ad757e0ca108 100644 --- a/src/include/66/resolve.h +++ b/src/include/66/resolve.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef SSRESOLVE_H -#define SSRESOLVE_H +#ifndef SS_RESOLVE_H +#define SS_RESOLVE_H #include <stddef.h> diff --git a/src/include/66/ssexec.h b/src/include/66/ssexec.h index 92c1c8bc277c21bc6a07769182abbfcc0206f22b..7a7b32266c1c382d923376b5f07a6921630acbb8 100644 --- a/src/include/66/ssexec.h +++ b/src/include/66/ssexec.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef SSEXEC_H -#define SSEXEC_H +#ifndef SS_SSEXEC_H +#define SS_SSEXEC_H #include <skalibs/stralloc.h> #include <skalibs/types.h> diff --git a/src/include/66/state.h b/src/include/66/state.h index 77048dbb11d85f0b74e46a0398a11ed61d62b429..a7b126c010e72c64cad5dc749bdd8f42c211d513 100644 --- a/src/include/66/state.h +++ b/src/include/66/state.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef SSSTATE_H -#define SSSTATE_H +#ifndef SS_STATE_H +#define SS_STATE_H #include <stddef.h> diff --git a/src/include/66/svc.h b/src/include/66/svc.h index d9fa724cf13999b696334febb0bb631140b312e1..8b1005a991cb62cba7d521fb1eed99d5c5fcb3ca 100644 --- a/src/include/66/svc.h +++ b/src/include/66/svc.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef SVC_H -#define SVC_H +#ifndef SS_SVC_H +#define SS_SVC_H #include <skalibs/tai.h> #include <skalibs/stralloc.h> diff --git a/src/include/66/tree.h b/src/include/66/tree.h index ac5d7f0e0e0ca812ac7b18bd11f305181ca0c3a0..6268c9133d63c52c3dd5dfc20a9037ac7f1d7701 100644 --- a/src/include/66/tree.h +++ b/src/include/66/tree.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef TREE_H -#define TREE_H +#ifndef SS_TREE_H +#define SS_TREE_H #include <sys/types.h> diff --git a/src/include/66/utils.h b/src/include/66/utils.h index d46ec1d357c41256a67bfa2bd1ce8115f64c7eff..1b9b87ad1c5e6b9290cc0be4f6fd7c688f4ea06b 100644 --- a/src/include/66/utils.h +++ b/src/include/66/utils.h @@ -12,14 +12,15 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef UTILS_H -#define UTILS_H +#ifndef SS_UTILS_H +#define SS_UTILS_H #include <sys/types.h> #include <unistd.h> //getuid #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> +#include <skalibs/gccattributes.h> #include <66/ssexec.h> #include <66/resolve.h> @@ -47,10 +48,13 @@ extern int set_livedir(stralloc *live) ; extern int set_livescan(stralloc *live,uid_t owner) ; extern int set_livetree(stralloc *live,uid_t owner) ; extern int set_livestate(stralloc *live,uid_t owner) ; -extern int insta_check(char const *svname) ; -extern int insta_create(stralloc *sasv,stralloc *sv, char const *src, int len) ; -extern int insta_splitname(stralloc *sa,char const *name,int len,int what) ; -extern int insta_replace(stralloc *sa,char const *src,char const *cpy) ; +extern int insta_check(char const *svname) gccattr_deprecated ; +extern int insta_create(stralloc *sasv,stralloc *sv, char const *src, int len) gccattr_deprecated ; +extern int insta_splitname(stralloc *sa,char const *name,int len,int what) gccattr_deprecated ; +extern int insta_replace(stralloc *sa,char const *src,char const *cpy) gccattr_deprecated ; extern int read_svfile(stralloc *sasv,char const *name,char const *src) ; - +extern int instance_check(char const *svname) ; +extern int instance_splitname(stralloc *sa,char const *name,int len,int what) ; +//extern int instance_change_name(stralloc *sa,char const *template,char const *copy) ; +extern int instance_create(stralloc *sasv,char const *svname, char const *regex, char const *src, int len) ; #endif diff --git a/src/lib66/backup_cmd_switcher.c b/src/lib66/backup_cmd_switcher.c index af12b33b8c0047929f2ab35e8bd767a5ca97eec8..a918cd5dee1fc6437b73eaf4316b96fe67538763 100644 --- a/src/lib66/backup_cmd_switcher.c +++ b/src/lib66/backup_cmd_switcher.c @@ -20,10 +20,9 @@ #include <oblibs/error2.h> #include <oblibs/string.h> #include <oblibs/types.h> -#include <oblibs/stralist.h> +#include <oblibs/sastr.h> #include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> #include <skalibs/types.h> #include <skalibs/djbunix.h> @@ -79,8 +78,7 @@ int backup_switcher(int argc, char const *const *argv,ssexec_t *info) } tree = *argv ; size_t treelen = strlen(tree) ; - - + /** $HOME/66/system/tree/servicedirs */ //base.len-- ; size_t psymlen ; @@ -172,8 +170,6 @@ int backup_switcher(int argc, char const *const *argv,ssexec_t *info) memcpy(dstback + info->base.len + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1, tree, treelen) ; memcpy(dstback + info->base.len + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + treelen, pback,pbacklen) ; dstback[info->base.len + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + treelen + pbacklen] = 0 ; - - if (what >= 0) { @@ -183,7 +179,6 @@ int backup_switcher(int argc, char const *const *argv,ssexec_t *info) return -1 ; } } - if (what) { @@ -209,15 +204,15 @@ int backup_switcher(int argc, char const *const *argv,ssexec_t *info) int backup_cmd_switcher(unsigned int verbosity,char const *cmd,ssexec_t *info) { int r ; + size_t pos = 0 ; + stralloc opts = STRALLOC_ZERO ; - genalloc opts = GENALLOC_ZERO ; - - if (!clean_val(&opts,cmd)) + if (!sastr_clean_string(&opts,cmd)) { VERBO3 strerr_warnwu2x("clean: ",cmd) ; return -1 ; } - int newopts = 5 + genalloc_len(stralist,&opts) ; + int newopts = 5 + sastr_len(&opts) ; char const *newargv[newopts] ; unsigned int m = 0 ; char fmt[UINT_FMT] ; @@ -227,15 +222,15 @@ int backup_cmd_switcher(unsigned int verbosity,char const *cmd,ssexec_t *info) newargv[m++] = "-v" ; newargv[m++] = fmt ; - for (unsigned int i = 0; i < genalloc_len(stralist,&opts); i++) - newargv[m++] = gaistr(&opts,i) ; + for (;pos < opts.len; pos += strlen(opts.s + pos) + 1) + newargv[m++] = opts.s + pos ; newargv[m++] = info->treename.s ; newargv[m++] = 0 ; r = backup_switcher(newopts,newargv,info) ; - genalloc_deepfree(stralist,&opts,stra_free) ; + stralloc_free(&opts) ; return r ; } diff --git a/src/lib66/backup_realpath_sym.c b/src/lib66/backup_realpath_sym.c index 2eec30946c53742b9ac2138fa0298f93edcc1777..8761c1880921956afd594100e3232e84c00a20a8 100644 --- a/src/lib66/backup_realpath_sym.c +++ b/src/lib66/backup_realpath_sym.c @@ -14,24 +14,24 @@ #include <66/utils.h> -#include <sys/stat.h> +#include <sys/types.h> +#include <string.h> #include <oblibs/error2.h> #include <oblibs/types.h> -#include <skalibs/uint32.h> -#include <skalibs/types.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> #include <66/constants.h> #include <66/enum.h> +#include <66/ssexec.h> int backup_realpath_sym(stralloc *sa, ssexec_t *info,unsigned int type) { ssize_t r ; size_t typelen ; - char *ptype = NULL ; + char *ptype = 0 ; if (type == CLASSIC) { @@ -56,8 +56,8 @@ int backup_realpath_sym(stralloc *sa, ssexec_t *info,unsigned int type) if(r <= 0) return 0 ; sa->len = 0 ; r = sarealpath(sa,sym) ; - if (r < 0 ) return 0 ; - if (!stralloc_0(sa)) retstralloc(0,"find_current") ; + if (r == -1 ) return 0 ; + if (!stralloc_0(sa)) retstralloc(0,"backup_realpath_sym") ; return 1 ; } diff --git a/src/lib66/db_cmd_master.c b/src/lib66/db_cmd_master.c deleted file mode 100644 index 7227c058ba2df73fd56a130d5cec090470598697..0000000000000000000000000000000000000000 --- a/src/lib66/db_cmd_master.c +++ /dev/null @@ -1,441 +0,0 @@ -/* - * db_cmd_start.c - * - * Copyright (c) 2018-2019 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/db.h> - -#include <s6-rc/config.h>//S6RC_BINPREFIX - -#include <sys/stat.h> -#include <unistd.h> - -#include <oblibs/error2.h> -#include <oblibs/string.h> -#include <oblibs/stralist.h> -#include <oblibs/files.h> -#include <oblibs/obgetopt.h> -#include <oblibs/directory.h> -#include <oblibs/strakeyval.h> - -#include <skalibs/types.h> -#include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> -#include <skalibs/djbunix.h> -#include <skalibs/avltree.h> - -#include <66/constants.h> -#include <66/parser.h> -#include <66/utils.h> - -#include <stdio.h> -//USAGE "db_update_start [ -v verbosity ] [ -a add ] [ -d delete ] [ -c copy to ] [ -B bundle ] [ -D directory ] service" -// -c -> copy the contents file to the given directory, in this case service is not mandatory -int db_update_master(int argc, char const *const *argv) -{ - int r ; - unsigned int add, del, copy, verbosity ; - - verbosity = 1 ; - - add = del = copy = 0 ; - - stralloc contents = STRALLOC_ZERO ; - stralloc tocopy = STRALLOC_ZERO ; - - genalloc in = GENALLOC_ZERO ;//type stralist - genalloc gargv = GENALLOC_ZERO ;//type stralist - - char const *bundle = 0 ; - char const *dir = 0 ; - - { - subgetopt_t l = SUBGETOPT_ZERO ; - - for (;;) - { - int opt = getopt_args(argc,argv, "v:adc:D:B:", &l) ; - if (opt == -1) break ; - if (opt == -2){ strerr_warnw1x("options must be set first") ; return 0 ; } - switch (opt) - { - case 'v' : if (!uint0_scan(l.arg, &verbosity)) return 0 ; break ; - case 'a' : add = 1 ; if (del) return 0 ; break ; - case 'd' : del = 1 ; if (add) return 0 ; break ; - case 'D' : dir = l.arg ; break ; - case 'B' : bundle = l.arg ; break ; - case 'c' : copy = 1 ; - if(!stralloc_cats(&tocopy,l.arg)) return 0 ; - if(!stralloc_0(&tocopy)) return 0 ; - break ; - default : return 0 ; - } - } - argc -= l.ind ; argv += l.ind ; - } - - if (argc < 1 && !copy) return 0 ; - if (!add && !del && !copy) return 0 ; - if (!dir) return 0 ; - if (!bundle) bundle = SS_MASTER ; - if (copy) - if (dir_scan_absopath(tocopy.s) < 0) return 0 ; - - size_t dirlen = strlen(dir) ; - size_t bundlen = strlen(bundle) ; - size_t newlen ; - char dst[dirlen + SS_DB_LEN + SS_SRC_LEN + bundlen + 1 + SS_CONTENTS_LEN + 1] ; - - if (dir_scan_absopath(dir) < 0) goto err ; - - for(;*argv;argv++) - if (!stra_add(&gargv,*argv)) retstralloc(111,"main") ; - - memcpy(dst, dir, dirlen) ; - memcpy(dst + dirlen, SS_DB, SS_DB_LEN) ; - memcpy(dst + dirlen + SS_DB_LEN, SS_SRC, SS_SRC_LEN) ; - dst[dirlen + SS_DB_LEN + SS_SRC_LEN] = '/' ; - memcpy(dst + dirlen + SS_DB_LEN + SS_SRC_LEN + 1, bundle, bundlen) ; - dst[dirlen + SS_DB_LEN + SS_SRC_LEN + 1 + bundlen] = '/' ; - newlen = dirlen + SS_DB_LEN + SS_SRC_LEN + 1 + bundlen + 1 ; - memcpy(dst + newlen, SS_CONTENTS, SS_CONTENTS_LEN) ; - dst[newlen + SS_CONTENTS_LEN] = 0 ; - - size_t filesize=file_get_size(dst) ; - - r = openreadfileclose(dst,&contents,filesize) ; - if(!r) - { - VERBO3 strerr_warnwu2sys("open: ", dst) ; - goto err ; - } - /** ensure that we have an empty line at the end of the string*/ - if (!stralloc_cats(&contents,"\n")) goto err ; - if (!stralloc_0(&contents)) goto err ; - - if (!clean_val(&in,contents.s)) - { - VERBO3 strerr_warnwu2x("clean: ",contents.s) ; - goto err ; - } - contents = stralloc_zero ; - - if (add) - { - for (unsigned int i = 0 ; i < genalloc_len(stralist,&gargv) ; i++) - { - - if (!stra_cmp(&in,gaistr(&gargv,i))) - { - if (!stra_add(&in,gaistr(&gargv,i))) - { - VERBO3 strerr_warnwu4x("add: ",gaistr(&gargv,i)," in ",dst) ; - goto err ; - } - } - } - } - - if (del) - { - for (unsigned int i = 0 ; i < genalloc_len(stralist,&gargv) ; i++) - { - if (stra_cmp(&in,gaistr(&gargv,i))) - { - if (!stra_remove(&in,gaistr(&gargv,i))) - { - VERBO3 strerr_warnwu4x("remove: ",gaistr(&gargv,i)," in ",dst) ; - goto err ; - } - } - } - } - - for (unsigned int i =0 ; i < genalloc_len(stralist,&in); i++) - { - if (!stralloc_cats(&contents,gaistr(&in,i))) goto err ; - if (!stralloc_cats(&contents,"\n")) goto err ; - } - dst[newlen] = 0 ; - - r = file_write_unsafe(dst,"contents",contents.s,contents.len) ; - if (!r) - { - VERBO3 strerr_warnwu3sys("write: ",dst,"contents") ; - goto err ; - } - - if (copy) - { - r = file_write_unsafe(tocopy.s,"contents",contents.s,contents.len) ; - if (!r) - { - VERBO3 strerr_warnwu3sys("write: ",tocopy.s,"/contents") ; - goto err ; - } - } - stralloc_free(&contents) ; - genalloc_deepfree(stralist,&in,stra_free) ; - genalloc_deepfree(stralist,&gargv,stra_free) ; - - return 1 ; - - err: - stralloc_free(&contents) ; - genalloc_deepfree(stralist,&in,stra_free) ; - genalloc_deepfree(stralist,&gargv,stra_free) ; - return 0 ; -} - -int db_cmd_master(unsigned int verbosity,char const *cmd) -{ - - int r ; - genalloc opts = GENALLOC_ZERO ; - - if (!clean_val(&opts,cmd)) - { - VERBO3 strerr_warnwu2x("clean: ",cmd) ; - genalloc_deepfree(stralist,&opts,stra_free) ; - return 0 ; - } - int newopts = 4 + genalloc_len(stralist,&opts) ; - char const *newargv[newopts] ; - unsigned int m = 0 ; - char fmt[UINT_FMT] ; - fmt[uint_fmt(fmt, verbosity)] = 0 ; - - newargv[m++] = "update_start" ; - newargv[m++] = "-v" ; - newargv[m++] = fmt ; - - for (unsigned int i = 0; i < genalloc_len(stralist,&opts); i++) - newargv[m++] = gaistr(&opts,i) ; - - newargv[m++] = 0 ; - - r = db_update_master(newopts,newargv) ; - - genalloc_deepfree(stralist,&opts,stra_free) ; - - return r ; -} - -/** action = 0 -> delete, action = 1 -> add, default delete*/ -int db_bundle_modif(genalloc *bundle,unsigned int verbosity, char const *src,unsigned int action) -{ - unsigned int i = 0 ; - size_t salen ; - stralloc update = STRALLOC_ZERO ; - char *what ; - - if (action) what = "-a" ; - else what = "-d" ; - - if (!stralloc_cats(&update,what)) return 0 ; - if (!stralloc_cats(&update," -D ")) return 0 ; - if (!stralloc_cats(&update,src)) return 0 ; - if (!stralloc_cats(&update," ")) return 0 ; - salen = update.len ; - for (;i < genalloc_len(strakeyval,bundle) ; i++) - { - update.len = salen ; - char *bname = gaikvkey(bundle,i) ; - char *svname = gaikvval(bundle,i) ; - - if (!stralloc_cats(&update,"-B ")) return 0 ; - if (!stralloc_cats(&update,bname)) return 0 ; - if (!stralloc_cats(&update," ")) return 0 ; - if (!stralloc_cats(&update,svname)) return 0 ; - if (!stralloc_0(&update)) return 0 ; - if (!db_cmd_master(verbosity,update.s)) - { - strerr_warnwu2x("update contents of bundle: ",bname) ; - return 0 ; - } - } - stralloc_free(&update) ; - - return 1 ; -} -/* -int db_bundle_contents(graph_t *g, char const *name, char const *src, unsigned int verbosity, unsigned int action) -{ - unsigned int a, b, c ; - int r = 0 ; - genalloc bundle = GENALLOC_ZERO ; - char const *string = g->string ; - for (a = 0 ; a < g->nvertex ; a++) - { - char const *bname = string + genalloc_s(vertex_graph_t,&g->vertex)[a].name ; - - if (genalloc_s(vertex_graph_t,&g->vertex)[a].type == BUNDLE) - { - - for (b = 0 ; b < genalloc_s(vertex_graph_t,&g->vertex)[a].ndeps; b++) - { - char const *depname = string + genalloc_s(vertex_graph_t,&genalloc_s(vertex_graph_t,&g->vertex)[a].dps)[b].name ; - if(obstr_equal(name,depname)) - { - for(c = 0; c < genalloc_len(strakeyval,&bundle) ; c++) - { - r = obstr_equal(depname,gaikvkey(&bundle,c)) ; - if (r) break ; - } - if (!r) - if (!strakv_add(&bundle,bname,name)) return 0 ; - } - } - } - } - if (genalloc_len(strakeyval,&bundle)) - { - if (!db_bundle_modif(&bundle,verbosity,src,action)) - goto err ; - } - genalloc_free(strakeyval,&bundle) ; - - return 1 ; - - err: - genalloc_free(strakeyval,&bundle) ; - return 0 ; -} -*/ -int db_write_contents(genalloc *ga, char const *bundle,char const *dir) -{ - int r ; - - stralloc in = STRALLOC_ZERO ; - - size_t dirlen = strlen(dir) ; - size_t bundlen = strlen(bundle) ; - - char dst[dirlen + SS_DB_LEN + SS_SRC_LEN + 1 + bundlen + 1] ; - memcpy(dst, dir, dirlen) ; - memcpy(dst + dirlen, SS_DB, SS_DB_LEN) ; - memcpy(dst + dirlen + SS_DB_LEN, SS_SRC, SS_SRC_LEN) ; - dst[dirlen + SS_DB_LEN + SS_SRC_LEN] = '/' ; - memcpy(dst + dirlen + SS_DB_LEN + SS_SRC_LEN + 1, bundle, bundlen) ; - dst[dirlen + SS_DB_LEN + SS_SRC_LEN + 1 + bundlen] = 0 ; - - for (unsigned int i = 0 ; i < genalloc_len(stralist,ga); i++) - { - if (!stralloc_cats(&in,gaistr(ga,i))) goto err ; - if (!stralloc_cats(&in,"\n")) goto err ; - } - - r = file_write_unsafe(dst,SS_CONTENTS,in.s,in.len) ; - if (!r) - { - VERBO3 strerr_warnwu3sys("write: ",dst,"contents") ; - goto err ; - } - - stralloc_free(&in) ; - - return 1 ; - - err: - stralloc_free(&in) ; - return 0 ; -} -/* -int db_write_master(ssexec_t *info, genalloc *ga, char const *dir,int both) -{ - int r ; - - char ownerstr[256] ; - size_t ownerlen = uid_fmt(ownerstr,info->owner) ; - ownerstr[ownerlen] = 0 ; - - stralloc in = STRALLOC_ZERO ; - stralloc inres = STRALLOC_ZERO ; - ss_resolve_t res = RESOLVE_ZERO ; - - size_t dirlen = strlen(dir) ; - - char runat[info->livetree.len + 1 + info->treename.len + SS_SVDIRS_LEN + SS_MASTER_LEN + 1] ; - memcpy(runat,info->livetree.s,info->livetree.len) ; - runat[info->livetree.len] = '/' ; - memcpy(runat + info->livetree.len + 1,info->treename.s,info->treename.len) ; - memcpy(runat + info->livetree.len + 1 + info->treename.len, SS_SVDIRS,SS_SVDIRS_LEN) ; - memcpy(runat + info->livetree.len + 1 + info->treename.len + SS_SVDIRS_LEN, SS_MASTER, SS_MASTER_LEN) ; - runat[info->livetree.len + 1 + info->treename.len + SS_SVDIRS_LEN + SS_MASTER_LEN] = 0 ; - - char dst[dirlen + SS_DB_LEN + SS_SRC_LEN + SS_MASTER_LEN + 1] ; - memcpy(dst, dir, dirlen) ; - memcpy(dst + dirlen, SS_DB, SS_DB_LEN) ; - memcpy(dst + dirlen + SS_DB_LEN, SS_SRC, SS_SRC_LEN) ; - memcpy(dst + dirlen + SS_DB_LEN + SS_SRC_LEN, SS_MASTER, SS_MASTER_LEN) ; - dst[dirlen + SS_DB_LEN + SS_SRC_LEN + SS_MASTER_LEN] = 0 ; - - size_t livelen = info->live.len - 1 ; - char resolve[livelen + SS_STATE_LEN + 1 + ownerlen + 1 + info->treename.len + 1] ; - memcpy(resolve,info->live.s,livelen) ; - memcpy(resolve + livelen, SS_STATE,SS_STATE_LEN) ; - resolve[livelen+ SS_STATE_LEN] = '/' ; - memcpy(resolve + livelen + SS_STATE_LEN + 1,ownerstr,ownerlen) ; - resolve[livelen + SS_STATE_LEN + 1 + ownerlen] = '/' ; - memcpy(resolve + livelen + SS_STATE_LEN + 1 + ownerlen + 1,info->treename.s,info->treename.len) ; - resolve[livelen + SS_STATE_LEN + 1 + ownerlen + 1 + info->treename.len] = 0 ; - - for (unsigned int i = 0 ; i < genalloc_len(stralist,ga); i++) - { - - if (!stralloc_cats(&in,gaistr(ga,i))) goto err ; - if (!stralloc_cats(&in,"\n")) goto err ; - - if (!stralloc_cats(&inres,gaistr(ga,i))) goto err ; - if (!stralloc_cats(&inres," ")) goto err ; - } - if (genalloc_len(stralist,ga)) inres.len--; - if (!stralloc_0(&inres)) goto err ; - - r = file_write_unsafe(dst,SS_CONTENTS,in.s,in.len) ; - if (!r) - { - VERBO3 strerr_warnwu3sys("write: ",dst,"contents") ; - goto err ; - } - - ss_resolve_init(&res) ; - res.name = ss_resolve_add_string(&res,SS_MASTER+1) ; - res.description = ss_resolve_add_string(&res,"inner bundle - do not use it") ; - res.treename = ss_resolve_add_string(&res,info->treename.s) ; - res.tree = ss_resolve_add_string(&res,info->tree.s) ; - res.live = ss_resolve_add_string(&res,info->live.s) ; - res.type = BUNDLE ; - res.deps = ss_resolve_add_string(&res,inres.s) ; - res.ndeps = genalloc_len(stralist,ga) ; - res.runat = ss_resolve_add_string(&res,runat) ; - res.resolve = ss_resolve_add_string(&res,resolve) ; - res.disen = 1 ; - res.init = 0 ; - res.unsupervise = 0 ; - res.reload = 0 ; - - if (!ss_resolve_write(&res,dir,SS_MASTER+1,both)) goto err ; - - stralloc_free(&in) ; - stralloc_free(&inres) ; - ss_resolve_free(&res) ; - - return 1 ; - - err: - ss_resolve_free(&res) ; - stralloc_free(&in) ; - stralloc_free(&inres) ; - return 0 ; -} -*/ diff --git a/src/lib66/db_compile.c b/src/lib66/db_compile.c index f58cf35318be6565f8012ae8af06a27dbdb962dc..2f64cde6dce11ceeadf6db60df34549f2246cd42 100644 --- a/src/lib66/db_compile.c +++ b/src/lib66/db_compile.c @@ -18,48 +18,47 @@ #include <string.h> #include <sys/stat.h> +#include <sys/types.h> #include <oblibs/string.h> #include <oblibs/error2.h> -#include <oblibs/directory.h> +#include <oblibs/types.h> -#include <skalibs/stralloc.h> #include <skalibs/types.h> #include <skalibs/djbunix.h> #include <66/utils.h> #include <66/constants.h> -#include <66/ssexec.h> -#include <stdio.h> int db_compile(char const *workdir, char const *tree, char const *treename, char const *const *envp) { int wstat, r ; pid_t pid ; + size_t wlen = strlen(workdir), treelen = strlen(treename) ; - stralloc source = STRALLOC_ZERO ; - stralloc destination = STRALLOC_ZERO ; - - if (!stralloc_cats(&destination,workdir)) retstralloc(0,"compile_db") ; - if (!stralloc_cats(&destination,SS_DB)) retstralloc(0,"compile_db") ; - if (!stralloc_0(&destination)) retstralloc(0,"compile_db") ; - r = dir_search(destination.s,treename,S_IFDIR) ;//+1 to remove the '/' - destination.len--; - if (!stralloc_cats(&destination,"/")) retstralloc(0,"compile_db") ; - if (!stralloc_cats(&destination,treename)) retstralloc(0,"compile_db") ; - if (!stralloc_0(&destination)) retstralloc(0,"compile_db") ; + char dest[wlen + SS_DB_LEN + 1 + treelen + 1] ; + memcpy(dest,workdir,wlen) ; + memcpy(dest + wlen,SS_DB,SS_DB_LEN) ; + dest[wlen + SS_DB_LEN] = '/' ; + memcpy(dest + wlen + SS_DB_LEN + 1,treename,treelen) ; + dest[wlen + SS_DB_LEN + 1 + treelen] = 0 ; + + char src[wlen + SS_DB_LEN + SS_SRC_LEN + 1] ; + memcpy(src,workdir,wlen) ; + memcpy(src + wlen,SS_DB,SS_DB_LEN) ; + memcpy(src + wlen + SS_DB_LEN,SS_SRC,SS_SRC_LEN) ; + src[wlen + SS_DB_LEN + SS_SRC_LEN] = 0 ; + + r = scan_mode(dest,S_IFDIR) ; if (r) { - if (rm_rf(destination.s) < 0) + if (rm_rf(dest) < 0) { - VERBO3 strerr_warnwu2sys("remove ", destination.s) ; + VERBO3 strerr_warnwu2sys("remove ", dest) ; return 0 ; } } - if (!stralloc_cats(&source,workdir)) retstralloc(0,"compile_db") ; - if (!stralloc_cats(&source,SS_DB SS_SRC)) retstralloc(0,"compile_db") ; - if (!stralloc_0(&source)) retstralloc(0,"compile_db") ; - + char const *newargv[7] ; unsigned int m = 0 ; char fmt[UINT_FMT] ; @@ -69,8 +68,8 @@ int db_compile(char const *workdir, char const *tree, char const *treename, char newargv[m++] = "-v" ; newargv[m++] = fmt ; newargv[m++] = "--" ; - newargv[m++] = destination.s ; - newargv[m++] = source.s ; + newargv[m++] = dest ; + newargv[m++] = src ; newargv[m++] = 0 ; pid = child_spawn0(newargv[0],newargv,envp) ; @@ -81,12 +80,9 @@ int db_compile(char const *workdir, char const *tree, char const *treename, char } if (wstat) { - VERBO3 strerr_warnwu2x("compile: ",destination.s) ; + VERBO3 strerr_warnwu2x("compile: ",dest) ; return 0 ; } - stralloc_free(&source) ; - stralloc_free(&destination) ; - return 1 ; } diff --git a/src/lib66/db_get_permissions.c b/src/lib66/db_get_permissions.c deleted file mode 100644 index 44a843dde59afe69e6723019b3f3058fc6d81d2e..0000000000000000000000000000000000000000 --- a/src/lib66/db_get_permissions.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * db_get_permissions.c - * - * Copyright (c) 2018-2019 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/types.h> -#include <sys/stat.h> -#include <errno.h> - -#include <oblibs/error2.h> -#include <oblibs/directory.h> -#include <oblibs/types.h> -#include <oblibs/stralist.h> -#include <oblibs/files.h> - -#include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> -#include <skalibs/types.h> - -#include <66/constants.h> - - -int db_get_permissions(stralloc *uid, char const *tree) -{ - genalloc list = GENALLOC_ZERO ; - - size_t treelen = strlen(tree) ; - char tmp[treelen + SS_RULES_LEN + 1] ; - memcpy(tmp,tree,treelen) ; - memcpy(tmp + treelen, SS_RULES, SS_RULES_LEN) ; - tmp[treelen + SS_RULES_LEN] = 0 ; - - if (!dir_get(&list,tmp,"",S_IFREG)) return 0 ; - - for (unsigned int i = 0; i < genalloc_len(stralist,&list); i++) - { - if (!stralloc_cats(uid,gaistr(&list,i))) retstralloc(0,"set_permissions_db") ; - if (!stralloc_cats(uid,",")) retstralloc(0,"set_permissions_db") ; - } - uid->len-- ;// remove the last ',' - if (!stralloc_0(uid)) retstralloc(0,"set_permissions_db") ; - - genalloc_deepfree(stralist,&list,stra_free) ; - - return 1 ; -} diff --git a/src/lib66/db_switch_to.c b/src/lib66/db_switch_to.c index af175dc7aff3fa2cd3414c142e74716a484ae637..40d9b52f0c4a3b4943e317ec188de3612dea9e4c 100644 --- a/src/lib66/db_switch_to.c +++ b/src/lib66/db_switch_to.c @@ -14,6 +14,8 @@ #include <66/db.h> +#include <string.h> + #include <oblibs/error2.h> #include <skalibs/stralloc.h> @@ -86,20 +88,6 @@ int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) VERBO3 strerr_warnwu3sys("switch db symlink of tree: ",info->treename.s," to source") ; goto err ; } - //db.len = 0 ; - /** in case of crash s6-rc-update copy again the old db to the - * original place, we need to update only the symlink */ - /*if (!backup_realpath_sym(&db,info,LONGRUN)) - { - VERBO3 strerr_warnwu2sys("find path of db service for: ",info->treename.s) ; - goto err ; - } - if (!db_update(db.s,info,envp)) - { - VERBO3 strerr_warnwu3sys("switch: ",info->treename.s," to source") ; - VERBO3 strerr_warnwu1sys("unable to rollback the db state, please make a bug report") ; - goto err ; - }*/ } } } @@ -134,18 +122,6 @@ int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) VERBO3 strerr_warnwu3sys("switch db service for: ",info->treename.s," to backup") ; goto err ; } - //db.len = 0 ; - /*if (!backup_realpath_sym(&db,info,LONGRUN)) - { - VERBO3 strerr_warnwu2sys("find path of db: ",info->treename.s) ; - goto err ; - } - if (!db_update(db.s, info,envp)) - { - VERBO3 strerr_warnwu3sys("switch: ",info->treename.s," to source") ; - VERBO3 strerr_warnwu1sys("unable to rollback the db state, please make a bug report") ; - goto err ; - }*/ } } VERBO3 strerr_warnt2x("make a backup of db service for: ",info->treename.s) ; diff --git a/src/lib66/db_update.c b/src/lib66/db_update.c index 8cc0448d69462ef949ce23190c020db2d30fb6cf..174a502ffb3dcbab5a23dcfdc0b5c7ceb18072df 100644 --- a/src/lib66/db_update.c +++ b/src/lib66/db_update.c @@ -16,14 +16,14 @@ #include <s6-rc/config.h>//S6RC_BINPREFIX -#include <sys/stat.h> +#include <sys/types.h> +#include <string.h> #include <oblibs/error2.h> #include <skalibs/types.h> #include <skalibs/djbunix.h> -#include <66/constants.h> #include <66/utils.h> #include <66/ssexec.h> diff --git a/src/lib66/deps-lib/66 b/src/lib66/deps-lib/66 index 608fa793f0106084e4acf4a049cea6c0a6cbf418..f21202a00e5c0d3f685a816bfb5fad8ccab36555 100644 --- a/src/lib66/deps-lib/66 +++ b/src/lib66/deps-lib/66 @@ -1,10 +1,8 @@ backup_cmd_switcher.o backup_make_new.o backup_realpath_sym.o -db_cmd_master.o db_compile.o db_find_compiled_state.o -db_get_permissions.o db_ok.o db_switch_to.o db_update.o diff --git a/src/lib66/environ.c b/src/lib66/environ.c index b45f01a4667a0abb5b71d6e7185e947a89fa0069..d5866ee7a315479e43c3ee75808d60ae614085b3 100644 --- a/src/lib66/environ.c +++ b/src/lib66/environ.c @@ -11,397 +11,19 @@ * This file may not be copied, modified, propagated, or distributed * except according to the terms contained in the LICENSE file./ */ - -#include <stddef.h> -#include <string.h> -#include <errno.h> + //#include <stdio.h> +#include <sys/types.h> +#include <string.h> -#include <oblibs/string.h> -#include <oblibs/stralist.h> -#include <oblibs/directory.h> +#include <oblibs/environ.h> +#include <oblibs/sastr.h> #include <oblibs/files.h> -#include <oblibs/types.h> #include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> -#include <skalibs/diuint32.h> -#include <skalibs/env.h> -#include <skalibs/strerr2.h> -#include <skalibs/djbunix.h> -#include <skalibs/bytestr.h> -#include <66/parser.h> -#include <66/environ.h> -#include <66/utils.h> #include <66/constants.h> -#include <66/config.h> - -#include <execline/execline.h> -/* @Return 1 on success - * @Return 0 on fail - * @Return -1 for empty line */ -int env_clean(stralloc *src) -{ - int r, e = 1 ; - unsigned int i ; - genalloc gatmp =GENALLOC_ZERO ;//stralist - stralloc kp = STRALLOC_ZERO ; - stralloc tmp = STRALLOC_ZERO ; - - size_t pos = 0 ; - char const *file = "env_clean" ; - parse_mill_t line = { .open = '@', .close = '=', \ - .skip = " \t\r", .skiplen = 3, \ - .end = "\n", .endlen = 1, \ - .jump = "#", .jumplen = 1,\ - .check = 0, .flush = 0, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - parse_mill_t line_end = { .open = '@', .close = '\n', \ - .skip = " \t\r", .skiplen = 3, \ - .end = "\n", .endlen = 1, \ - .jump = "#", .jumplen = 1,\ - .check = 0, .flush = 0, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - - size_t blen = src->len, n = 0 ; - if (!stralloc_inserts(src,0,"@")) goto err ; - while(pos < (blen+n) && n < 2) - { - kp.len = 0 ; - genalloc_deepfree(stralist,&gatmp,stra_free) ; - line.inner.nopen = line.inner.nclose = 0 ; - r = parse_config(!n?&line:&line_end,file,src,&kp,&pos) ; - if (!r) goto err ; - if (r < 0 && !n){ e = -1 ; goto freed ; } - if (!stralloc_0(&kp)) goto err ; - if (!clean_val(&gatmp,kp.s)) goto err ; - for (i = 0 ; i < genalloc_len(stralist,&gatmp) ; i++) - { - if ((i+1) < genalloc_len(stralist,&gatmp)) - { - if (!stralloc_cats(&tmp,gaistr(&gatmp,i))) goto err ; - if (!stralloc_cats(&tmp," ")) goto err ; - } - else if (!stralloc_cats(&tmp,gaistr(&gatmp,i))) goto err ; - } - if (!n) if (!stralloc_cats(&tmp,"=")) goto err ; - if (!stralloc_inserts(src,pos,"@")) goto err ; - n++; - } - - if (!stralloc_0(&tmp)) goto err ; - if (!stralloc_copy(src,&tmp)) goto err ; - - freed: - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - genalloc_deepfree(stralist,&gatmp,stra_free) ; - return e ; - - err: - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - genalloc_deepfree(stralist,&gatmp,stra_free) ; - return 0 ; -} - -int env_split_one(char *line,genalloc *ga,stralloc *sa) -{ - size_t slen = strlen(line) ; - char s[slen + 1] ; - memcpy(s,line,slen) ; - s[slen] = 0 ; - - char *k = 0 ; - char *v = 0 ; - diuint32 tmp = DIUINT32_ZERO ; - k = s ; - v = s ; - obstr_sep(&v,"=") ; - /** TODO, for the moment we just ignore un key with an empty - * value, this is clearely not a good way, it must be handled - * correctly. By the way the parser is currently re written and - * the env_** will changes. Just be functionnal here*/ - if (!*v) return -1 ; - tmp.left = sa->len ; - if(!stralloc_catb(sa,k,strlen(k)+1)) return 0 ; - if (!obstr_trim(v,'\n')) return 0 ; - tmp.right = sa->len ; - if(!stralloc_catb(sa,v,strlen(v)+1)) return 0 ; - if (!genalloc_append(diuint32,ga,&tmp)) return 0 ; - return 1 ; -} - -int env_split(genalloc *gaenv,stralloc *saenv,stralloc *src) -{ - int nbline = 0, i = 0 ; - genalloc gatmp = GENALLOC_ZERO ;//stralist - stralloc tmp = STRALLOC_ZERO ; - nbline = get_nbline_ga(src->s,src->len,&gatmp) ; - for (; i < nbline ; i++) - { - char *line = gaistr(&gatmp,i) ; - if (!*line) continue ; - tmp.len = 0 ; - if (!stralloc_cats(&tmp,line)) goto err ; - /** skip commented line or empty line*/ - if (env_clean(&tmp) < 0) continue ; - if (!stralloc_0(&tmp)) goto err ; - if (!env_split_one(tmp.s,gaenv,saenv)) goto err ; - } - genalloc_deepfree(stralist,&gatmp,stra_free) ; - stralloc_free(&tmp) ; - return 1 ; - err: - genalloc_deepfree(stralist,&gatmp,stra_free) ; - stralloc_free(&tmp) ; - return 0 ; -} - -int env_parsenclean(stralloc *modifs,stralloc *src) -{ - int nbline = 0, i = 0 ; - size_t pos = 0 ; - genalloc gatmp = GENALLOC_ZERO ;//stralist - stralloc tmp = STRALLOC_ZERO ; - nbline = get_nbline_ga(src->s,src->len,&gatmp) ; - - for (; i < nbline ; i++) - { - tmp.len = 0 ; - if (!gaistrlen(&gatmp,i)) break ; - if (!stralloc_cats(&tmp,gaistr(&gatmp,i))) goto err ; - if (!parse_env(&tmp,&pos)) goto err ; - if (!env_clean(&tmp)) goto err ; - tmp.len--;//remove '0' - int r = get_len_until(tmp.s,'=') ; - if (tmp.s[r+1] == SS_VAR_UNEXPORT){ - r++ ; - char t[tmp.len+1] ; - memcpy(t,tmp.s,r) ; - memcpy(t+r,tmp.s+r+1,tmp.len-(r+1)) ; - tmp.len--; - t[tmp.len] = 0 ; - if (!stralloc_catb(modifs,t,tmp.len + 1)) goto err ; - }else if (!stralloc_catb(modifs,tmp.s,tmp.len + 1)) goto err ;// || - } - - genalloc_deepfree(stralist,&gatmp,stra_free) ; - stralloc_free(&tmp) ; - return 1 ; - err: - genalloc_deepfree(stralist,&gatmp,stra_free) ; - stralloc_free(&tmp) ; - return 0 ; -} - -int make_env_from_line(char const **v,stralloc *sa) -{ - genalloc gatmp = GENALLOC_ZERO ; - stralloc copy = STRALLOC_ZERO ; - unsigned int i = 0 ; - if (!sa->len) goto err ; - if (!clean_val(&gatmp,sa->s)) goto err ; - for (;i < genalloc_len(stralist,&gatmp) ; i++) - { - char *line = gaistr(&gatmp,i) ; - if (!stralloc_catb(©,line,gaistrlen(&gatmp,i) + 1)) goto err ; - } - stralloc_copy(sa,©) ; - stralloc_free(©) ; - if (!env_make(v,i,sa->s,sa->len)) goto err ; - genalloc_deepfree(stralist,&gatmp,stra_free) ; - return i ; - err: - stralloc_free(©) ; - genalloc_deepfree(stralist,&gatmp,stra_free) ; - return 0 ; -} - -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_warnwu1x("el_vardupl") ; goto err ; } - if (!stralloc_catb(&info->vars,key, strlen(key) + 1)) { strerr_warnwu1x("append stralloc of env_substitute") ; goto err ; } - - x = env_get2(envp, key) ; - if (!x) - { - if (insist) { strerr_warnw2x(key,": is not set") ; goto err ; } - 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 ; - return 0 ; -} - -int env_addkv (const char *key, const char *val, exlsn_t *info) -{ - int r ; - 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)) goto err ; - if (!stralloc_catb (&info->vars, key, strlen(key) + 1)) goto err ; - if (!stralloc_cats (&info->values, val)) 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 ; - return 0 ; -} - -int env_get_from_src(stralloc *modifs,char const *src) -{ - int r ; - size_t filesize ; - unsigned int i ; - stralloc sa = STRALLOC_ZERO ; - genalloc toparse = GENALLOC_ZERO ; - r = scan_mode(src,S_IFDIR) ; - if (r < 0) - { - r = scan_mode(src,S_IFREG) ; - if (!r || r < 0) - { - VERBO3 strerr_warnw2sys("invalid environment: ",src) ; - goto err ; - } - filesize=file_get_size(src) ; - if (filesize > MAXENV) - { - VERBO3 strerr_warnw2x("environment too long: ",src) ; - goto err ; - } - if (!openreadfileclose(src,&sa,filesize)) - { - VERBO3 strerr_warnwu2sys("open: ",src ) ; - goto err ; - } - if (!env_parsenclean(modifs,&sa)) - { - VERBO3 strerr_warnwu2x("parse and clean environment of: ",sa.s) ; - goto err ; - } - } - else if (!r) - { - VERBO3 strerr_warnw2sys("invalid environment: ",src) ; - goto err ; - } - /** we parse all file of the directory*/ - else - { - r = dir_get(&toparse,src,"",S_IFREG) ; - if (!r) - { - VERBO3 strerr_warnwu2sys("get file from: ",src) ; - goto err ; - } - for (i = 0 ; i < genalloc_len(stralist,&toparse) ; i++) - { - sa.len = 0 ; - if (i > MAXFILE) - { - VERBO3 strerr_warnw2x("to many file to parse in: ",src) ; - goto err ; - } - if (!file_readputsa(&sa,src,gaistr(&toparse,i))) - { - VERBO3 strerr_warnw4x("read file: ",src,"/",gaistr(&toparse,i)) ; - goto err ; - } - if (!env_parsenclean(modifs,&sa)) - { - VERBO3 strerr_warnw4x("parse and clean environment of: ",src,"/",gaistr(&toparse,i)) ; - goto err ; - } - } - } - genalloc_deepfree(stralist,&toparse,stra_free) ; - stralloc_free(&sa) ; - return 1 ; - err: - genalloc_deepfree(stralist,&toparse,stra_free) ; - stralloc_free(&sa) ; - return 0 ; -} - -size_t build_env(char const *src,char const *const *envp,char const **newenv, char *tmpenv) -{ - - stralloc modifs = STRALLOC_ZERO ; - size_t envlen = env_len(envp) ; - - if (!env_get_from_src(&modifs,src)) - { - VERBO3 strerr_warnw2x("get environment file from: ",src) ; - goto err ; - } - size_t n = env_len(envp) + 1 + byte_count(modifs.s,modifs.len,'\0') ; - size_t mlen = modifs.len ; - if (mlen > MAXENV) - { - VERBO3 strerr_warnw2x("environment too long: ",src) ; - goto err ; - } - memcpy(tmpenv,modifs.s,mlen) ; - tmpenv[mlen] = 0 ; - - if (!env_merge(newenv, n, envp, envlen, tmpenv, mlen)) - { - VERBO3 strerr_warnwu2x("merge environment from: ",src) ; - goto err ; - } - - stralloc_free(&modifs) ; - - return 1 ; - err: - stralloc_free(&modifs) ; - return 0 ; -} +#include <66/utils.h> int env_resolve_conf(stralloc *env, uid_t owner) { @@ -421,68 +43,74 @@ int env_resolve_conf(stralloc *env, uid_t owner) int env_merge_conf(char const *dst,char const *file,stralloc *srclist,stralloc *modifs,unsigned int force) { - int found = 0 ; - stralloc newlist = STRALLOC_ZERO ; - // key=value from modifs - genalloc mga = GENALLOC_ZERO ;// diuint32 - stralloc msa = STRALLOC_ZERO ; - // key=value from src - genalloc ga = GENALLOC_ZERO ;// diuint32 - stralloc sa = STRALLOC_ZERO ; - char *key, *val, *mkey, *mval ; - if (!env_split(&mga,&msa,modifs)) strerr_diefu1x(111,"split key=value pair") ; - if (!env_split(&ga,&sa,srclist)) strerr_diefu3x(111,"split key=value pair of file: ",dst,file) ; - // replace existing key - for (unsigned int i = 0 ; i < genalloc_len(diuint32,&ga) ; i++) - { - found = 0 ; - key = sa.s + genalloc_s(diuint32,&ga)[i].left ; - val = sa.s + genalloc_s(diuint32,&ga)[i].right ; - if (!stralloc_cats(&newlist,key) || - !stralloc_cats(&newlist,"=")) return 0 ; - for (unsigned int j = 0 ; j < genalloc_len(diuint32,&mga) ; j++) + int r ; + size_t pos = 0, fakepos = 0 ; + stralloc result = STRALLOC_ZERO ; + stralloc sval = STRALLOC_ZERO ; + stralloc mkey = STRALLOC_ZERO ; + stralloc mval = STRALLOC_ZERO ; + + if (!environ_get_clean_env(srclist) || + !environ_clean_nline(srclist) || + !stralloc_0(srclist)) goto err ; + srclist->len-- ; + + + if (!environ_get_clean_env(modifs) || + !environ_clean_nline(modifs) || + !stralloc_0(modifs)) goto err ; + modifs->len-- ; + + if (!stralloc_copy(&result,srclist) || + !sastr_split_string_in_nline(modifs) || + !sastr_split_string_in_nline(srclist)) goto err ; + + if (!stralloc_0(&result)) goto err ; + result.len-- ; + + for (;pos < modifs->len; pos += strlen(modifs->s + pos) + 1) + { + fakepos = pos ; + sval.len = mkey.len = mval.len = 0 ; + if (!stralloc_copy(&mkey,modifs) || + !stralloc_copy(&mval,modifs) || + !stralloc_copy(&sval,srclist)) goto err ; + + if (!environ_get_key_nclean(&mkey,&pos)) goto err ; + + r = sastr_find(srclist,mkey.s) ; + if (r >= 0) { - mkey = msa.s + genalloc_s(diuint32,&mga)[j].left ; - mval = msa.s + genalloc_s(diuint32,&mga)[j].right ; - if (obstr_equal(key,mkey) && force) + if (force) { - found = 1 ; - if (!stralloc_cats(&newlist,mval)) return 0 ; - break ; + if (!environ_get_val_of_key(&sval,mkey.s) || + !environ_get_val_of_key(&mval,mkey.s) || + !sastr_replace(&result,sval.s,mval.s)) goto err ; + stralloc_0(&result) ; + result.len-- ; } } - if (!found) if (!stralloc_cats(&newlist,val)) return 0 ; - if (!stralloc_cats(&newlist,"\n")) return 0 ; - - } - // append new key coming from modifs - for (unsigned int i = 0 ; i < genalloc_len(diuint32,&mga) ; i++) - { - found = 0 ; - key = msa.s + genalloc_s(diuint32,&mga)[i].left ; - val = msa.s + genalloc_s(diuint32,&mga)[i].right ; - for (unsigned int j = 0 ; j < genalloc_len(diuint32,&ga) ; j++) - { - mkey = sa.s + genalloc_s(diuint32,&ga)[j].left ; - mval = sa.s + genalloc_s(diuint32,&ga)[j].right ; - if (obstr_equal(key,mkey)) - found = 1 ; - } - if (!found) + else { - if (!stralloc_cats(&newlist,key) || - !stralloc_cats(&newlist,"=")) return 0 ; - if (!stralloc_cats(&newlist,val)) return 0 ; - if (!stralloc_cats(&newlist,"\n")) return 0 ; + if (!stralloc_cats(&result,"\n") || + !stralloc_catb(&result,modifs->s+fakepos,strlen(modifs->s + fakepos))) goto err ; + } } - if (!file_write_unsafe(dst,file,newlist.s,newlist.len)) - strerr_diefu3sys(111,"write: ",dst,file) ; + if (!stralloc_cats(&result,"\n") || + !stralloc_0(&result)) goto err ; + result.len-- ; + if (!file_write_unsafe(dst,file,result.s,result.len)) goto err ; - stralloc_free(&newlist) ; - stralloc_free(&sa) ; - stralloc_free(&msa) ; - genalloc_free(diuint32,&mga) ; - genalloc_free(diuint32,&ga) ; + stralloc_free(&result) ; + stralloc_free(&sval) ; + stralloc_free(&mkey) ; + stralloc_free(&mval) ; return 1 ; + err: + stralloc_free(&result) ; + stralloc_free(&sval) ; + stralloc_free(&mkey) ; + stralloc_free(&mval) ; + return 0 ; } diff --git a/src/lib66/get_enum.c b/src/lib66/get_enum.c index 224f4c93f71cdbba3302385287045d489a6ae086..b2bd1bd8f22c6f59031b6a1e52d352d036926414 100644 --- a/src/lib66/get_enum.c +++ b/src/lib66/get_enum.c @@ -87,7 +87,7 @@ char const *get_keybyid(key_enum_t key) ssize_t get_enumbyid(char const *str, key_enum_t key_el) { - key_enum_t i = 0 ; + key_enum_t i = 0 ; for (;i<key_el;i++) if(obstr_equal(str,get_keybyid(i))) return i ; diff --git a/src/lib66/get_userhome.c b/src/lib66/get_userhome.c index fa47b2c7cfd12e1a76741abbed45fb941d892734..aec37b707abebefed321949e32006435a80e2891 100644 --- a/src/lib66/get_userhome.c +++ b/src/lib66/get_userhome.c @@ -22,7 +22,8 @@ char const *get_userhome(uid_t myuid) { char const *user_home = NULL ; struct passwd *st = getpwuid(myuid) ; - + int e = errno ; + errno = 0 ; if (!st) { if (!errno) errno = ESRCH ; @@ -31,6 +32,6 @@ char const *get_userhome(uid_t myuid) user_home = st->pw_dir ; if (!user_home) return 0 ; - + errno = e ; return user_home ; } diff --git a/src/lib66/instance.c b/src/lib66/instance.c index 06f56e1f698a7100acc2885eb5fe8c071a0b7139..ad9ebc56e5b7d454a8971498e2e732c367107244 100644 --- a/src/lib66/instance.c +++ b/src/lib66/instance.c @@ -19,12 +19,81 @@ #include <oblibs/error2.h> #include <oblibs/files.h> #include <oblibs/string.h> -#include <oblibs/stralist.h> #include <oblibs/directory.h> +#include <oblibs/environ.h> +#include <oblibs/sastr.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> +#include <66/enum.h> + +/** New functions */ + +int instance_check(char const *svname) +{ + int r ; + r = get_len_until(svname,'@') ; + // avoid empty value after the instance template name + if (strlen(svname+r) <= 1 && r > 0) return 0 ; + + return r ; +} + +int instance_splitname(stralloc *sa,char const *name,int len,int what) +{ + char const *copy ; + size_t tlen = len + 1 ; + + char template[tlen + 1] ; + memcpy(template,name,tlen) ; + template[tlen] = 0 ; + + copy = name + tlen ; + + sa->len = 0 ; + if (!what) + if (!stralloc_cats(sa,template) || + !stralloc_0(sa)) return 0 ; + else + if (!stralloc_catb(sa,copy,strlen(copy)) || + !stralloc_0(sa)) return 0 ; + return 1 ; +} + +int instance_create(stralloc *sasv,char const *svname, char const *regex, char const *src, int len) +{ + char const *copy ; + size_t tlen = len + 1 ; + + stralloc tmp = STRALLOC_ZERO ; + + char template[tlen + 1] ; + memcpy(template,svname,tlen) ; + template[tlen] = 0 ; + + copy = svname + tlen ; + + if (!file_readputsa(&tmp,src,template)) { + VERBO3 strerr_warnwu3sys("open: ",src,template) ; + goto err ; + } + if (!sastr_replace_all(&tmp,regex,copy)){ + VERBO3 strerr_warnwu3x("replace instance character at: ",src,template) ; + goto err ; + } + if (!stralloc_copy(sasv,&tmp)) goto err ; + stralloc_free(&tmp) ; + return 1 ; + err: + stralloc_free(&tmp) ; + return 0 ; +} + +/********************* + * Deprecated function + * *******************/ + int insta_replace(stralloc *sa,char const *src,char const *cpy) { @@ -60,8 +129,10 @@ int insta_replace(stralloc *sa,char const *src,char const *cpy) } result[curr] = 0 ; - - return stralloc_obreplace(sa,result) ; + sa->len = 0 ; + if (!stralloc_cats(sa,result) || + !stralloc_0(sa)) return 0 ; + return 1 ; } /** instance -> 0, copy -> 1 */ @@ -76,10 +147,14 @@ int insta_splitname(stralloc *sa,char const *name,int len,int what) copy = name + tlen ; + sa->len = 0 ; if (!what) - return stralloc_obreplace(sa,template) ; + if (!stralloc_cats(sa,template) || + !stralloc_0(sa)) return 0 ; else - return stralloc_obreplace(sa,copy) ; + if (!stralloc_catb(sa,copy,strlen(copy)) || + !stralloc_0(sa)) return 0 ; + return 1 ; } int insta_create(stralloc *sasv,stralloc *sv, char const *src, int len) @@ -130,8 +205,10 @@ int insta_create(stralloc *sasv,stralloc *sv, char const *src, int len) stralloc_free(&sa) ; stralloc_free(&tmp) ; - - return stralloc_obreplace(sv,copy) ; + sv->len = 0 ; + if (!stralloc_catb(sv,copy,strlen(copy)) || + !stralloc_0(sv)) return 0 ; + return 1 ; } int insta_check(char const *svname) diff --git a/src/lib66/parser.c b/src/lib66/parser.c index 98c6d4513d11ac98f30e4f7436b6431b7552f74e..78e34a30a43c2871ce89eda477d180478fd2bd89 100644 --- a/src/lib66/parser.c +++ b/src/lib66/parser.c @@ -13,6 +13,8 @@ */ #include <string.h> +#include <stdint.h> +#include <stdint.h> //#include <stdio.h> #include <oblibs/error2.h> @@ -20,6 +22,7 @@ #include <oblibs/files.h> #include <oblibs/stralist.h> #include <oblibs/obgetopt.h> +#include <oblibs/mill.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> @@ -31,186 +34,57 @@ #include <66/utils.h> #include <66/parser.h> -inline uint8_t cclass (parse_mill_t *p) -{ - size_t i = 0 ; - - if (!p->inner.curr) return 0 ; - else if (p->inner.curr == '\n') - { - if (p->flush) p->inner.flushed = 1 ; - p->inner.jumped = 0 ; - p->inner.nline++ ; - } - for (; i < p->jumplen ; i++) - { - if (p->inner.curr == p->jump[i]) - { - p->inner.jumped = 1 ; - return 2 ; - } - } - for (i = 0 ; i < p->endlen ; i++) - { - if (p->inner.curr == p->end[i]) - { - if (p->inner.curr == p->close) p->inner.nclose++ ; - return 3 ; - } - } - for (i = 0 ; i < p->skiplen ; i++) - { - if (p->inner.curr == p->skip[i]) - { - if (p->open && !p->forceskip) return 1 ; - return 0 ; - } - } - /* close and open can be the same, in this case - * we skip open if it already found */ - if (p->inner.curr == p->open && !p->inner.nopen) - { - p->inner.nopen++ ; - return 0 ; - } - - if (p->inner.curr == p->close) - { - p->inner.nclose++ ; - if (p->force) return 3 ; - return 0 ; - } - - return 1 ; -} -inline char next(stralloc *s,size_t *pos) +int parser(sv_alltype *service,stralloc *src,char const *svname) { - char c ; - if (*pos >= s->len) return -1 ; - c = s->s[*pos] ; - (*pos) += 1 ; - return c ; -} -/** @Return 1 on sucess - * @Return 0 on fail - * @Return 2 for end of file - * @Return -1 if close was not found */ -inline int parse_config(parse_mill_t *p,char const *file, stralloc *src, stralloc *kp,size_t *pos) -{ - uint8_t what = 0 ; - static uint8_t const table[5] = { IGN, KEEP, JUMP, EXIT, END } ; - uint8_t state = 1, end = 0 ; - char j = 0 ; - while (state) - { - p->inner.curr = next(src, pos) ; - what = table[cclass(p)] ; - // end of file - if (p->inner.curr == -1) what = END ; - if (p->inner.flushed) - { - kp->len = 0 ; - p->inner.nopen = 0 ; - p->inner.nclose = 0 ; - p->inner.flushed = 0 ; - what = SKIP ; - } - switch(what) - { - case KEEP: - if (p->inner.nopen && !p->inner.jumped) - if (!stralloc_catb(kp,&p->inner.curr,1)) return 0 ; - break ; - case JUMP: - if (!p->inner.nopen) - { - while (j != '\n') - { - j = next(src,pos) ; - if (j < 0) break ;//end of string - } - p->inner.jumped = 0 ; - p->inner.nline++ ; - } - break ; - case IGN: - break ; - case EXIT: - state = 0 ; - break ; - case END: - state = 0 ; - end = 1 ; - break ; - default: break ; - } - } - - if (p->check && p->inner.nopen != p->inner.nclose) - { - char fmt[UINT_FMT] ; - fmt[uint_fmt(fmt, p->inner.nline-1)] = 0 ; - char sepopen[2] = { p->open,0 } ; - char sepclose[2] = { p->close,0 } ; - strerr_warnw6x("umatched ",(p->inner.nopen > p->inner.nclose) ? sepopen : sepclose," in: ",file," at line: ",fmt) ; - return 0 ; - } - if (!p->inner.nclose) return -1 ; - if (end) return 2 ; - return 1 ; -} - -int parser(sv_alltype *service,stralloc *src,char const *file) -{ - int r ; - int svtype = -1 ; + int r , svtype = -1 ; + size_t i = 0 ; section_t sasection = SECTION_ZERO ; genalloc ganocheck = GENALLOC_ZERO ; - sasection.file = file ; + sasection.file = svname ; - r = get_section_range(&sasection,src) ; + r = section_get_range(&sasection,src) ; if (r <= 0){ - strerr_warnwu2x("parse section of service file: ",file) ; + strerr_warnwu2x("parse section of service file: ",svname) ; goto err ; } if (!sasection.idx[MAIN]) { - VERBO1 strerr_warnw2x("missing section [main] in service file: ", file) ; + VERBO1 strerr_warnw2x("missing section [main] in service file: ", svname) ; goto err ; } - if (!get_key_range(&ganocheck,&sasection,file,&svtype)) goto err ; + if (!key_get_range(&ganocheck,&sasection,&svtype)) goto err ; if (svtype < 0) { - VERBO1 strerr_warnw2x("invalid value for key: @type in service file: ",file) ; + VERBO1 strerr_warnw4x("invalid value for key: ",get_keybyid(TYPE)," in service file: ",svname) ; goto err ; } if (svtype != BUNDLE && !sasection.idx[START]) { - VERBO1 strerr_warnw2x("missing section [start] in service file: ", file) ; + VERBO1 strerr_warnw2x("missing section [start] in service file: ", svname) ; goto err ; } if (!genalloc_len(keynocheck,&ganocheck)){ - VERBO1 strerr_warnw2x("empty service file: ",file) ; + VERBO1 strerr_warnw2x("empty service file: ",svname) ; goto err ; } - for (unsigned int i = 0;i < genalloc_len(keynocheck,&ganocheck);i++) + for (i = 0;i < genalloc_len(keynocheck,&ganocheck);i++) { uint32_t idsec = genalloc_s(keynocheck,&ganocheck)[i].idsec ; - for (int j = 0;j < total_list_el[idsec] && total_list[idsec].list > 0;j++) + for (unsigned int j = 0;j < total_list_el[idsec] && total_list[idsec].list > 0;j++) { if (!get_mandatory(&ganocheck,idsec,j)) { - VERBO1 strerr_warnw2x("mandatory key is missing in service file: ",file) ; + VERBO1 strerr_warnw2x("mandatory key is missing in service file: ",svname) ; goto err ; } } } - for (unsigned int i = 0;i < genalloc_len(keynocheck,&ganocheck);i++) + for (i = 0;i < genalloc_len(keynocheck,&ganocheck);i++) { if (!nocheck_toservice(&(genalloc_s(keynocheck,&ganocheck)[i]),svtype,service)) { - VERBO1 strerr_warnwu2x("keep information of service file: ",file) ; + VERBO1 strerr_warnwu2x("keep information of service file: ",svname) ; goto err ; } } diff --git a/src/lib66/parser_enabled.c b/src/lib66/parser_enabled.c index 0918f6a22471a55e9c1f019cec1254629840ec7c..efc5ab9a9c615e82043ad552d05a9095c39cb91e 100644 --- a/src/lib66/parser_enabled.c +++ b/src/lib66/parser_enabled.c @@ -30,167 +30,138 @@ #include <66/constants.h> #include <66/environ.h> -int parse_service_get_list(stralloc *result, stralloc *list) +int parse_service_check_enabled(ssexec_t *info, char const *svname,uint8_t force,uint8_t *exist) { - int found ; - size_t i = 0, len = list->len ; - for (;i < len; i += strlen(list->s + i) + 1) + stralloc sares = STRALLOC_ZERO ; + ss_resolve_t res = RESOLVE_ZERO ; + int ret = 1 ; + if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) { - found = 0 ; - char *name = list->s+i ; - size_t svlen = strlen(name) ; - char svname[svlen + 1] ; - char svsrc[svlen + 1] ; - if (!basename(svname,name)) return 0 ; - if (!dirname(svsrc,name)) return 0 ; - if (ss_resolve_src(result,svname,svsrc,&found) <= 0) return 0 ; + VERBO3 strerr_warnwu1sys("set revolve pointer to source") ; + goto err ; + } + if (ss_resolve_check(sares.s,svname)) + { + if (!ss_resolve_read(&res,sares.s,svname)) + { + VERBO3 strerr_warnwu2sys("read resolve file of: ",svname) ; + goto err ; + } + if (res.disen) + { + (*exist) = 1 ; + if (!force) { + VERBO1 strerr_warnw3x("Ignoring: ",svname," service: already enabled") ; + ret = 2 ; + goto freed ; + } + } } - return 1 ; + freed: + stralloc_free(&sares) ; + ss_resolve_free(&res) ; + return ret ; + err: + stralloc_free(&sares) ; + ss_resolve_free(&res) ; + return 0 ; } int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *service,unsigned int *nbsv,uid_t owner) { stralloc conf = STRALLOC_ZERO ; size_t svlen = strlen(service) ; - char svsrc[svlen + 1] ; - if (!dirname(svsrc,service)) return 0 ; - size_t srclen = strlen(svsrc) ; // keep source of the frontend file sv_before->src = keep.len ; - if (!stralloc_catb(&keep,svsrc,srclen + 1)) return 0 ; + if (!stralloc_catb(&keep,service,svlen + 1)) goto err ; // keep source of the configuration file if (sv_before->opts[2]) { - if (!env_resolve_conf(&conf,owner)) return 0 ; + if (!env_resolve_conf(&conf,owner)) goto err ; sv_before->srconf = keep.len ; - if (!stralloc_catb(&keep,conf.s,conf.len + 1)) return 0 ; + if (!stralloc_catb(&keep,conf.s,conf.len + 1)) goto err ; } // keep service on current list - if (!stralloc_catb(parsed_list,service,svlen + 1)) return 0 ; - if (!genalloc_append(sv_alltype,&gasv,sv_before)) return 0 ; + if (!stralloc_catb(parsed_list,service,svlen + 1)) goto err ; + if (!genalloc_append(sv_alltype,&gasv,sv_before)) goto err ; (*nbsv)++ ; stralloc_free(&conf) ; return 1 ; - - - + err: + stralloc_free(&conf) ; + return 0 ; } -int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,unsigned int force) +int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,uint8_t force) { - unsigned int exist = 0 ; + uint8_t exist = 0 ; char *dname = 0 ; stralloc newsv = STRALLOC_ZERO ; if (sv_before->cname.nga) { - for (int i = 0;i < sv_before->cname.nga;i++) + size_t id = sv_before->cname.idga, nid = sv_before->cname.nga ; + for (;nid; id += strlen(deps.s + id) + 1, nid--) { newsv.len = 0 ; if (sv_before->cname.itype != BUNDLE) { - VERBO3 strerr_warni4x("Service : ",sv, " depends on : ",deps.s+(genalloc_s(unsigned int,&gadeps)[sv_before->cname.idga+i])) ; - }else VERBO3 strerr_warni5x("Bundle : ",sv, " contents : ",deps.s+(genalloc_s(unsigned int,&gadeps)[sv_before->cname.idga+i])," as service") ; - - dname = deps.s+(genalloc_s(unsigned int,&gadeps)[sv_before->cname.idga+i]) ; + VERBO3 strerr_warni4x("Service : ",sv, " depends on : ",deps.s+id) ; + }else VERBO3 strerr_warni5x("Bundle : ",sv, " contents : ",deps.s+id," as service") ; + dname = deps.s + id ; if (!ss_resolve_src_path(&newsv,dname,info)) { VERBO3 strerr_warnwu2x("resolve source path of: ",dname) ; - stralloc_free(&newsv) ; - return 0 ; - } - if (!parse_service_before(info,parsed_list,newsv.s,nbsv,sasv,force,exist)) - { - stralloc_free(&newsv) ; - return 0 ; + goto err ; } + if (!parse_service_before(info,parsed_list,newsv.s,nbsv,sasv,force,&exist)) goto err ; } } else VERBO3 strerr_warni2x(sv,": haven't dependencies") ; stralloc_free(&newsv) ; return 1 ; + err: + stralloc_free(&newsv) ; + return 0 ; } -int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,unsigned int force,unsigned int exist) +int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,uint8_t force,uint8_t *exist) { - int r = 0 , insta ; - size_t svlen = strlen(sv), svsrclen ; - - char svname[svlen + 1] ; - char svsrc[svlen + 1] ; - char svpath[svlen + 1] ; + int r, insta ; + size_t svlen = strlen(sv), svsrclen, svnamelen ; + char svname[svlen + 1], svsrc[svlen + 1], svpath[svlen + 1] ; if (!basename(svname,sv)) return 0 ; if (!dirname(svsrc,sv)) return 0 ; svsrclen = strlen(svsrc) ; + svnamelen = strlen(svname) ; if (scan_mode(sv,S_IFDIR) == 1) return 1 ; - - stralloc newsv = STRALLOC_ZERO ; - stralloc tmp = STRALLOC_ZERO ; - - { - if (!set_ownerhome(&tmp,info->owner)) - { - VERBO3 strerr_warnwu1sys("set home directory") ; - goto err ; - } - if (!stralloc_cats(&tmp,info->tree.s)) retstralloc(0,"parse_service_before") ; - if (!stralloc_cats(&tmp,SS_SVDIRS)) retstralloc(0,"parse_service_before") ; - if (!stralloc_cats(&tmp,SS_DB)) retstralloc(0,"parse_service_before") ; - if (!stralloc_cats(&tmp,SS_SRC)) retstralloc(0,"parse_service_before") ; - if (!stralloc_0(&tmp)) retstralloc(0,"parse_service_before") ; - - insta = insta_check(svname) ; - if (!insta) - { - VERBO3 strerr_warnw2x("invalid instance name: ",svname) ; - goto err ; - } - if (insta > 0) - { - if (!insta_splitname(&newsv,svname,insta,1)) - { - VERBO3 strerr_warnwu2x("split copy name of instance: ",svname) ; - goto err ; - } - } - else if (!stralloc_cats(&newsv,svname)) retstralloc(0,"parse_service_before") ; - if (!stralloc_0(&newsv)) goto err ; - r = dir_search(tmp.s,newsv.s,S_IFDIR) ; - if (r && !force) { - VERBO2 strerr_warni2x(newsv.s,": already added") ; - goto freed ; - } - else if (r < 0) - { - VERBO3 strerr_warnw3x("Conflicting format type for ",newsv.s," service file") ; - goto err ; - } - newsv.len = 0 ; - } - if (!stralloc_cats(&newsv,svname)) goto err ; - if (!stralloc_0(&newsv)) goto err ; + r = parse_service_check_enabled(info,svname,force,exist) ; + if (r == 2) goto freed ; + else if (!r) return 0 ; sv_alltype sv_before = SV_ALLTYPE_ZERO ; - insta = insta_check(newsv.s) ; + insta = instance_check(svname) ; if (!insta) { - VERBO3 strerr_warnw2x("invalid instance name: ",newsv.s) ; - goto err ; + VERBO3 strerr_warnw2x("invalid instance name: ",svname) ; + return 0 ; } if (insta > 0) { - - if (!insta_create(sasv,&newsv,svsrc,insta)) + if (!instance_create(sasv,svname,SS_INSTANCE,svsrc,insta)) { - VERBO3 strerr_warnwu2x("create instance service: ",newsv.s) ; - goto err ; + VERBO3 strerr_warnwu2x("create instance service: ",svname) ; + return 0 ; } - - }else if (!read_svfile(sasv,newsv.s,svsrc)) goto err ; + /** ensure that we have an empty line at the end of the string*/ + if (!stralloc_cats(sasv,"\n")) retstralloc(0,"parse_service_before") ; + if (!stralloc_0(sasv)) retstralloc(0,"parse_service_before") ; + }else if (!read_svfile(sasv,svname,svsrc)) return 0 ; memcpy(svpath,svsrc,svsrclen) ; - memcpy(svpath + svsrclen,newsv.s,newsv.len) ; + memcpy(svpath + svsrclen,svname,svnamelen) ; + svpath[svsrclen + svnamelen] = 0 ; if (sastr_cmp(parsed_list,svpath) >= 0) { @@ -199,20 +170,44 @@ int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,un sv_alltype_free(&sv_before) ; goto freed ; } + + if (!parser(&sv_before,sasv,svname)) return 0 ; - if (!parser(&sv_before,sasv,newsv.s)) goto err ; + /** keep the name set by user + * uniquely for instantiated service + * The name must contain the template string */ - if (!parse_add_service(parsed_list,&sv_before,svpath,nbsv,info->owner)) goto err ; + if (insta > 0 && sv_before.cname.name >= 0 ) + { + stralloc sainsta = STRALLOC_ZERO ; + stralloc name = STRALLOC_ZERO ; + if (!stralloc_cats(&name,keep.s + sv_before.cname.name)) goto err ; + + if (!instance_splitname(&sainsta,svname,insta,0)) goto err ; + if (sastr_find(&name,sainsta.s) == -1) + { + strerr_warnw2x("invalid instantiated service name: ", keep.s + sv_before.cname.name) ; + goto err ; + } + stralloc_free(&sainsta) ; + stralloc_free(&name) ; + goto add ; + err: + stralloc_free(&sainsta) ; + stralloc_free(&name) ; + return 0 ; + } + else + { + sv_before.cname.name = keep.len ; + if (!stralloc_catb(&keep,svname,svnamelen + 1)) return 0 ; + } + add: + if (!parse_add_service(parsed_list,&sv_before,svpath,nbsv,info->owner)) return 0 ; - if ((sv_before.cname.itype > CLASSIC && force > 1) || !exist) - if (!parse_service_deps(info,parsed_list,&sv_before,sv,nbsv,sasv,force)) goto err ; + if ((sv_before.cname.itype > CLASSIC && force > 1) || !(*exist)) + if (!parse_service_deps(info,parsed_list,&sv_before,sv,nbsv,sasv,force)) return 0 ; freed: - stralloc_free(&newsv) ; - stralloc_free(&tmp) ; return 1 ; - err: - stralloc_free(&newsv) ; - stralloc_free(&tmp) ; - return 0 ; } diff --git a/src/lib66/parser_utils.c b/src/lib66/parser_utils.c index a7fbd0ccac4bce62c003666742d9687a2b5c904d..9784969ee46aaa126f4ccc49ea9ebe099795be68 100644 --- a/src/lib66/parser_utils.c +++ b/src/lib66/parser_utils.c @@ -17,6 +17,10 @@ #include <string.h> #include <unistd.h>//getuid #include <stdlib.h> +#include <stdint.h> +#include <sys/types.h> +#include <pwd.h> +#include <errno.h> //#include <stdio.h> #include <oblibs/bytes.h> @@ -24,8 +28,9 @@ #include <oblibs/files.h> #include <oblibs/error2.h> #include <oblibs/types.h> -#include <oblibs/directory.h> -#include <oblibs/strakeyval.h> +#include <oblibs/mill.h> +#include <oblibs/environ.h> +#include <oblibs/sastr.h> #include <skalibs/sig.h> #include <skalibs/genalloc.h> @@ -38,16 +43,33 @@ #include <66/constants.h> #include <66/enum.h> #include <66/utils.h>//MYUID -#include <66/environ.h>//MYUID stralloc keep = STRALLOC_ZERO ;//sv_alltype data stralloc deps = STRALLOC_ZERO ;//sv_name depends -genalloc gadeps = GENALLOC_ZERO ;//unsigned int, pos in deps +//genalloc gadeps = GENALLOC_ZERO ;//unsigned int, pos in deps genalloc gasv = GENALLOC_ZERO ;//sv_alltype general +/********************************** + * function helper declaration + * *******************************/ + +void section_setsa(int id, stralloc_ref *p,section_t *sa) ; +int section_get_skip(char const *s,size_t pos,int nline) ; +int section_get_id(stralloc *secname, char const *string,size_t *pos,int *id) ; +int key_get_next_id(stralloc *sa, char const *string,size_t *pos) ; +int get_clean_val(keynocheck *ch) ; +int get_enum(char const *string, keynocheck *ch) ; +int get_timeout(keynocheck *ch,uint32_t *ui) ; +int get_uint(keynocheck *ch,uint32_t *ui) ; +int check_valid_runas(keynocheck *check) ; +void parse_err(int ierr,keynocheck *check) ; +int parse_line(stralloc *sa, size_t *pos) ; +int parse_bracket(stralloc *sa,size_t *pos) ; + /********************************** * freed function * *******************************/ + void sv_alltype_free(sv_alltype *sv) { stralloc_free(&sv->saenv) ; @@ -73,232 +95,82 @@ void freed_parser(void) { stralloc_free(&keep) ; stralloc_free(&deps) ; - genalloc_free(unsigned int,&gadeps) ; +// genalloc_free(unsigned int,&gadeps) ; for (unsigned int i = 0 ; i < genalloc_len(sv_alltype,&gasv) ; i++) sv_alltype_free(&genalloc_s(sv_alltype,&gasv)[i]) ; } /********************************** - * parser utilities + * Mill utilities * *******************************/ -int parse_line(stralloc *src, size_t *pos) -{ - size_t newpos = 0 ; - stralloc kp = STRALLOC_ZERO ; - char const *file = "parse_line" ; - parse_mill_t line = { .open = '@', .close = '\n', \ - .skip = " \t\r", .skiplen = 3, \ - .end = "\n", .endlen = 1, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 0, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - - stralloc_inserts(src,0,"@") ; - if (!parse_config(&line,file,src,&kp,&newpos)) goto err ; - if (!stralloc_0(&kp)) goto err ; - if (!clean_value(&kp)) goto err ; - if (!stralloc_copy(src,&kp)) goto err ; - *pos += newpos - 1 ; - stralloc_free(&kp) ; - return 1 ; - err: - stralloc_free(&kp) ; - return 0 ; -} + +parse_mill_t MILL_FIRST_BRACKET = \ +{ \ + .search = "(", .searchlen = 1, \ + .end = ")", .endlen = 1, \ + .inner.debug = "first_bracket" } ; -int parse_quote(stralloc *src,size_t *pos) -{ - int r, err = 0 ; - size_t newpos = 0 ; - char const *file = "parse_quote" ; - stralloc kp = STRALLOC_ZERO ; - parse_mill_t quote = { .open = '"', .close = '"', \ - .skip = 0, .skiplen = 0, \ - .end = "\n", .endlen = 1, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 0, \ - .forceskip = 0, .force = 0, \ - .inner = PARSE_MILL_INNER_ZERO } ; +parse_mill_t MILL_GET_AROBASE_KEY = \ +{ \ + .open = '@', .close = '=', .keepopen = 1, \ + .flush = 1, \ + .forceclose = 1, .skip = " \t\r", .skiplen = 3, \ + .forceskip = 1, .inner.debug = "get_arobase_key" } ; - r = parse_config("e,file,src,&kp,&newpos) ; - if (!r) goto err ; - else if (r == -1) { err = -1 ; goto err ; } - if (!stralloc_0(&kp)) goto err ; - if (!stralloc_copy(src,&kp)) goto err ; - *pos += newpos - 1 ; - stralloc_free(&kp) ; - return 1 ; - err: - stralloc_free(&kp) ; - return err ; -} +parse_mill_t MILL_GET_COMMENTED_KEY = \ +{ \ + .search = "#", .searchlen = 1, \ + .end = "@", .endlen = 1, + .inner.debug = "get_commented_key" } ; -int parse_bracket(stralloc *src,size_t *pos) -{ - int err = -1 ; - size_t newpos = 0 ; - ssize_t id = -1, start = -1, end = -1 ; - char const *file = "parse_bracket" ; - stralloc kp = STRALLOC_ZERO ; - stralloc tmp = STRALLOC_ZERO ; - - parse_mill_t key = { .open = '@', .close = '=', \ - .skip = " \n\t\r", .skiplen = 4, \ - .end = 0, .endlen = 0, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 1, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; +parse_mill_t MILL_GET_SECTION_NAME = \ +{ \ + .open = '[', .close = ']', \ + .forceclose = 1, .forceskip = 1, \ + .skip = " \t\r", .skiplen = 3, \ + .inner.debug = "get_section_name" } ; - - while (id < 0 && newpos < src->len) - { - kp.len = 0 ; - key.inner.nclose = 0 ; - key.inner.nopen = 0 ; - if (!parse_config(&key,file,src,&kp,&newpos)) goto err ; - if (!kp.len) break ;//end of string - if (!stralloc_0(&kp)) goto err ; - if (!clean_value(&kp)) goto err ; - if (!stralloc_inserts(&kp,0,"@")) goto err ; - id = get_enumbyid(kp.s,key_enum_el) ; - } - /** id is negative and we are at the end of string - * field can contain instance name with @ character - * in this case we keep the src as it */ - if (id < 0) - { - if (!stralloc_cats(&tmp,src->s)) goto err ; - }else if (!stralloc_catb(&tmp,src->s,(newpos - (kp.len+1)))) goto err ;//+1 remove the @ of the next key - if (!stralloc_0(&tmp)) goto err ; - kp.len = 0 ; - start = get_len_until(tmp.s,'(') ; - if (start < 0) { err = -1 ; goto err ; } - start++ ; - end = get_rlen_until(tmp.s,')',tmp.len) ; - if (end < 0) { err = -1 ; goto err ; } - if (!stralloc_catb(&kp,tmp.s+start,end-start)) goto err ; - if (!stralloc_0(&kp)) goto err ; - if (!stralloc_copy(src,&kp)) goto err ; - *pos += end + 1 ; //+1 to remove the last ')' - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - return 1 ; - err: - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - return err ; -} - -int parse_env(stralloc *src,size_t *pos) -{ - int r ; - size_t newpos = 0 ; - size_t base ; - stralloc kp = STRALLOC_ZERO ; - stralloc tmp = STRALLOC_ZERO ; - char const *file = "parse_env" ; - parse_mill_t line = { .open = '@', .close = '\n', \ - .skip = " \t\r", .skiplen = 3, \ - .end = "\n", .endlen = 1, \ - .jump = "#", .jumplen = 1,\ - .check = 0, .flush = 0, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - - size_t blen = src->len, n = 0 ; - if (!stralloc_inserts(src,0,"@")) goto err ; - while(newpos < (blen+n)) - { - base = kp.len ; - line.inner.nopen = line.inner.nclose = 0 ; - r = parse_config(&line,file,src,&kp,&newpos) ; - if (!r) goto err ; - else if (r < 0){ kp.len = base ; goto append ; } - if (!stralloc_cats(&kp,"\n")) goto err ; - append: - if (!stralloc_inserts(src,newpos,"@")) goto err ; - n++; - } - if (!stralloc_0(&kp)) goto err ; - if (!stralloc_copy(src,&kp)) goto err ; - *pos += newpos - 1 ; - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - return 1 ; - err: - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - return 0 ; -} - /********************************** * parser split function * *******************************/ -int get_section_range(section_t *sasection,stralloc *src) +int section_get_range(section_t *sasection,stralloc *src) { + if (!src->len) return 0 ; size_t pos = 0, start = 0 ; - int n = 0, id = -1, /*idc = 0,*/ skip = 0, err = 0 ; + int r, n = 0, id = -1, skip = 0 ; stralloc secname = STRALLOC_ZERO ; stralloc_ref psasection ; - parse_mill_t section = { .open = '[', .close = ']', \ - .skip = " \n\t\r", .skiplen = 4, \ - .end = 0, .endlen = 0, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 1, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - - while (pos < src->len) + stralloc cp = STRALLOC_ZERO ; + /** be clean */ + wild_zero_all(&MILL_GET_LINE) ; + wild_zero_all(&MILL_GET_SECTION_NAME) ; + r = mill_string(&cp,src,&MILL_GET_LINE) ; + if (r == -1 || !r) goto err ; + if (!sastr_rebuild_in_nline(&cp)) goto err ; + while (pos < cp.len) { if(secname.len && n) { - skip = section_skip(src->s,pos,section.inner.nline) ; + skip = section_get_skip(cp.s,pos,MILL_GET_SECTION_NAME.inner.nline) ; id = get_enumbyid(secname.s,key_enum_section_el) ; section_setsa(id,&psasection,sasection) ; if (skip) sasection->idx[id] = 1 ; } - secname.len = section.inner.nclose = section.inner.nopen = 0 ; - id = -1 ; - while (id < 0 && pos < src->len) - { - secname.len = section.inner.nclose = section.inner.nopen = 0 ; - if(!parse_config(§ion,sasection->file,src,&secname,&pos)) goto err ; - if (!secname.len) break ; //end of string - if (!stralloc_0(&secname)) goto err ; - id = get_enumbyid(secname.s,key_enum_section_el) ; - /*if (id < 0) - { - idc = section_valid(id,section.inner.nline,pos,src,sasection->file) ; - if (!idc) goto err ; - else if (idc < 0) goto invalid ; - }*/ - } + if (!section_get_id(&secname,cp.s,&pos,&id)) goto err ; + if (!secname.len && !n) goto err ; if (!n) { - skip = section_skip(src->s,pos,section.inner.nline) ; + skip = section_get_skip(cp.s,pos,MILL_GET_SECTION_NAME.inner.nline) ; section_setsa(id,&psasection,sasection) ; if (skip) sasection->idx[id] = 1 ; start = pos ; - id = -1 ; - while (id < 0 && pos < src->len) - { - section.inner.nclose = section.inner.nopen = secname.len = 0 ; - if (!parse_config(§ion,sasection->file,src,&secname,&pos)) goto err ; - if (!secname.len) break ; //end of string - if (!stralloc_0(&secname)) goto err ; - id = get_enumbyid(secname.s,key_enum_section_el) ; - /*if (id < 0) - { - idc = section_valid(id,section.inner.nline,pos,src,sasection->file) ; - if (!idc) goto err ; - else if (idc < 0) goto invalid ; - }*/ - } + + if (!section_get_id(&secname,cp.s,&pos,&id)) goto err ; if(skip) { - if (!stralloc_catb(psasection,src->s+start,(pos - start) - (secname.len + 2))) goto err ;//+2 to remove '[]'character + r = get_rlen_until(cp.s,'\n',pos-1) ;//-1 to retrieve the end of previous line + if (r == -1) goto err ; + if (!stralloc_catb(psasection,cp.s+start,(r-start))) goto err ; if (!stralloc_0(psasection)) goto err ; } n++ ; @@ -308,37 +180,37 @@ int get_section_range(section_t *sasection,stralloc *src) { if (skip) { - if (!stralloc_catb(psasection,src->s+start,(pos - start) - (secname.len + 1))) goto err ;//only -1 to remove '\n'character + /** end of file do not contain section, avoid to remove the len of it if in the case*/ + if (secname.len) + { + r = get_rlen_until(cp.s,'\n',pos-1) ;//-1 to retrieve the end of previous line + if (r == -1) goto err ; + if (!stralloc_catb(psasection,cp.s+start,(r - start))) goto err ; + + } + else if (!stralloc_catb(psasection,cp.s+start,cp.len - start)) goto err ; if (!stralloc_0(psasection)) goto err ; } start = pos ; } } stralloc_free(&secname) ; + stralloc_free(&cp) ; return 1 ; - /*invalid: - err = -1 ; - VERBO1 strerr_warnw2x("invalid section: ",secname.s) ; - */err: + err: stralloc_free(&secname) ; - return err ; + stralloc_free(&cp) ; + return 0 ; } -int get_key_range(genalloc *ga, section_t *sasection,char const *file,int *svtype) +int key_get_range(genalloc *ga, section_t *sasection,int *svtype) { int r ; - size_t pos = 0 ; + size_t pos = 0, fakepos = 0 ; uint8_t found = 0 ; stralloc sakey = STRALLOC_ZERO ; stralloc_ref psasection ; key_all_t const *list = total_list ; - parse_mill_t key = { .open = '@', .close = '=', \ - .skip = " \n\t\r", .skiplen = 4, \ - .end = 0, .endlen = 0, \ - .jump = "#", .jumplen = 1,\ - .check = 0, .flush = 1, \ - .forceskip = 1, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; for (int i = 0 ; i < key_enum_section_el ; i++) { @@ -353,8 +225,13 @@ int get_key_range(genalloc *ga, section_t *sasection,char const *file,int *svtyp nocheck.expected = KEYVAL ; nocheck.mandatory = OPTS ; section_setsa(i,&psasection,sasection) ; - if (!stralloc_cats(&nocheck.val,psasection->s+1)) goto err ; - if (!parse_env(&nocheck.val,&pos)) { strerr_warnwu2x("parse section: ",get_keybyid(i)) ; goto err ; } + if (!stralloc_cats(&nocheck.val,psasection->s+1)) goto err ;//+1 remove the first '\n' + if (!environ_get_clean_env(&nocheck.val)) { VERBO3 strerr_warnwu2x("parse section: ",get_keybyid(i)) ; goto err ; } + if (!stralloc_cats(&nocheck.val,"\n") || + !stralloc_0(&nocheck.val)) goto err ; + nocheck.val.len-- ; + + if (!genalloc_append(keynocheck,ga,&nocheck)) goto err ; } else @@ -365,14 +242,16 @@ int get_key_range(genalloc *ga, section_t *sasection,char const *file,int *svtyp while (pos < blen) { keynocheck nocheck = KEYNOCHECK_ZERO ; - key.inner.nopen = key.inner.nclose = sakey.len = 0 ; - r = parse_config(&key,file,psasection,&sakey,&pos) ; - if (!r) goto err ; + sakey.len = 0 ; + r = mill_element(&sakey,psasection->s,&MILL_GET_AROBASE_KEY,&pos) ; + if (r == -1) goto err ; + if (!r) break ; //end of string + fakepos = get_rlen_until(psasection->s,'\n',pos) ; + r = mill_element(&sakey,psasection->s,&MILL_GET_COMMENTED_KEY,&fakepos) ; + if (r == -1) goto err ; + if (r) continue ; if (!stralloc_cats(&nocheck.val,psasection->s+pos)) goto err ; if (!stralloc_0(&nocheck.val)) goto err ; - if (!sakey.len) break ;// end of string - stralloc_inserts(&sakey,0,"@") ; - stralloc_0(&sakey) ; for (int j = 0 ; j < total_list_el[i]; j++) { found = 0 ; @@ -386,27 +265,38 @@ int get_key_range(genalloc *ga, section_t *sasection,char const *file,int *svtyp switch(list[i].list[j].expected) { case QUOTE: - r = parse_quote(&nocheck.val,&pos) ; - if (r < 0) + if (!sastr_get_double_quote(&nocheck.val)) { - VERBO3 parse_err(6,nocheck.idsec,nocheck.idkey) ; + VERBO3 parse_err(6,&nocheck) ; goto err ; } - else if (!r) goto err ; + if (!stralloc_0(&nocheck.val)) goto err ; break ; case BRACKET: - r = parse_bracket(&nocheck.val,&pos) ; - if (r < 0) + if (!parse_bracket(&nocheck.val,&pos)) + { + VERBO3 parse_err(6,&nocheck) ; + goto err ; + } + if (nocheck.val.len == 1) { - VERBO3 parse_err(6,nocheck.idsec,nocheck.idkey) ; + VERBO3 parse_err(9,&nocheck) ; goto err ; } - else if (!r) goto err ; break ; case LINE: case UINT: case SLASH: - if (!parse_line(&nocheck.val,&pos)) goto err ; + if (!parse_line(&nocheck.val,&pos)) + { + VERBO3 parse_err(7,&nocheck) ; + goto err ; + } + if (nocheck.val.len == 1) + { + VERBO3 parse_err(9,&nocheck) ; + goto err ; + } if (!i && !j) (*svtype) = get_enumbyid(nocheck.val.s,key_enum_el) ; break ; default: @@ -440,8 +330,9 @@ int get_mandatory(genalloc *nocheck,int idsec,int idkey) key_all_t const *list = total_list ; - genalloc gatmp = GENALLOC_ZERO ; - r = 0 ; + stralloc sa = STRALLOC_ZERO ; + + r = -1 ; count = 0 ; bkey = -1 ; countidsec = 0 ; @@ -541,9 +432,13 @@ int get_mandatory(genalloc *nocheck,int idsec,int idkey) } if (bkey >= 0) { - if (!clean_val(&gatmp,genalloc_s(keynocheck,nocheck)[bkey].val.s)) strerr_diefu2x(111,"parse file ",genalloc_s(keynocheck,nocheck)[bkey].val.s) ; - r = stra_cmp(&gatmp,get_keybyid(ENVIR)) ; - if ((r) && (!count)) + if (!sastr_clean_string(&sa,genalloc_s(keynocheck,nocheck)[bkey].val.s)) + { + VERBO3 strerr_warnwu2x("clean value of: ",sa.s) ; + return 0 ; + } + r = sastr_cmp(&sa,get_keybyid(ENVIR)) ; + if ((r >= 0) && (!count)) { VERBO3 strerr_warnw1x("options env was asked -- section environment must be set") ; return 0 ; @@ -553,9 +448,7 @@ int get_mandatory(genalloc *nocheck,int idsec,int idkey) default: break ; } - - genalloc_deepfree(stralist,&gatmp,stra_free) ; - + stralloc_free(&sa) ; return 1 ; } @@ -645,47 +538,32 @@ int nocheck_toservice(keynocheck *nocheck,int svtype, sv_alltype *service) /********************************** * store * *******************************/ - int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) { - int r, nbline ; - unsigned int i ; - genalloc gatmp = GENALLOC_ZERO ; - stralloc satmp = STRALLOC_ZERO ; - r = i = 0 ; - + int r = 0 ; + size_t pos = 0, *chlen = &nocheck->val.len ; + char *chval = nocheck->val.s ; + switch(nocheck->idkey){ case TYPE: - r = get_enumbyid(nocheck->val.s,key_enum_el) ; - if (r < 0) - { - VERBO3 parse_err(0,nocheck->idsec,TYPE) ; - return 0 ; - } + r = get_enum(chval,nocheck) ; + if (!r) return 0 ; service->cname.itype = r ; break ; case NAME: service->cname.name = keep.len ; - if (!stralloc_catb(&keep,nocheck->val.s,nocheck->val.len + 1)) retstralloc(0,"parse_common") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_common:NAME") ; break ; case DESCRIPTION: service->cname.description = keep.len ; - if (!stralloc_catb(&keep,nocheck->val.s,nocheck->val.len + 1)) retstralloc(0,"parse_common") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_common:DESCRIPTION") ; break ; case OPTIONS: - if (!clean_val(&gatmp,nocheck->val.s)) + if (!get_clean_val(nocheck)) return 0 ; + for (;pos < *chlen; pos += strlen(chval + pos)+1) { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - for (i = 0;i<genalloc_len(stralist,&gatmp);i++) - { - r = get_enumbyid(gaistr(&gatmp,i),key_enum_el) ; - if (r < 0) - { - VERBO3 parse_err(0,nocheck->idsec,OPTIONS) ; - return 0 ; - } + r = get_enum(chval + pos,nocheck) ; + if (!r) return 0 ; if (svtype == CLASSIC || svtype == LONGRUN) { if (r == LOGGER) @@ -696,22 +574,13 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) if (r == ENVIR) service->opts[2] = 1 ; } - break ; case FLAGS: - if (!clean_val(&gatmp,nocheck->val.s)) + if (!get_clean_val(nocheck)) return 0 ; + for (;pos < *chlen; pos += strlen(chval + pos)+1) { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - for (unsigned int i = 0;i<genalloc_len(stralist,&gatmp);i++) - { - r = get_enumbyid(gaistr(&gatmp,i),key_enum_el) ; - if (r < 0) - { - VERBO3 parse_err(0,nocheck->idsec,FLAGS) ; - return 0 ; - } + r = get_enum(chval + pos,nocheck) ; + if (!r) return 0 ; if (r == DOWN) service->flags[0] = 1 ;/**0 means not enabled*/ if (r == NOSETSID) @@ -719,230 +588,116 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) } break ; case USER: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - /** special case, we don't know which user want to use - * the service, we need a general name to allow all user - * the term "user" is took here to allow the current user*/ - if (stra_cmp(&gatmp,"user")) + if (!get_clean_val(nocheck)) return 0 ; { - stra_remove(&gatmp,"user") ; - for (i=0;i<genalloc_len(stralist,&gatmp);i++) + uid_t owner = MYUID ; + if (!owner) { - r = scan_uidlist(gaistr(&gatmp,i),(uid_t *)service->user) ; - if (!r) + if (sastr_find(&nocheck->val,"root") == -1) { - VERBO3 parse_err(0,nocheck->idsec,USER) ; + VERBO3 strerr_warnwu3x("use service: ",keep.s+service->cname.name," -- permission denied") ; return 0 ; } } - uid_t nb = service->user[0] ; - nb++ ; - service->user[0] = nb ; - service->user[nb] = MYUID ; - //search for root permissions - int e = 1 ; - for (int i =1; i < nb; i++) - if (!service->user[i]) e = 0 ; - if ((!MYUID) && (e)) + /** special case, we don't know which user want to use + * the service, we need a general name to allow all user + * the term "user" is took here to allow the current user*/ + ssize_t p = sastr_cmp(&nocheck->val,"user") ; + for (;pos < *chlen; pos += strlen(chval + pos)+1) { - VERBO3 strerr_warnwu3x("use ",keep.s+service->cname.name," service: permission denied") ; - return 0 ; + if (pos == (size_t)p) continue ; + if (!scan_uidlist(chval + pos,(uid_t *)service->user)) + { + VERBO3 parse_err(0,nocheck) ; + return 0 ; + } } - break ; - } - else - if (MYUID > 0) - { - VERBO3 strerr_warnwu3x("use ",keep.s+service->cname.name," service: permission denied") ; - return 0 ; - } - else if (genalloc_len(stralist,&gatmp) > 1) - { - r = scan_uidlist(nocheck->val.s,(uid_t *)service->user) ; - if (!r) + uid_t nb = service->user[0] ; + if (p == -1 && owner) { - VERBO3 parse_err(0,nocheck->idsec,USER) ; - return 0 ; + int e = 0 ; + for (int i = 1; i < nb+1; i++) + if (service->user[i] == owner) e = 1 ; + + if (!e) + { + VERBO3 strerr_warnwu3x("use service: ",keep.s+service->cname.name," -- permission denied") ; + return 0 ; + } } - break ; - } - else - r = scan_uidlist("root",(uid_t *)service->user) ; - if (!r) - { - VERBO3 parse_err(0,nocheck->idsec,USER) ; - return 0 ; } break ; case HIERCOPY: - if (!clean_val(&gatmp,nocheck->val.s)) + if (!get_clean_val(nocheck)) return 0 ; { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - for (i = 0 ; i < genalloc_len(stralist,&gatmp) ; i++) - { - char *name = gaistr(&gatmp,i) ; - size_t namelen = gaistrlen(&gatmp,i) ; - service->hiercopy[i+1] = keep.len ; - if (!stralloc_catb(&keep,name,namelen + 1)) retstralloc(0,"parse_common:hiercopy") ; - service->hiercopy[0] = i+1 ; + unsigned int idx = 0 ; + for (;pos < *chlen; pos += strlen(chval + pos)+1) + { + char *name = chval + pos ; + size_t namelen = strlen(chval + pos) ; + service->hiercopy[idx+1] = keep.len ; + if (!stralloc_catb(&keep,name,namelen + 1)) retstralloc(0,"parse_common:HIERCOPY") ; + service->hiercopy[0] = ++idx ; + } } break ; case DEPENDS: - if (service->cname.itype == CLASSIC) + if ((service->cname.itype == CLASSIC) || (service->cname.itype == BUNDLE)) { - VERBO3 strerr_warnw3x("key : ",get_keybyid(nocheck->idkey)," : is not valid for type classic") ; + VERBO3 strerr_warnw4x("key: ",get_keybyid(nocheck->idkey),": is not valid for type ",get_keybyid(service->cname.itype)) ; return 0 ; } - else - if (service->cname.itype == BUNDLE) - { - VERBO3 strerr_warnw3x("key : ",get_keybyid(nocheck->idkey)," : is not valid for type bundle") ; - return 0 ; - } - if (!clean_val(&gatmp,nocheck->val.s)) + if (!get_clean_val(nocheck)) return 0 ; + service->cname.idga = deps.len ; + for (;pos < *chlen; pos += strlen(chval + pos)+1) { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - service->cname.idga = genalloc_len(unsigned int,&gadeps) ; - for (i = 0;i<genalloc_len(stralist,&gatmp);i++) - { - if (!genalloc_append(unsigned int,&gadeps,&deps.len)) retstralloc(0,"parse_common") ; - if (!stralloc_catb(&deps,gaistr(&gatmp,i),gaistrlen(&gatmp,i) + 1)) retstralloc(0,"parse_common") ; + if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) retstralloc(0,"parse_common:DEPENDS") ; service->cname.nga++ ; } break ; case CONTENTS: if (service->cname.itype != BUNDLE) { - VERBO3 strerr_warnw4x("key : ",get_keybyid(nocheck->idkey)," : is not valid for type ",get_keybyid(service->cname.itype)) ; + VERBO3 strerr_warnw4x("key: ",get_keybyid(nocheck->idkey),": is not valid for type ",get_keybyid(service->cname.itype)) ; return 0 ; } - if (!clean_val(&gatmp,nocheck->val.s)) + if (!get_clean_val(nocheck)) return 0 ; + service->cname.idga = deps.len ; + for (;pos < *chlen; pos += strlen(chval + pos) + 1) { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - service->cname.idga = genalloc_len(unsigned int,&gadeps) ; - for (i = 0;i<genalloc_len(stralist,&gatmp);i++) - { - if (!genalloc_append(unsigned int,&gadeps,&deps.len)) retstralloc(0,"parse_common") ; - if (!stralloc_catb(&deps,gaistr(&gatmp,i),gaistrlen(&gatmp,i) + 1)) retstralloc(0,"parse_common") ; + if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) retstralloc(0,"parse_common:CONTENTS") ; service->cname.nga++ ; } break ; - case NOTIFY: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - if (!scan_uint32(gastr(&gatmp))) - { - VERBO3 parse_err(3,nocheck->idsec,NOTIFY) ; - return 0 ; - } - if (!uint32_scan(gastr(&gatmp),&service->notification)) - { - VERBO3 parse_err(3,nocheck->idsec,NOTIFY) ; - return 0 ; - } - break ; case T_KILL: - r = scan_timeout(nocheck->val.s,(uint32_t *)service->timeout,0) ; - if (r < 0) - { - VERBO3 parse_err(3,nocheck->idsec,T_KILL) ; - return 0 ; - } - break ; case T_FINISH: - r = scan_timeout(nocheck->val.s,(uint32_t *)service->timeout,1) ; - if (r < 0) - { - VERBO3 parse_err(3,nocheck->idsec,T_FINISH) ; - return 0 ; - } - break ; case T_UP: - r = scan_timeout(nocheck->val.s,(uint32_t *)service->timeout,2) ; - if (r < 0) - { - VERBO3 parse_err(3,nocheck->idsec,T_UP) ; - return 0 ; - } - break ; case T_DOWN: - r = scan_timeout(nocheck->val.s,(uint32_t *)service->timeout,3) ; - if (r < 0) - { - VERBO3 parse_err(3,nocheck->idsec,T_DOWN) ; - return 0 ; - } + if (!get_timeout(nocheck,(uint32_t *)service->timeout)) return 0 ; break ; case DEATH: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - if (!scan_uint32(gastr(&gatmp))) + if (!get_uint(nocheck,&service->death)) return 0 ; + break ; + case NOTIFY: + if (!get_uint(nocheck,&service->notification)) return 0 ; + break ; + case ENVAL: + if (!environ_clean_nline(&nocheck->val)) { - VERBO3 parse_err(3,nocheck->idsec,DEATH) ; + VERBO3 strerr_warnwu2x("clean environment value: ",chval) ; return 0 ; } - if (!uint32_scan(gastr(&gatmp),&service->death)) + if (!stralloc_cats(&nocheck->val,"\n")) return 0 ; + if (!stralloc_copy(&service->saenv,&nocheck->val)) { - VERBO3 parse_err(3,nocheck->idsec,DEATH) ; + VERBO3 strerr_warnwu2x("store environment value: ",chval) ; return 0 ; } break ; - case ENVAL: - nbline = get_nbline_ga(nocheck->val.s,nocheck->val.len,&gatmp) ; - for (i = 0;i < nbline;i++) - { - satmp.len = 0 ; - if (!stralloc_cats(&satmp,gaistr(&gatmp,i)) || - !stralloc_0(&satmp)) - { - VERBO3 strerr_warnwu2x("append environment value: ",gaistr(&gatmp,i)) ; - stralloc_free(&satmp) ; - return 0 ; - } - r = env_clean(&satmp) ; - if (r > 0) - { - if (!stralloc_cats(&service->saenv,satmp.s) || - !stralloc_cats(&service->saenv,"\n")) - { - VERBO3 strerr_warnwu2x("store environment value: ",gaistr(&gatmp,i)) ; - stralloc_free(&satmp) ; - return 0 ; - } - } - else if (!r) - { - VERBO3 strerr_warnwu2x("clean environment value: ",gaistr(&gatmp,i)) ; - stralloc_free(&satmp) ; - return 0 ; - } - } - break ; case SIGNAL: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - if (!sig0_scan(gastr(&gatmp), &service->signal)) + if (!sig0_scan(chval,&service->signal)) { - VERBO3 parse_err(3,nocheck->idsec,SIGNAL) ; + VERBO3 parse_err(3,nocheck) ; return 0 ; } break ; @@ -951,65 +706,52 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) return 0 ; } - genalloc_deepfree(stralist,&gatmp,stra_free) ; - stralloc_free(&satmp) ; return 1 ; } int keep_runfinish(sv_exec *exec,keynocheck *nocheck) { - int r ; - - genalloc gatmp = GENALLOC_ZERO ; - - switch(nocheck->idkey){ + int r = 0 ; + size_t *chlen = &nocheck->val.len ; + char *chval = nocheck->val.s ; + + switch(nocheck->idkey) + { case BUILD: - r = get_enumbyid(nocheck->val.s,key_enum_el) ; - if (r < 0) - { - VERBO3 parse_err(0,nocheck->idsec,BUILD) ; - return 0 ; - } + r = get_enum(chval,nocheck) ; + if (!r) return 0 ; exec->build = r ; break ; case RUNAS: - r = scan_uid(nocheck->val.s,&exec->runas) ; - if (!r) - { - VERBO3 parse_err(0,nocheck->idsec,RUNAS) ; - return 0 ; - } + if (!check_valid_runas(nocheck)) return 0 ; + exec->runas = keep.len ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_runfinish:RUNAS") ; break ; case SHEBANG: - r = dir_scan_absopath(nocheck->val.s) ; - if (r < 0) + if (chval[0] != '/') { - VERBO3 parse_err(4,nocheck->idsec,SHEBANG) ; + VERBO3 parse_err(4,nocheck) ; return 0 ; } exec->shebang = keep.len ; - if (!stralloc_catb(&keep,nocheck->val.s,nocheck->val.len + 1)) exitstralloc("parse_runfinish:stralloc:SHEBANG") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_runfinish:SHEBANG") ; break ; case EXEC: exec->exec = keep.len ; - if (!stralloc_catb(&keep,nocheck->val.s,nocheck->val.len + 1)) exitstralloc("parse_runfinish:stralloc:EXEC") ; - + if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_runfinish:EXEC") ; break ; default: VERBO3 strerr_warnw2x("unknown key: ",get_keybyid(nocheck->idkey)) ; return 0 ; - } - - genalloc_deepfree(stralist,&gatmp,stra_free) ; - + } return 1 ; } int keep_logger(sv_execlog *log,keynocheck *nocheck) { - int r, i ; - - genalloc gatmp = GENALLOC_ZERO ; + int r ; + size_t pos = 0, *chlen = &nocheck->val.len ; + char *chval = nocheck->val.s ; switch(nocheck->idkey){ case BUILD: @@ -1019,16 +761,11 @@ int keep_logger(sv_execlog *log,keynocheck *nocheck) if (!keep_runfinish(&log->run,nocheck)) return 0 ; break ; case DEPENDS: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - log->idga = genalloc_len(unsigned int,&gadeps) ; - for (i = 0;i<genalloc_len(stralist,&gatmp);i++) + if (!get_clean_val(nocheck)) return 0 ; + log->idga = deps.len ; + for (;pos < *chlen; pos += strlen(chval + pos) + 1) { - if (!genalloc_append(unsigned int,&gadeps,&deps.len)) retstralloc(0,"parse_logger") ; - if (!stralloc_catb(&deps,gaistr(&gatmp,i),gaistrlen(&gatmp,i) + 1)) retstralloc(0,"parse_logger") ; + if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) retstralloc(0,"parse_logger:DEPENDS") ; log->nga++ ; } break ; @@ -1039,64 +776,33 @@ int keep_logger(sv_execlog *log,keynocheck *nocheck) if (!keep_runfinish(&log->run,nocheck)) return 0 ; break ; case T_KILL: - r = scan_timeout(nocheck->val.s,(uint32_t *)log->timeout,0) ; - if (r < 0) parse_err(3,nocheck->idsec,T_KILL) ; - break ; case T_FINISH: - r = scan_timeout(nocheck->val.s,(uint32_t *)log->timeout,1) ; - if (r < 0) - { - VERBO3 parse_err(3,nocheck->idsec,T_FINISH) ; - return 0 ; - } + if (!get_timeout(nocheck,(uint32_t *)log->timeout)) return 0 ; break ; case DESTINATION: - r = dir_scan_absopath(nocheck->val.s) ; - if (r < 0) + if (chval[0] != '/') { - VERBO3 parse_err(4,nocheck->idsec,DESTINATION) ; + VERBO3 parse_err(4,nocheck) ; return 0 ; } log->destination = keep.len ; - if (!stralloc_catb(&keep,nocheck->val.s,nocheck->val.len + 1)) retstralloc(0,"parse_logger") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_logger:DESTINATION") ; break ; case BACKUP: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - if (!scan_uint32(gastr(&gatmp))) - { - VERBO3 parse_err(3,nocheck->idsec,BACKUP) ; - return 0 ; - } - uint_scan(gastr(&gatmp),&log->backup) ; + if (!get_uint(nocheck,&log->backup)) return 0 ; break ; case MAXSIZE: - if (!scan_uint32(nocheck->val.s)) - { - VERBO3 parse_err(3,nocheck->idsec,MAXSIZE) ; - return 0 ; - } - uint_scan(nocheck->val.s,&log->maxsize) ; + if (!get_uint(nocheck,&log->maxsize)) return 0 ; break ; case TIMESTP: - r = get_enumbyid (nocheck->val.s,key_enum_el) ; - if (r < 0) - { - VERBO3 parse_err(0,nocheck->idsec,TIMESTP) ; - return 0 ; - } + r = get_enum(chval,nocheck) ; + if (!r) return 0 ; log->timestamp = r ; break ; default: VERBO3 strerr_warnw2x("unknown key: ",get_keybyid(nocheck->idkey)) ; return 0 ; } - - genalloc_deepfree (stralist,&gatmp,stra_free) ; - return 1 ; } @@ -1132,20 +838,63 @@ int read_svfile(stralloc *sasv,char const *name,char const *src) return 0 ; } /** ensure that we have an empty line at the end of the string*/ - if (!stralloc_cats(sasv,"\n")) retstralloc(0,"parse_service_before") ; - if (!stralloc_0(sasv)) retstralloc(0,"parse_service_before") ; + if (!stralloc_cats(sasv,"\n")) retstralloc(0,"read_svfile") ; + if (!stralloc_0(sasv)) retstralloc(0,"read_svfile") ; + + return 1 ; +} + +int add_pipe(sv_alltype *sv, stralloc *sa) +{ + char *prodname = keep.s+sv->cname.name ; + + stralloc tmp = STRALLOC_ZERO ; + + sv->pipeline = sa->len ; + if (!stralloc_cats(&tmp,SS_PIPE_NAME)) retstralloc(0,"add_pipe") ; + if (!stralloc_cats(&tmp,prodname)) retstralloc(0,"add_pipe") ; + if (!stralloc_0(&tmp)) retstralloc(0,"add_pipe") ; + + if (!stralloc_catb(sa,tmp.s,tmp.len+1)) retstralloc(0,"add_pipe") ; + stralloc_free(&tmp) ; + + return 1 ; +} + +int parse_line(stralloc *sa, size_t *pos) +{ + if (!sa->len) return 0 ; + int r = 0 ; + size_t newpos = 0 ; + stralloc kp = STRALLOC_ZERO ; + wild_zero_all(&MILL_CLEAN_LINE) ; + r = mill_element(&kp,sa->s,&MILL_CLEAN_LINE,&newpos) ; + if (r == -1 || !r) goto err ; + if (!stralloc_0(&kp)) goto err ; + if (!stralloc_copy(sa,&kp)) goto err ; + *pos += newpos - 1 ; + stralloc_free(&kp) ; return 1 ; + err: + stralloc_free(&kp) ; + return 0 ; } -ssize_t get_sep_before (char const *line, char const sepstart, char const sepend) +int parse_bracket(stralloc *sa,size_t *pos) { - size_t linend, linesep ; - linesep=get_len_until(line,sepstart) ; - linend=get_len_until(line,sepend) ; - if (linesep > linend) return -1 ; - if (!linend) return 0 ; - return linesep ; + if (!sa->len) return 0 ; + size_t newpos = 0 ; + stralloc kp = STRALLOC_ZERO ; + if (!key_get_next_id(&kp,sa->s,&newpos)) goto err ; + if (!stralloc_0(&kp)) goto err ; + if (!stralloc_copy(sa,&kp)) goto err ; + *pos += newpos ; + stralloc_free(&kp) ; + return 1 ; + err: + stralloc_free(&kp) ; + return 0 ; } void section_setsa(int id, stralloc_ref *p,section_t *sa) @@ -1161,147 +910,171 @@ void section_setsa(int id, stralloc_ref *p,section_t *sa) } } -int section_skip(char const *s,size_t pos,int nline) +int section_get_skip(char const *s,size_t pos,int nline) { ssize_t r = -1 ; if (nline == 1) { - r = get_sep_before(s,'#','\n') ; + r = get_sep_before(s,'#','[') ; if (r >= 0) return 0 ; } r = get_rlen_until(s,'\n',pos) ; if (r >= 0) { - r = get_sep_before(s+r+1,'#','\n') ; + r = get_sep_before(s+r+1,'#','[') ; if (r >= 0) return 0 ; } return 1 ; } -/*@Return 1 on success - * @Return 0 on fail - * @Return -1 on invalid section */ -int section_valid(int id, uint32_t nline, size_t pos,stralloc *src, char const *file) +int section_get_id(stralloc *secname, char const *string,size_t *pos,int *id) { - int r, rn, found = 0, err = 0 ; - size_t tpos = 0 ; - stralloc tmp = STRALLOC_ZERO ; - stralloc fake = STRALLOC_ZERO ; - key_all_t const *list = total_list ; - parse_mill_t key = { .open = '@', .close = '=', \ - .skip = " \n\t\r", .skiplen = 4, \ - .end = 0, .endlen = 0, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 0, \ - .forceskip = 1, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - - - /* keys like execute can contain '[]' regex character, - * check it and ignore the regex if it's the case*/ - r = get_rlen_until(src->s,'\n',pos) ; - /*we are on first line?*/ - if (r < 0 && nline > 1) goto err ; - else if (nline == 1) goto freed ; - r++; - rn = get_sep_before(src->s+r,'@','\n') ; - if (rn < 0) goto invalid ; - if (!stralloc_cats(&tmp,src->s+r)) goto err ; - if (!stralloc_0(&tmp)) goto err ; - if (!parse_config(&key,file,&tmp,&fake,&tpos)) goto err ; - if (!fake.len) goto err ; - stralloc_inserts(&fake,0,"@") ; - stralloc_0(&fake) ; - for (int i = 0 ; i < key_enum_section_el; i++) + size_t len = strlen(string) ; + size_t newpos = 0 ; + (*id) = -1 ; + + while ((*id) < 0 && (*pos) < len) { - for (int j = 0 ; j < total_list_el[i]; j++) + secname->len = 0 ; + newpos = 0 ; + if (mill_element(secname,string+(*pos),&MILL_GET_SECTION_NAME,&newpos) == -1) return 0 ; + if (secname->len) { - if (list[i].list[j].name && obstr_equal(fake.s,list[i].list[j].name)) - { found = 1 ; break ; } + if (!stralloc_0(secname)) return 0 ; + (*id) = get_enumbyid(secname->s,key_enum_section_el) ; } + (*pos) += newpos ; } - if (!found) goto invalid ; - freed: - stralloc_free(&tmp) ; - stralloc_free(&fake) ; - return 1 ; - invalid: - err = -1 ; - err: - stralloc_free(&tmp) ; - stralloc_free(&fake) ; - return err ; + return 1 ; } -int clean_value(stralloc *sa) +int key_get_next_id(stralloc *sa, char const *string,size_t *pos) { - size_t pos = 0 ; - char const *file = "clean_value" ; - stralloc tmp = STRALLOC_ZERO ; - parse_mill_t empty = { .open = '@', .close = ' ', \ - .skip = " \n\t\r", .skiplen = 4, \ - .end = 0, .endlen = 0, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 0, \ - .forceskip = 1, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - if (!stralloc_inserts(sa,0,"@")) goto err ; - if (!stralloc_cats(sa," ")) goto err ; - if (!parse_config(&empty,file,sa,&tmp,&pos)) goto err ; - if (!stralloc_0(&tmp)) goto err ; - if (!stralloc_copy(sa,&tmp)) goto err ; - stralloc_free(&tmp) ; + if (!string) return 0 ; + int r = 0 ; + size_t newpos = 0, len = strlen(string) ; + stralloc kp = STRALLOC_ZERO ; + wild_zero_all(&MILL_GET_AROBASE_KEY) ; + wild_zero_all(&MILL_FIRST_BRACKET) ; + int id = -1 ; + r = mill_element(&kp,string,&MILL_FIRST_BRACKET,&newpos) ; + if (r == -1 || !r) goto err ; + *pos = newpos ; + while (id == -1 && newpos < len) + { + kp.len = 0 ; + r = mill_element(&kp,string,&MILL_GET_AROBASE_KEY,&newpos) ; + if (r == -1) goto err ; + if (!stralloc_0(&kp)) goto err ; + id = get_enumbyid(kp.s,key_enum_el) ; + } + newpos = get_rlen_until(string,')',newpos) ; + if (newpos == -1) goto err ; + if (!stralloc_catb(sa,string+*pos,newpos - *pos)) goto err ; + *pos = newpos + 1 ; //+1 remove the last ')' + stralloc_free(&kp) ; return 1 ; err: - stralloc_free(&tmp) ; + stralloc_free(&kp) ; return 0 ; } -void parse_err(int ierr,int idsec,int idkey) +int get_clean_val(keynocheck *ch) { + if (!sastr_clean_element(&ch->val)) + { + VERBO3 parse_err(8,ch) ; + return 0 ; + } + return 1 ; +} + +int get_enum(char const *string, keynocheck *ch) +{ + int r = get_enumbyid(string,key_enum_el) ; + if (r == -1) + { + VERBO3 parse_err(0,ch) ; + return 0 ; + } + return r ; +} + +int get_timeout(keynocheck *ch,uint32_t *ui) +{ + int time = 0 ; + if (ch->idkey == T_KILL) time = 0 ; + else if (ch->idkey == T_FINISH) time = 1 ; + else if (ch->idkey == T_UP) time = 2 ; + else if (ch->idkey == T_DOWN) time = 3 ; + if (scan_timeout(ch->val.s,ui,time) == -1) + { + VERBO3 parse_err(3,ch) ; + return 0 ; + } + return 1 ; +} + +int get_uint(keynocheck *ch,uint32_t *ui) +{ + if (!uint32_scan(ch->val.s,ui)) + { + VERBO3 parse_err(3,ch) ; + return 0 ; + } + return 1 ; +} + +int check_valid_runas(keynocheck *ch) +{ + errno = 0 ; + struct passwd *pw = getpwnam(ch->val.s); + if (pw == NULL && errno) + { + VERBO3 parse_err(0,ch) ; + return 0 ; + } + return 1 ; +} + +void parse_err(int ierr,keynocheck *check) +{ + int idsec = check->idsec ; + int idkey = check->idkey ; switch(ierr) { case 0: - strerr_warnw4x("invalid value for key: ",get_keybyid(idkey)," in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("invalid value for key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 1: - strerr_warnw4x("multiple definition of key: ",get_keybyid(idkey)," in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("multiple definition of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 2: - strerr_warnw4x("same value for key: ",get_keybyid(idkey)," in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("same value for key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 3: - strerr_warnw4x("key: ",get_keybyid(idkey)," must be an integrer value in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("key: ",get_keybyid(idkey),": must be an integrer value in section: ",get_keybyid(idsec)) ; break ; case 4: - strerr_warnw4x("key: ",get_keybyid(idkey)," must be an absolute path in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("key: ",get_keybyid(idkey),": must be an absolute path in section: ",get_keybyid(idsec)) ; break ; case 5: - strerr_warnw4x("key: ",get_keybyid(idkey)," must be set in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("key: ",get_keybyid(idkey),": must be set in section: ",get_keybyid(idsec)) ; break ; case 6: - strerr_warnw4x("invalid format of key: ",get_keybyid(idkey)," in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("invalid format of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + break ; + case 7: + strerr_warnwu4x("parse key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + break ; + case 8: + strerr_warnwu4x("clean value of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + break ; + case 9: + strerr_warnw4x("empty value of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; default: strerr_warnw1x("unknown parse_err number") ; break ; } } - -int add_pipe(sv_alltype *sv, stralloc *sa) -{ - char *prodname = keep.s+sv->cname.name ; - - stralloc tmp = STRALLOC_ZERO ; - - sv->pipeline = sa->len ; - if (!stralloc_cats(&tmp,SS_PIPE_NAME)) retstralloc(0,"add_pipe") ; - if (!stralloc_cats(&tmp,prodname)) retstralloc(0,"add_pipe") ; - if (!stralloc_0(&tmp)) retstralloc(0,"add_pipe") ; - - if (!stralloc_catb(sa,tmp.s,tmp.len+1)) retstralloc(0,"add_pipe") ; - - stralloc_free(&tmp) ; - - return 1 ; -} diff --git a/src/lib66/parser_write.c b/src/lib66/parser_write.c index 25f1f033af8cdc2afcd34e9cd35cf9d6c6475aa5..5a4227bc52a36dd656f21b304fdf057476126614 100644 --- a/src/lib66/parser_write.c +++ b/src/lib66/parser_write.c @@ -17,6 +17,7 @@ #include <string.h> #include <errno.h> #include <sys/stat.h> +#include <stdint.h> //#include <stdio.h> #include <oblibs/string.h> @@ -46,7 +47,7 @@ /** @Return 0 on fail * @Return 1 on success * @Return 2 if the service is ignored */ -int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned int force, unsigned int conf) +int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, uint8_t force, uint8_t conf) { int r ; @@ -158,7 +159,7 @@ int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned return 1 ; } -int write_classic(sv_alltype *sv, char const *dst, unsigned int force,unsigned int conf) +int write_classic(sv_alltype *sv, char const *dst, uint8_t force,uint8_t conf) { /**notification,timeout, ...*/ if (!write_common(sv, dst, conf)) @@ -195,7 +196,7 @@ int write_classic(sv_alltype *sv, char const *dst, unsigned int force,unsigned i return 1 ; } -int write_longrun(sv_alltype *sv,char const *dst, unsigned int force, unsigned int conf) +int write_longrun(sv_alltype *sv,char const *dst, uint8_t force, uint8_t conf) { size_t r ; char *name = keep.s+sv->cname.name ; @@ -252,7 +253,7 @@ int write_longrun(sv_alltype *sv,char const *dst, unsigned int force, unsigned i } /** dependencies */ - if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "dependencies", &gadeps)) + if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "dependencies")) { VERBO3 strerr_warnwu3x("write: ",dst,"/dependencies") ; return 0 ; @@ -262,7 +263,7 @@ int write_longrun(sv_alltype *sv,char const *dst, unsigned int force, unsigned i return 1 ; } -int write_oneshot(sv_alltype *sv,char const *dst,unsigned int conf) +int write_oneshot(sv_alltype *sv,char const *dst,uint8_t conf) { if (!write_common(sv, dst,conf)) @@ -286,7 +287,7 @@ int write_oneshot(sv_alltype *sv,char const *dst,unsigned int conf) } } - if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "dependencies", &gadeps)) + if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "dependencies")) { VERBO3 strerr_warnwu3x("write: ",dst,"/dependencies") ; return 0 ; @@ -304,7 +305,7 @@ int write_bundle(sv_alltype *sv, char const *dst) return 0 ; } /** contents file*/ - if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "contents", &gadeps)) + if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "contents")) { VERBO3 strerr_warnwu3x("write: ",dst,"/contents") ; return 0 ; @@ -313,15 +314,18 @@ int write_bundle(sv_alltype *sv, char const *dst) return 1 ; } -int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *dst, int mode, unsigned int force) +int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *dst, mode_t mode, uint8_t force) { int r ; int logbuild = log->run.build ; - char *time = NULL ; - char *pmax = NULL ; - char *pback = NULL ; + uid_t log_uid ; + gid_t log_gid ; + char *time = 0 ; + char *pmax = 0 ; + char *pback = 0 ; char *timestamp = "t" ; + char *logrunner = log->run.runas ? keep.s + log->run.runas : SS_LOGGER_RUNNER ; char max[UINT32_FMT] ; char back[UINT32_FMT] ; char const *userhome ; @@ -388,7 +392,7 @@ int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *d /** dependencies*/ if (log->nga) { - if (!write_dependencies(log->nga,log->idga,ddst.s,"dependencies",&gadeps)) + if (!write_dependencies(log->nga,log->idga,ddst.s,"dependencies")) { VERBO3 strerr_warnwu3x("write: ",ddst.s,"/dependencies") ; return 0 ; @@ -415,14 +419,10 @@ int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *d /** uid */ if (!stralloc_cats(&shebang, "#!" EXECLINE_SHEBANGPREFIX "execlineb -P\n")) retstralloc(0,"write_logger") ; if (!stralloc_0(&shebang)) retstralloc(0,"write_logger") ; - if ((!MYUID && log->run.runas)) + if ((!MYUID)) { if (!stralloc_cats(&ui,S6_BINPREFIX "s6-setuidgid ")) retstralloc(0,"write_logger") ; - if (!get_namebyuid(log->run.runas,&ui)) - { - VERBO3 strerr_warnwu1sys("set owner for the logger") ; - return 0 ; - } + if (!stralloc_cats(&ui,logrunner)) retstralloc(0,"write_logger") ; } if (!stralloc_cats(&ui,"\n")) retstralloc(0,"write_logger") ; if (!stralloc_0(&ui)) retstralloc(0,"write_logger") ; @@ -522,26 +522,35 @@ int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *d return 0 ; } - size_t destlen = get_rlen_until(destlog.s,'/',destlog.len) ; - destlog.len = destlen ; - if (!stralloc_0(&destlog)) retstralloc(0,"write_logger") ; - - r = dir_search(destlog.s,svname,S_IFDIR) ; - if (r < 0) + + r = scan_mode(destlog.s,S_IFDIR) ; + if (r == -1) { - VERBO3 strerr_warnw4x(destlog.s,"/",svname," already exist with different mode") ; + VERBO3 strerr_warnw3x("log directory: ", destlog.s,": already exist with a different mode") ; return 0 ; } - if (!r) { - r = dir_create_under(destlog.s,svname,0755) ; - if (r < 0) + if (!dir_create_parent(destlog.s,0755)) { - VERBO3 strerr_warnwu5sys("create ",destlog.s,"/",svname," directory") ; + VERBO3 strerr_warnwu2sys("create log directory: ",destlog.s) ; return 0 ; } } - + if ((!MYUID)) + { + if (!youruid(&log_uid,logrunner) || + !yourgid(&log_gid,log_uid)) + { + VERBO3 strerr_warnwu2sys("get uid and gid of: ",logrunner) ; + return 0 ; + } + if (chown(destlog.s,log_uid,log_gid) == -1) + { + VERBO3 strerr_warnwu2sys("chown: ",destlog.s) ; + return 0 ; + } + } + stralloc_free(&shebang) ; stralloc_free(&ui) ; stralloc_free(&exec) ; @@ -567,7 +576,7 @@ int write_consprod(sv_alltype *sv,char const *prodname,char const *consname,char memcpy(prodfile,proddst,proddstlen) ; prodfile[proddstlen] = 0 ; - char pipefile[consdstlen + consnamelen + 1 + 1] ; + char pipefile[consdstlen + 1 + consnamelen + 1 + 1] ; /**producer-for*/ if (!file_write_unsafe(consfile,get_keybyid(CONSUMER),prodname,strlen(prodname))) @@ -587,9 +596,11 @@ int write_consprod(sv_alltype *sv,char const *prodname,char const *consname,char size_t len = strlen(deps.s+sv->pipeline) ; char pipename[len + 1] ; memcpy(pipefile,consdst,consdstlen) ; - memcpy(pipefile + consdstlen, consname,consnamelen) ; - memcpy(pipefile + consdstlen + consnamelen, "/", 1) ; - pipefile[consdstlen + consnamelen + 1] = 0 ; + pipefile[consdstlen] = '/' ; + memcpy(pipefile + consdstlen + 1, consname,consnamelen) ; + pipefile[consdstlen + 1 + consnamelen] = '/' ; + pipefile[consdstlen + 1 + consnamelen + 1] = 0 ; + memcpy(pipename,deps.s+sv->pipeline,len) ; pipename[len] = 0 ; if (!file_write_unsafe(pipefile,PIPELINE_NAME,pipename,len)) @@ -602,7 +613,7 @@ int write_consprod(sv_alltype *sv,char const *prodname,char const *consname,char return 1 ; } -int write_common(sv_alltype *sv, char const *dst,unsigned int conf) +int write_common(sv_alltype *sv, char const *dst,uint8_t conf) { int r ; char *time = NULL ; @@ -758,8 +769,7 @@ int write_common(sv_alltype *sv, char const *dst,unsigned int conf) return 1 ; } - -int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,int mode) +int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,mode_t mode) { unsigned int type = sv->cname.itype ; @@ -783,11 +793,7 @@ int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,in if ((!owner && exec->runas)) { if (!stralloc_cats(&ui,S6_BINPREFIX "s6-setuidgid ")) retstralloc(0,"write_exec") ; - if (!get_namebyuid(exec->runas,&ui)) - { - VERBO3 strerr_warnwu1sys("set owner for the execute file") ; - return 0 ; - } + if (!stralloc_cats(&ui,keep.s + exec->runas)) retstralloc(0,"write_exec") ; if (!stralloc_cats(&ui,"\n")) retstralloc(0,"write_exec") ; } /** environment */ @@ -875,34 +881,16 @@ int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,in return 1 ; } -int write_dependencies(unsigned int nga,unsigned int idga,char const *dst,char const *filename, genalloc *ga) +int write_dependencies(unsigned int nga,unsigned int idga,char const *dst,char const *filename) { - int r ; - stralloc contents = STRALLOC_ZERO ; - stralloc namedeps = STRALLOC_ZERO ; - - for (unsigned int i = 0; i < nga; i++) + size_t id = idga, nid = nga ; + for (;nid; id += strlen(deps.s + id) + 1, nid--) { - if (!stralloc_obreplace(&namedeps,deps.s+genalloc_s(unsigned int,ga)[idga+i])) return 0 ; - r = insta_check(namedeps.s) ; - if (!r) - { - VERBO3 strerr_warnw2x(" invalid instance name: ",namedeps.s) ; - return 0 ; - } - if (r > 0) - { - if (!insta_splitname(&namedeps,namedeps.s,r,1)) - { - VERBO3 strerr_warnwu2x("split copy name of instance: ",namedeps.s) ; - return 0 ; - } - } - if (!stralloc_cats(&contents,namedeps.s)) retstralloc(0,"write_dependencies") ; - if (!stralloc_cats(&contents,"\n")) retstralloc(0,"write_dependencies") ; + if (!stralloc_cats(&contents,deps.s + id) || + !stralloc_cats(&contents,"\n")) retstralloc(0,"write_dependencies") ; } - + if (contents.len) { if (!file_write_unsafe(dst,filename,contents.s,contents.len)) @@ -913,11 +901,9 @@ int write_dependencies(unsigned int nga,unsigned int idga,char const *dst,char c } stralloc_free(&contents) ; - stralloc_free(&namedeps) ; return 1 ; err: stralloc_free(&contents) ; - stralloc_free(&namedeps) ; return 0 ; } diff --git a/src/lib66/rc_init.c b/src/lib66/rc_init.c index dca07901150b9d3f80ed27a87628d839743dd4da..6f6c3b2ebdb9007d133339eefa0baaaf6d50421d 100644 --- a/src/lib66/rc_init.c +++ b/src/lib66/rc_init.c @@ -16,14 +16,17 @@ #include <string.h> #include <stdlib.h> +#include <sys/types.h> #include <oblibs/error2.h> #include <oblibs/string.h> #include <oblibs/types.h> #include <oblibs/directory.h> +#include <oblibs/sastr.h> #include <skalibs/genalloc.h> #include <skalibs/djbunix.h> +#include <skalibs/types.h> #include <66/resolve.h> #include <66/ssexec.h> @@ -40,11 +43,12 @@ int rc_init(ssexec_t *info, char const *const *envp) { int r, wstat, empty = 0 ; pid_t pid ; + size_t pos = 0 ; ss_state_t sta = STATE_ZERO ; stralloc sares = STRALLOC_ZERO ; ss_resolve_t res = RESOLVE_ZERO ; - genalloc gasvc = GENALLOC_ZERO ; //stralist type + stralloc sasvc = STRALLOC_ZERO ; genalloc gares = GENALLOC_ZERO ; //ss_resolve_t type char svdir[info->tree.len + SS_SVDIRS_LEN + SS_DB_LEN + 1 + info->treename.len + 1] ; @@ -120,23 +124,23 @@ int rc_init(ssexec_t *info, char const *const *envp) if (wstat) { VERBO1 strerr_warnwu2x("init db of tree: ",info->treename.s) ; goto err ; } - if (!clean_val(&gasvc,res.sa.s + res.deps)) { VERBO1 strerr_warnwu1sys("clean dependencies of inner bundle") ; goto err ; } + if (!sastr_clean_string(&sasvc,res.sa.s + res.deps)) { VERBO1 strerr_warnwu1sys("clean dependencies of inner bundle") ; goto err ; } - for (unsigned int i = 0 ; i < genalloc_len(stralist,&gasvc) ; i++) + for (; pos < sasvc.len ; pos += strlen(sasvc.s + pos) +1) { - char *name = gaistr(&gasvc,i) ; + char *name = sasvc.s + pos ; ss_resolve_t tmp = RESOLVE_ZERO ; if (!ss_resolve_check(sares.s,name)){ VERBO1 strerr_warnw2sys("unknown service: ",name) ; goto err ; } if (!ss_resolve_read(&tmp,sares.s,name)) { VERBO1 strerr_warnwu2sys("read resolve file of: ",name) ; goto err ; } if (!ss_resolve_add_deps(&gares,&tmp,sares.s)) { VERBO1 strerr_warnwu2sys("resolve dependencies of: ",name) ; goto err ; } ss_resolve_free(&tmp) ; } - - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&gares) ; i++) + + for (pos = 0 ; pos < genalloc_len(ss_resolve_t,&gares) ; pos++) { - char const *string = genalloc_s(ss_resolve_t,&gares)[i].sa.s ; - char const *name = string + genalloc_s(ss_resolve_t,&gares)[i].name ; - char const *state = string + genalloc_s(ss_resolve_t,&gares)[i].state ; + char const *string = genalloc_s(ss_resolve_t,&gares)[pos].sa.s ; + char const *name = string + genalloc_s(ss_resolve_t,&gares)[pos].name ; + char const *state = string + genalloc_s(ss_resolve_t,&gares)[pos].state ; VERBO2 strerr_warni2x("Write state file of: ",name) ; if (!ss_state_write(&sta,state,name)) @@ -147,20 +151,16 @@ int rc_init(ssexec_t *info, char const *const *envp) VERBO1 strerr_warni2x("Initialized successfully: ",name) ; } - /* - VERBO2 strerr_warnt2x("reload scandir: ",info->scandir.s) ; - if (scandir_send_signal(info->scandir.s,"an") <= 0) goto err ; - */ end: genalloc_deepfree(ss_resolve_t,&gares,ss_resolve_free) ; - genalloc_deepfree(stralist,&gasvc,stra_free) ; + stralloc_free(&sasvc) ; ss_resolve_free(&res) ; stralloc_free(&sares) ; return empty ? 2 : 1 ; err: genalloc_deepfree(ss_resolve_t,&gares,ss_resolve_free) ; - genalloc_deepfree(stralist,&gasvc,stra_free) ; + stralloc_free(&sasvc) ; ss_resolve_free(&res) ; stralloc_free(&sares) ; return 0 ; diff --git a/src/lib66/rc_send.c b/src/lib66/rc_send.c index 2dc45a768b5b4891d18f5a257ff9b146379d6204..d0026e8a30e508fbcbf313a072536a348072e20a 100644 --- a/src/lib66/rc_send.c +++ b/src/lib66/rc_send.c @@ -14,8 +14,7 @@ #include <66/rc.h> -#include <string.h> -#include <stdlib.h> +#include <stddef.h> #include <skalibs/genalloc.h> @@ -24,7 +23,7 @@ int rc_send(ssexec_t *info,genalloc *ga,char const *sig,char const *const *envp) { - unsigned int i = 0 ; + size_t i = 0 ; int nargc = 3 + genalloc_len(ss_resolve_t,ga) ; char const *newargv[nargc] ; unsigned int m = 0 ; diff --git a/src/lib66/rc_unsupervise.c b/src/lib66/rc_unsupervise.c index 49494a7da76cddc477d33c7900d81596a0207dc6..a512846969fff5a3be9ab5176080042f57ff18ba 100644 --- a/src/lib66/rc_unsupervise.c +++ b/src/lib66/rc_unsupervise.c @@ -33,6 +33,7 @@ int rc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *const *envp) { + size_t i = 0 ; ss_resolve_t_ref pres ; stralloc sares = STRALLOC_ZERO ; ss_state_t sta = STATE_ZERO ; @@ -60,7 +61,7 @@ int rc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *const goto err ; } - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) + for (; i < genalloc_len(ss_resolve_t,ga) ; i++) { char const *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; char const *name = string + genalloc_s(ss_resolve_t,ga)[i].name ; @@ -73,7 +74,7 @@ int rc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *const strerr_warnwu1sys("set revolve pointer to source") ; goto err ; } - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) + for (i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) { pres = &genalloc_s(ss_resolve_t,ga)[i] ; char const *string = pres->sa.s ; @@ -91,7 +92,7 @@ int rc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *const { ss_state_setflag(&sta,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_INIT,SS_FLAGS_TRUE) ; - ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; + // ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_PID,SS_FLAGS_FALSE) ; VERBO2 strerr_warni2x("Write state file of: ",name) ; diff --git a/src/lib66/resolve.c b/src/lib66/resolve.c index cc943043528107e3124e8e3622a837b7305e5b01..a8a98e1ca0161a3c4b94ee51f527073b1a086aee 100644 --- a/src/lib66/resolve.c +++ b/src/lib66/resolve.c @@ -14,7 +14,9 @@ #include <string.h> #include <sys/stat.h> +#include <stdint.h> #include <stdlib.h>//realpath +#include <sys/types.h> //#include <stdio.h> #include <oblibs/types.h> @@ -22,7 +24,6 @@ #include <oblibs/directory.h> #include <oblibs/files.h> #include <oblibs/string.h> -#include <oblibs/stralist.h> #include <oblibs/sastr.h> #include <skalibs/stralloc.h> @@ -102,7 +103,7 @@ int ss_resolve_pointo(stralloc *sa,ssexec_t *info,unsigned int type, unsigned in else if (!stralloc_cats(&tmp,SS_DB)) goto err ; } if (!stralloc_0(&tmp) || - !stralloc_obreplace(sa,tmp.s)) goto err ; + !stralloc_copy(sa,&tmp)) goto err ; stralloc_free(&tmp) ; return 1 ; @@ -142,7 +143,7 @@ int ss_resolve_src_path(stralloc *sasrc,char const *sv, ssexec_t *info) src = SS_SERVICE_SYSDIR ; r = ss_resolve_src(sasrc,sv,src,&found) ; if (r < 0) { VERBO3 strerr_warnwu2sys("parse source directory: ",src) ; goto err ; } - if (!r) { VERBO3 strerr_warnw2sys("unknown service: ",sv) ; goto err ; } + if (!r) { VERBO3 strerr_warnw2x("unknown service: ",sv) ; goto err ; } } } stralloc_free(&home) ; @@ -175,8 +176,6 @@ int ss_resolve_src(stralloc *sasrc, char const *name, char const *src,int *found stralloc subdir = STRALLOC_ZERO ; stralloc satmp = STRALLOC_ZERO ; - obr = insta = 0 ; - DIR *dir = opendir(src) ; if (!dir) { @@ -214,11 +213,11 @@ int ss_resolve_src(stralloc *sasrc, char const *name, char const *src,int *found obr = 0 ; insta = 0 ; obr = obstr_equal(name,d->d_name) ; - insta = insta_check(name) ; + insta = instance_check(name) ; if (insta > 0) { - if (!insta_splitname(&sainsta,name,insta,0)) goto errdir ; + if (!instance_splitname(&sainsta,name,insta,0)) goto errdir ; obr = obstr_equal(sainsta.s,d->d_name) ; } @@ -570,8 +569,6 @@ int ss_resolve_setlognwrite(ss_resolve_t *sv, char const *dst,ssexec_t *info) int ss_resolve_setnwrite(sv_alltype *services, ssexec_t *info, char const *dst) { - int r ; - char ownerstr[UID_FMT] ; size_t ownerlen = uid_fmt(ownerstr,info->owner) ; ownerstr[ownerlen] = 0 ; @@ -653,26 +650,11 @@ int ss_resolve_setnwrite(sv_alltype *services, ssexec_t *info, char const *dst) if (res.ndeps) { - for (unsigned int i = 0; i < res.ndeps; i++) + size_t id = services->cname.idga, nid = res.ndeps ; + for (;nid; id += strlen(deps.s + id) + 1, nid--) { - if (!stralloc_obreplace(&namedeps,deps.s+genalloc_s(unsigned int,&gadeps)[services->cname.idga+i])) goto err ; - r = insta_check(namedeps.s) ; - if (!r) - { - VERBO1 strerr_warnw2x(" invalid instance name: ",namedeps.s) ; - goto err ; - } - if (r > 0) - { - if (!insta_splitname(&namedeps,namedeps.s,r,1)) - { - VERBO1 strerr_warnwu2x("split copy name of instance: ",namedeps.s) ; - goto err ; - } - } - namedeps.len--; - if (!stralloc_catb(&final,namedeps.s,namedeps.len)) { VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } - if (!stralloc_catb(&final," ",1)) {VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } + if (!stralloc_catb(&final,deps.s + id,strlen(deps.s + id)) || + !stralloc_catb(&final," ",1)) retstralloc(0,"write_dependencies") ; } final.len-- ; if (!stralloc_0(&final)){ VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } @@ -804,8 +786,8 @@ int ss_resolve_append(genalloc *ga,ss_resolve_t *res) int ss_resolve_add_deps(genalloc *tokeep,ss_resolve_t *res, char const *src) { - unsigned int i = 0 ; - genalloc tmp = GENALLOC_ZERO ; + size_t pos = 0 ; + stralloc tmp = STRALLOC_ZERO ; char *name = res->sa.s + res->name ; char *deps = res->sa.s + res->deps ; @@ -814,39 +796,40 @@ int ss_resolve_add_deps(genalloc *tokeep,ss_resolve_t *res, char const *src) if (res->ndeps) { - if (!clean_val(&tmp,deps)) return 0 ; - for (;i < genalloc_len(stralist,&tmp) ; i++) + if (!sastr_clean_string(&tmp,deps)) return 0 ; + for (;pos < tmp.len ; pos += strlen(tmp.s + pos) + 1) { ss_resolve_t dres = RESOLVE_ZERO ; - if (!ss_resolve_check(src,gaistr(&tmp,i))) goto err ; - if (!ss_resolve_read(&dres,src,gaistr(&tmp,i))) goto err ; - if (dres.ndeps && !ss_resolve_cmp(tokeep,gaistr(&tmp,i))) + char *dname = tmp.s + pos ; + if (!ss_resolve_check(src,dname)) goto err ; + if (!ss_resolve_read(&dres,src,dname)) goto err ; + if (dres.ndeps && !ss_resolve_cmp(tokeep,dname)) { if (!ss_resolve_add_deps(tokeep,&dres,src)) goto err ; } - if (!ss_resolve_cmp(tokeep,gaistr(&tmp,i))) + if (!ss_resolve_cmp(tokeep,dname)) { if (!ss_resolve_append(tokeep,&dres)) goto err ; } ss_resolve_free(&dres) ; } } - genalloc_deepfree(stralist,&tmp,stra_free) ; + stralloc_free(&tmp) ; return 1 ; err: - genalloc_deepfree(stralist,&tmp,stra_free) ; + stralloc_free(&tmp) ; return 0 ; } int ss_resolve_add_rdeps(genalloc *tokeep, ss_resolve_t *res, char const *src) { int type ; - genalloc tmp = GENALLOC_ZERO ; - genalloc nsv = GENALLOC_ZERO ; + stralloc tmp = STRALLOC_ZERO ; + stralloc nsv = STRALLOC_ZERO ; ss_state_t sta = STATE_ZERO ; char *name = res->sa.s + res->name ; - size_t srclen = strlen(src) ; + size_t srclen = strlen(src), a = 0, b = 0, c = 0 ; char s[srclen + SS_RESOLVE_LEN + 1] ; memcpy(s,src,srclen) ; memcpy(s + srclen,SS_RESOLVE,SS_RESOLVE_LEN) ; @@ -855,7 +838,7 @@ int ss_resolve_add_rdeps(genalloc *tokeep, ss_resolve_t *res, char const *src) if (res->type == CLASSIC) type = 0 ; else type = 1 ; - if (!dir_get(&nsv,s,SS_MASTER+1,S_IFREG)) goto err ; + if (!sastr_dir_get(&nsv,s,SS_MASTER+1,S_IFREG)) goto err ; if (!ss_resolve_cmp(tokeep,name) && (!obstr_equal(name,SS_MASTER+1))) { @@ -863,13 +846,14 @@ int ss_resolve_add_rdeps(genalloc *tokeep, ss_resolve_t *res, char const *src) } if (res->type == BUNDLE && res->ndeps) { - if (!clean_val(&tmp,res->sa.s + res->deps)) goto err ; + if (!sastr_clean_string(&tmp,res->sa.s + res->deps)) goto err ; ss_resolve_t dres = RESOLVE_ZERO ; - for (unsigned int i = 0 ; i < genalloc_len(stralist,&tmp) ; i++) + for (; a < tmp.len ; a += strlen(tmp.s + a) + 1) { - if (!ss_resolve_check(src,gaistr(&tmp,i))) goto err ; - if (!ss_resolve_read(&dres,src,gaistr(&tmp,i))) goto err ; - if (!ss_resolve_cmp(tokeep,gaistr(&tmp,i))) + char *name = tmp.s + a ; + if (!ss_resolve_check(src,name)) goto err ; + if (!ss_resolve_read(&dres,src,name)) goto err ; + if (!ss_resolve_cmp(tokeep,name)) { if (!ss_resolve_append(tokeep,&dres)) goto err ; if (!ss_resolve_add_rdeps(tokeep,&dres,src)) goto err ; @@ -877,12 +861,12 @@ int ss_resolve_add_rdeps(genalloc *tokeep, ss_resolve_t *res, char const *src) ss_resolve_free(&dres) ; } } - for (unsigned int i = 0 ; i < genalloc_len(stralist,&nsv) ; i++) + for (; b < nsv.len ; b += strlen(nsv.s + b) +1) { int dtype = 0 ; - genalloc_deepfree(stralist,&tmp,stra_free) ; + tmp.len = 0 ; ss_resolve_t dres = RESOLVE_ZERO ; - char *dname = gaistr(&nsv,i) ; + char *dname = nsv.s + b ; if (obstr_equal(name,dname)) { ss_resolve_free(&dres) ; continue ; } if (!ss_resolve_check(src,dname)) goto err ; @@ -902,10 +886,10 @@ int ss_resolve_add_rdeps(genalloc *tokeep, ss_resolve_t *res, char const *src) { if (dres.ndeps)// || (dres.type == BUNDLE && dres.ndeps) || ) { - if (!clean_val(&tmp,dres.sa.s + dres.deps)) goto err ; - for (unsigned int j = 0 ; j < genalloc_len(stralist,&tmp) ; j++) + if (!sastr_clean_string(&tmp,dres.sa.s + dres.deps)) goto err ; + for (c = 0 ; c < tmp.len ; c += strlen(tmp.s + c) + 1) { - if (obstr_equal(name,gaistr(&tmp,j))) + if (obstr_equal(name,tmp.s + c)) { if (!ss_resolve_append(tokeep,&dres)) goto err ; if (!ss_resolve_add_rdeps(tokeep,&dres,src)) goto err ; @@ -919,20 +903,21 @@ int ss_resolve_add_rdeps(genalloc *tokeep, ss_resolve_t *res, char const *src) ss_resolve_free(&dres) ; } - genalloc_deepfree(stralist,&tmp,stra_free) ; - genalloc_deepfree(stralist,&nsv,stra_free) ; + stralloc_free(&nsv) ; + stralloc_free(&tmp) ; return 1 ; err: - genalloc_deepfree(stralist,&tmp,stra_free) ; - genalloc_deepfree(stralist,&nsv,stra_free) ; + stralloc_free(&nsv) ; + stralloc_free(&tmp) ; return 0 ; } int ss_resolve_add_logger(genalloc *ga,char const *src) { + size_t i = 0 ; genalloc gatmp = GENALLOC_ZERO ; - - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) + + for (; i < genalloc_len(ss_resolve_t,ga) ; i++) { ss_resolve_t res = RESOLVE_ZERO ; ss_resolve_t dres = RESOLVE_ZERO ; @@ -985,16 +970,18 @@ int ss_resolve_create_live(ssexec_t *info) if (!r) { ssize_t len = get_rlen_until(sares.s,'/',sares.len) ; - - char sym[sares.len + SS_RESOLVE_LEN + 1] ; - memcpy(sym,sares.s,len) ; - sym[len] = 0 ; - r = dir_create_under(sym,info->treename.s,0700) ; + sares.len-- ; + char sym[sares.len + SS_SVDIRS_LEN + 1] ; + memcpy(sym,sares.s,sares.len) ; + sym[sares.len] = 0 ; + + r = dir_create_parent(sym,0700) ; if (!r) goto err ; + sym[len] = 0 ; if (chown(sym,info->owner,gidowner) < 0) goto err ; - memcpy(sym,sares.s,sares.len - 1) ; - memcpy(sym + (sares.len - 1), SS_SVDIRS, SS_SVDIRS_LEN) ; - sym[(sares.len - 1) + SS_SVDIRS_LEN] = 0 ; + memcpy(sym,sares.s,sares.len) ; + memcpy(sym + sares.len, SS_SVDIRS, SS_SVDIRS_LEN) ; + sym[sares.len + SS_SVDIRS_LEN] = 0 ; VERBO3 strerr_warnt4x("point symlink: ",sym," to ",ressrc.s) ; if (symlink(ressrc.s,sym) < 0) @@ -1030,15 +1017,14 @@ int ss_resolve_search(genalloc *ga,char const *name) int ss_resolve_write_master(ssexec_t *info,ss_resolve_graph_t *graph,char const *dir, unsigned int reverse) { int r ; - + size_t i = 0 ; char ownerstr[UID_FMT] ; size_t ownerlen = uid_fmt(ownerstr,info->owner) ; ownerstr[ownerlen] = 0 ; stralloc in = STRALLOC_ZERO ; stralloc inres = STRALLOC_ZERO ; - stralloc already = STRALLOC_ZERO ; - genalloc gain = GENALLOC_ZERO ; + stralloc gain = STRALLOC_ZERO ; ss_resolve_t res = RESOLVE_ZERO ; size_t dirlen = strlen(dir) ; @@ -1078,21 +1064,20 @@ int ss_resolve_write_master(ssexec_t *info,ss_resolve_graph_t *graph,char const file[dstlen + 1 + SS_CONTENTS_LEN] = 0 ; size_t filesize=file_get_size(file) ; - r = openreadfileclose(file,&already,filesize) ; + r = openreadfileclose(file,&gain,filesize) ; if(!r) goto err ; /** ensure that we have an empty line at the end of the string*/ - if (!stralloc_cats(&already,"\n")) goto err ; - if (!stralloc_0(&already)) goto err ; - if (!clean_val(&gain,already.s)) goto err ; - stralloc_free(&already) ; + if (!stralloc_cats(&gain,"\n")) goto err ; + if (!stralloc_0(&gain)) goto err ; + if (!sastr_clean_element(&gain)) goto err ; } - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&graph->sorted); i++) + for (; i < genalloc_len(ss_resolve_t,&graph->sorted); i++) { char *string = genalloc_s(ss_resolve_t,&graph->sorted)[i].sa.s ; char *name = string + genalloc_s(ss_resolve_t,&graph->sorted)[i].name ; if (reverse) - if (!stra_cmp(&gain,name)) continue ; + if (sastr_cmp(&gain,name) == -1) continue ; if (!stralloc_cats(&in,name)) goto err ; if (!stralloc_cats(&in,"\n")) goto err ; @@ -1128,15 +1113,13 @@ int ss_resolve_write_master(ssexec_t *info,ss_resolve_graph_t *graph,char const stralloc_free(&in) ; stralloc_free(&inres) ; ss_resolve_free(&res) ; - stralloc_free(&already) ; - genalloc_deepfree(stralist,&gain,stra_free) ; + stralloc_free(&gain) ; return 1 ; err: ss_resolve_free(&res) ; stralloc_free(&in) ; stralloc_free(&inres) ; - stralloc_free(&already) ; - genalloc_deepfree(stralist,&gain,stra_free) ; + stralloc_free(&gain) ; return 0 ; } diff --git a/src/lib66/resolve_graph.c b/src/lib66/resolve_graph.c index 03e74a8bd7f878d843bd6c1d26c483dbff5fdb41..5fa9d2a6bc996c08ad5c1f849d194851cd6d7215 100644 --- a/src/lib66/resolve_graph.c +++ b/src/lib66/resolve_graph.c @@ -17,6 +17,7 @@ #include <oblibs/string.h> #include <oblibs/directory.h> #include <oblibs/error2.h> +#include <oblibs/sastr.h> #include <skalibs/genalloc.h> @@ -105,20 +106,21 @@ int ss_resolve_graph_sort(ss_resolve_graph_t *graph) int ss_resolve_graph_publish(ss_resolve_graph_t *graph,unsigned int reverse) { int ret = 0 ; - genalloc gatmp = GENALLOC_ZERO ; + size_t a = 0 , b = 0 ; + stralloc sa = STRALLOC_ZERO ; - for (unsigned int a = 0 ; a < genalloc_len(ss_resolve_t,&graph->name) ; a++) + for (; a < genalloc_len(ss_resolve_t,&graph->name) ; a++) { ss_resolve_graph_ndeps_t rescp = RESOLVE_GRAPH_NDEPS_ZERO ; rescp.idx = a ; if (genalloc_s(ss_resolve_t,&graph->name)[a].ndeps) { - genalloc_deepfree(stralist,&gatmp,stra_free) ; - if (!clean_val(&gatmp, genalloc_s(ss_resolve_t,&graph->name)[a].sa.s + genalloc_s(ss_resolve_t,&graph->name)[a].deps)) goto err ; - for (unsigned int b = 0 ; b < genalloc_len(stralist,&gatmp) ; b++) + sa.len = 0 ; + if (!sastr_clean_string(&sa, genalloc_s(ss_resolve_t,&graph->name)[a].sa.s + genalloc_s(ss_resolve_t,&graph->name)[a].deps)) goto err ; + for (; b < sa.len ; b += strlen(sa.s + b) +1) { - char *deps = gaistr(&gatmp,b) ; + char *deps = sa.s + b ; int r = ss_resolve_search(&graph->name,deps) ; if (r >= 0) { @@ -132,10 +134,10 @@ int ss_resolve_graph_publish(ss_resolve_graph_t *graph,unsigned int reverse) if (ss_resolve_graph_sort(graph) < 0) { ret = -1 ; goto err ; } if (!reverse) genalloc_reverse(ss_resolve_t,&graph->sorted) ; - genalloc_deepfree(stralist,&gatmp,stra_free) ; + stralloc_free(&sa) ; return 1 ; err: - genalloc_deepfree(stralist,&gatmp,stra_free) ; + stralloc_free(&sa) ; return ret ; } @@ -171,9 +173,9 @@ int ss_resolve_graph_build(ss_resolve_graph_t *graph,ss_resolve_t *res,char cons * @Return 0 on fail*/ int ss_resolve_graph_src(ss_resolve_graph_t *graph, char const *dir, unsigned int reverse, unsigned int what) { - genalloc gatmp = GENALLOC_ZERO ; + stralloc sa = STRALLOC_ZERO ; ss_resolve_t res = RESOLVE_ZERO ; - size_t dirlen = strlen(dir) ; + size_t dirlen = strlen(dir), pos = 0 ; char solve[dirlen + SS_DB_LEN + SS_SRC_LEN + 1] ; memcpy(solve,dir,dirlen) ; @@ -182,29 +184,28 @@ int ss_resolve_graph_src(ss_resolve_graph_t *graph, char const *dir, unsigned in { memcpy(solve + dirlen, SS_SVC, SS_SVC_LEN) ; solve[dirlen + SS_SVC_LEN] = 0 ; - if (!dir_get(&gatmp,solve,"",S_IFDIR)) goto err ; + if (!sastr_dir_get(&sa,solve,"",S_IFDIR)) goto err ; } if (what) { memcpy(solve + dirlen, SS_DB, SS_DB_LEN) ; memcpy(solve + dirlen + SS_DB_LEN, SS_SRC, SS_SRC_LEN) ; solve[dirlen + SS_DB_LEN + SS_SRC_LEN] = 0 ; - if (!dir_get(&gatmp,solve,SS_MASTER + 1,S_IFDIR)) goto err ; + if (!sastr_dir_get(&sa,solve,SS_MASTER + 1,S_IFDIR)) goto err ; } - - for(unsigned int i = 0 ; i < genalloc_len(stralist,&gatmp) ; i++) + for (;pos < sa.len; pos += strlen(sa.s + pos) + 1) { - char *name = gaistr(&gatmp,i) ; + char *name = sa.s + pos ; if (!ss_resolve_check(dir,name)) goto err ; if (!ss_resolve_read(&res,dir,name)) goto err ; if (!ss_resolve_graph_build(graph,&res,dir,reverse)) goto err ; } - genalloc_deepfree(stralist,&gatmp,stra_free) ; + stralloc_free(&sa) ; ss_resolve_free(&res) ; return 1 ; err: - genalloc_deepfree(stralist,&gatmp,stra_free) ; + stralloc_free(&sa) ; ss_resolve_free(&res) ; return 0 ; } diff --git a/src/lib66/scandir_send_signal.c b/src/lib66/scandir_send_signal.c index 8aa34efc6cea3b5498cae53473b1a6b53c7b8719..cad238eaefd7db8f7ee61e7f43e66e9c4d0d7eaa 100644 --- a/src/lib66/scandir_send_signal.c +++ b/src/lib66/scandir_send_signal.c @@ -14,6 +14,8 @@ #include <66/utils.h> +#include <stddef.h> + #include <oblibs/error2.h> #include <s6/s6-supervise.h> diff --git a/src/lib66/set_livedir.c b/src/lib66/set_livedir.c index cfae00bdfd08395189e2745080da86f0ec364368..5901194ca2302fadcff6ce323a281b8909212877 100644 --- a/src/lib66/set_livedir.c +++ b/src/lib66/set_livedir.c @@ -15,7 +15,6 @@ #include <66/utils.h> #include <oblibs/error2.h> -#include <oblibs/directory.h> #include <skalibs/stralloc.h> diff --git a/src/lib66/set_livescan.c b/src/lib66/set_livescan.c index 67a4b240cd204769f0cd29d8d79684b56fafb9f5..9d30f1e5ff7c11f539c6ec48404aa2d33eb03072 100644 --- a/src/lib66/set_livescan.c +++ b/src/lib66/set_livescan.c @@ -13,14 +13,14 @@ */ #include <66/utils.h> - + +#include <stddef.h> + #include <oblibs/error2.h> -#include <oblibs/directory.h> #include <skalibs/stralloc.h> #include <skalibs/types.h> -#include <66/config.h> #include <66/constants.h> int set_livescan(stralloc *scandir,uid_t owner) diff --git a/src/lib66/set_livestate.c b/src/lib66/set_livestate.c index 43f13cea512cec95eeadd23eababa3db49661e89..a8409b1c5a0d5203b1f0363a7aa6b4b4ccb6fde2 100644 --- a/src/lib66/set_livestate.c +++ b/src/lib66/set_livestate.c @@ -13,22 +13,21 @@ */ #include <66/utils.h> - + +#include <stddef.h> + #include <oblibs/error2.h> -#include <oblibs/directory.h> #include <skalibs/stralloc.h> #include <skalibs/types.h> -#include <66/config.h> #include <66/constants.h> int set_livestate(stralloc *livestate,uid_t owner) { int r ; char ownerpack[UID_FMT] ; - - + r = set_livedir(livestate) ; if (r < 0) return -1 ; if (!r) return 0 ; diff --git a/src/lib66/set_livetree.c b/src/lib66/set_livetree.c index 8b7b08f94b8d32a61e5e1854e6254b06015a8f46..e0bb8bd99e8ff167062f1e896c48cc4ac630a6bb 100644 --- a/src/lib66/set_livetree.c +++ b/src/lib66/set_livetree.c @@ -13,22 +13,21 @@ */ #include <66/utils.h> - + +#include <stddef.h> + #include <oblibs/error2.h> -#include <oblibs/directory.h> #include <skalibs/stralloc.h> #include <skalibs/types.h> -#include <66/config.h> #include <66/constants.h> int set_livetree(stralloc *livetree,uid_t owner) { int r ; char ownerpack[UID_FMT] ; - - + r = set_livedir(livetree) ; if (r < 0) return -1 ; if (!r) return 0 ; diff --git a/src/lib66/set_ownerhome.c b/src/lib66/set_ownerhome.c index 07a748a36942d61d2c80340eac6804e6fea8a649..39b8555f5261fd70222e6404e706803c174ea52b 100644 --- a/src/lib66/set_ownerhome.c +++ b/src/lib66/set_ownerhome.c @@ -26,10 +26,10 @@ int set_ownerhome(stralloc *base,uid_t owner) { - char const *user_home = NULL ; + char const *user_home = 0 ; int e = errno ; struct passwd *st = getpwuid(owner) ; - + errno = 0 ; if (!st) { if (!errno) errno = ESRCH ; diff --git a/src/lib66/set_ownersysdir.c b/src/lib66/set_ownersysdir.c index 624171dbebd95de522c6d897819e83b0c8c2c1b5..1647d9d8bc618f28373af69d6d9edc781dd6ba3b 100644 --- a/src/lib66/set_ownersysdir.c +++ b/src/lib66/set_ownersysdir.c @@ -29,7 +29,7 @@ int set_ownersysdir(stralloc *base, uid_t owner) char const *user_home = NULL ; int e = errno ; struct passwd *st = getpwuid(owner) ; - + errno = 0 ; if (!st) { if (!errno) errno = ESRCH ; diff --git a/src/lib66/ssexec_dbctl.c b/src/lib66/ssexec_dbctl.c index ccaec1c4de87cccb898e4261f4f4fce1b20c3b80..250e6ee2bd68c140448fa62392e3c5b354340985 100644 --- a/src/lib66/ssexec_dbctl.c +++ b/src/lib66/ssexec_dbctl.c @@ -150,7 +150,7 @@ static int check_status(genalloc *gares,ssexec_t *info,int signal) if (nret) ret = 111 ; ss_state_setflag(&sta,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; - ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; + // ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; if (pres->type == BUNDLE || pres->type == ONESHOT) { if (up) ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_TRUE) ; diff --git a/src/lib66/ssexec_enable.c b/src/lib66/ssexec_enable.c index f69384ba8a46882b3fe6c75d85c0aa92c7491118..56ec9ec98c50361f71948873375062311b9ed06c 100644 --- a/src/lib66/ssexec_enable.c +++ b/src/lib66/ssexec_enable.c @@ -13,18 +13,18 @@ */ #include <string.h> +#include <stdint.h> #include <errno.h> //#include <stdio.h> #include <oblibs/obgetopt.h> #include <oblibs/error2.h> -#include <oblibs/stralist.h> #include <oblibs/string.h> +#include <oblibs/sastr.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <skalibs/djbunix.h> -#include <skalibs/diuint32.h> #include <66/constants.h> #include <66/utils.h> @@ -37,9 +37,9 @@ /** force == 1, only rewrite the service * force == 2, rewrite the service and it dependencies*/ -static unsigned int FORCE = 0 ; +static uint8_t FORCE = 0 ; /** rewrite configuration file */ -static unsigned int CONF = 0 ; +static uint8_t CONF = 0 ; static void cleanup(char const *dst) { @@ -55,47 +55,28 @@ static void check_identifier(char const *name) static void start_parser(stralloc *list,ssexec_t *info, unsigned int *nbsv) { - unsigned int exist = 0 ; - stralloc sares = STRALLOC_ZERO ; + int r ; + uint8_t exist = 0 ; + size_t i = 0, len = list->len ; + stralloc sasv = STRALLOC_ZERO ; stralloc tmp = STRALLOC_ZERO ; - ss_resolve_t res = RESOLVE_ZERO ; -// if (!parse_service_get_list(&tmp,list)) strerr_diefu1x(111,"get services list") ; -// if (!stralloc_copy(list,&tmp)) strerr_diefu1sys(111,"copy stralloc") ; - tmp.len = 0 ; - size_t i = 0, len = list->len ; - if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) strerr_diefu1sys(111,"set revolve pointer to source") ; for (;i < len; i += strlen(list->s + i) + 1) { exist = 0 ; - sares.len = 0 ; char *name = list->s+i ; size_t namelen = strlen(name) ; char svname[namelen + 1] ; - if (!basename(svname,name)) strerr_diefu2sys(111,"get basename of: ", name) ; - if (ss_resolve_check(sares.s,svname)) - { - if (!ss_resolve_read(&res,sares.s,svname)) strerr_diefu2sys(111,"read resolve file of: ",svname) ; - if (res.disen) - { - exist = 1 ; - if (!FORCE) - { - VERBO1 strerr_warnw3x("Ignoring: ",svname," service: already enabled") ; - continue ; - } - } - } - - if (!parse_service_before(info,&tmp,name,nbsv,&sasv,FORCE,exist)) + if (!basename(svname,name)) strerr_diefu2sys(111,"get basename of: ", svname) ; + r = parse_service_check_enabled(info,svname,FORCE,&exist) ; + if (!r) strerr_diefu2x(111,"check enabled service: ",svname) ; + if (r == 2) continue ; + if (!parse_service_before(info,&tmp,name,nbsv,&sasv,FORCE,&exist)) strerr_diefu3x(111,"parse service file: ",svname,": or its dependencies") ; } - stralloc_free(&sares) ; stralloc_free(&sasv) ; - stralloc_free(&tmp) ; - ss_resolve_free(&res) ; - + stralloc_free(&tmp) ; } int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssexec_t *info) @@ -105,12 +86,13 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex CONF = 0 ; int r ; + size_t pos = 0 ; unsigned int nbsv, nlongrun, nclassic, start ; stralloc home = STRALLOC_ZERO ; stralloc workdir = STRALLOC_ZERO ; stralloc sasrc = STRALLOC_ZERO ; - genalloc tostart = GENALLOC_ZERO ; // type stralist + stralloc tostart = STRALLOC_ZERO ; r = nbsv = nclassic = nlongrun = start = 0 ; @@ -168,11 +150,11 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex strerr_diefu2x(111,"write revolve file for: ",name) ; } VERBO2 strerr_warni2x("Service written successfully: ", name) ; - if (!stra_cmp(&tostart,name)) + if (sastr_cmp(&tostart,name) == -1) { if (sv->cname.itype == CLASSIC) nclassic++ ; else nlongrun++ ; - if (!stra_add(&tostart,name)) + if (!sastr_add_string(&tostart,name)) { cleanup(workdir.s) ; retstralloc(111,"main") ; @@ -240,30 +222,30 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex stralloc_free(&workdir) ; stralloc_free(&sasrc) ; - for (unsigned int i = 0 ; i < genalloc_len(stralist,&tostart); i++) - VERBO1 strerr_warni2x("Enabled successfully: ", gaistr(&tostart,i)) ; + for (; pos < tostart.len; pos += strlen(tostart.s + pos) + 1) + VERBO1 strerr_warni2x("Enabled successfully: ", tostart.s + pos) ; - if (start && genalloc_len(stralist,&tostart)) + if (start && tostart.len) { - int nargc = 2 + genalloc_len(stralist,&tostart) ; + int nargc = 2 + sastr_len(&tostart) ; char const *newargv[nargc] ; unsigned int m = 0 ; newargv[m++] = "fake_name" ; - for (unsigned int i = 0 ; i < genalloc_len(stralist,&tostart); i++) - newargv[m++] = gaistr(&tostart,i) ; + for (pos = 0 ; pos < tostart.len; pos += strlen(tostart.s + pos) + 1) + newargv[m++] = tostart.s + pos ; newargv[m++] = 0 ; if (ssexec_start(nargc,newargv,envp,info)) { - genalloc_deepfree(stralist,&tostart,stra_free) ; + stralloc_free(&tostart) ; return 111 ; } } - genalloc_deepfree(stralist,&tostart,stra_free) ; + stralloc_free(&tostart) ; return 0 ; } diff --git a/src/lib66/ssexec_init.c b/src/lib66/ssexec_init.c index c87dbad03410d0cf5260816148ce19659cd4cd24..f4548e5b09a3a61b13fe5735f77130a674c07e05 100644 --- a/src/lib66/ssexec_init.c +++ b/src/lib66/ssexec_init.c @@ -15,12 +15,14 @@ #include <string.h> #include <sys/types.h> #include <unistd.h>//chown -//#include <stdio.h> +#include <stdio.h> #include <oblibs/error2.h> #include <oblibs/types.h>//scan_mode #include <oblibs/stralist.h> #include <oblibs/directory.h> +#include <oblibs/sastr.h> +#include <oblibs/string.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> @@ -39,11 +41,10 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec_t *info) { int r, db, classic, earlier ; - - genalloc gasvc = GENALLOC_ZERO ; //stralist type + ssize_t i = 0, logname = 0 ; genalloc gares = GENALLOC_ZERO ; //ss_resolve_t type - stralloc sares = STRALLOC_ZERO ; + stralloc sasvc = STRALLOC_ZERO ; ss_resolve_t res = RESOLVE_ZERO ; ss_state_t sta = STATE_ZERO ; @@ -67,7 +68,7 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec r = scandir_ok(info->scandir.s) ; if (r != 1) earlier = 1 ; - + r = scan_mode(info->livetree.s,S_IFDIR) ; if (r < 0) strerr_dief2x(111,info->livetree.s," conflicted format") ; if (!r) @@ -90,32 +91,30 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec /** svc already initiated? */ if (classic) { - size_t i ; - if (!dir_get(&gasvc,svdir,"",S_IFDIR)) strerr_diefu1x(111,"get classic services") ; - if (!genalloc_len(stralist,&gasvc)) + if (!sastr_dir_get(&sasvc,svdir,"",S_IFDIR)) strerr_diefu2x(111,"get classic services from: ",svdir) ; + if (!sasvc.len) { VERBO1 strerr_warni2x("Initialization aborted -- no classic services into tree: ",info->treename.s) ; - genalloc_deepfree(ss_resolve_t,&gares,ss_resolve_free) ; - genalloc_deepfree(stralist,&gasvc,stra_free) ; goto follow ; } if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) strerr_diefu1x(111,"set revolve pointer to source") ; - for (i = 0 ; i < genalloc_len(stralist,&gasvc) ; i++) + for (i = 0;i < sasvc.len; i += strlen(sasvc.s + i) + 1) { - char *name = gaistr(&gasvc,i) ; + char *name = sasvc.s + i ; ss_resolve_t tmp = RESOLVE_ZERO ; if (!ss_resolve_check(sares.s,name)) strerr_dief2sys(110,"unknown service: ",name) ; if (!ss_resolve_read(&tmp,sares.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; if (!ss_resolve_add_deps(&gares,&tmp,sares.s)) strerr_diefu2sys(111,"resolve dependencies of: ",name) ; ss_resolve_free(&tmp) ; } - /** reverse to start first the logger */ - genalloc_reverse(ss_resolve_t,&gares) ; + if (!earlier) { + /** reverse to start first the logger */ + genalloc_reverse(ss_resolve_t,&gares) ; if (!svc_init(info,svdir,&gares)) strerr_diefu2x(111,"initiate service of tree: ",info->treename.s) ; } else @@ -123,22 +122,25 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec if (!ss_resolve_create_live(info)) strerr_diefu1sys(111,"create live state") ; for (i = 0 ; i < genalloc_len(ss_resolve_t,&gares) ; i++) { + logname = 0 ; char *string = genalloc_s(ss_resolve_t,&gares)[i].sa.s ; char *name = string + genalloc_s(ss_resolve_t,&gares)[i].name ; size_t namelen = strlen(name) ; + logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; + if (logname > 0) name = string + genalloc_s(ss_resolve_t,&gares)[i].logassoc ; 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,string + genalloc_s(ss_resolve_t,&gares)[i].runat)) strerr_diefu4sys(111,"copy: ",tocopy," to: ",string + genalloc_s(ss_resolve_t,&gares)[i].runat) ; + if (!hiercopy(tocopy,string + genalloc_s(ss_resolve_t,&gares)[i].runat)) strerr_diefu4sys(111,"copy earlier service: ",tocopy," to: ",string + genalloc_s(ss_resolve_t,&gares)[i].runat) ; ss_state_setflag(&sta,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; - ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; + // ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_UNKNOWN) ; ss_state_setflag(&sta,SS_FLAGS_PID,SS_FLAGS_UNKNOWN) ; if (!ss_state_write(&sta,string + genalloc_s(ss_resolve_t,&gares)[i].state,name)) strerr_diefu2sys(111,"write state file of: ",name) ; - VERBO1 strerr_warni2x("Initialized successfully: ",name) ; + VERBO1 strerr_warni2x("Initialized successfully: ", logname < 0 ? name : string + genalloc_s(ss_resolve_t,&gares)[i].logreal) ; } } } @@ -146,10 +148,10 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec follow: stralloc_free(&sares) ; + stralloc_free(&sasvc) ; ss_resolve_free(&res) ; genalloc_deepfree(ss_resolve_t,&gares,ss_resolve_free) ; - genalloc_deepfree(stralist,&gasvc,stra_free) ; - + /** db already initiated? */ if (db) { diff --git a/src/lib66/ssexec_stop.c b/src/lib66/ssexec_stop.c index 97c66796365d2c78e0aea4bc9f4c42c130c9a09b..5a35b4292adfbc832149b52621ef6179194cb281 100644 --- a/src/lib66/ssexec_stop.c +++ b/src/lib66/ssexec_stop.c @@ -119,14 +119,14 @@ int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec if (info->timeout) DEADLINE = info->timeout ; - int cl, rc, sigopt, mainunsup ; + int cl, rc, sigopt ; stralloc sares = STRALLOC_ZERO ; genalloc gares = GENALLOC_ZERO ; //ss_resolve_t ss_resolve_t_ref pres ; ss_resolve_t res = RESOLVE_ZERO ; ss_state_t sta = STATE_ZERO ; - cl = rc = sigopt = mainunsup = 0 ; + cl = rc = sigopt = 0 ; { subgetopt_t l = SUBGETOPT_ZERO ; @@ -139,7 +139,7 @@ int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec switch (opt) { - case 'u' : UNSUP = 1 ; mainunsup = 1 ; break ; + case 'u' : UNSUP = 1 ; break ; case 'X' : if (sigopt) exitusage(usage_stop) ; sigopt = 1 ; SIG = "-X" ; break ; case 'K' : if (sigopt) exitusage(usage_stop) ; sigopt = 1 ; SIG = "-K" ; break ; default : exitusage(usage_stop) ; diff --git a/src/lib66/ssexec_svctl.c b/src/lib66/ssexec_svctl.c index 191d86997555ac41c012ebbdd7ab9ef1d79d524d..77e8671d2507f2bcce965119fa42dd8b3dcc6c2b 100644 --- a/src/lib66/ssexec_svctl.c +++ b/src/lib66/ssexec_svctl.c @@ -229,7 +229,7 @@ static void write_state(ss_resolve_sig_t *svc) } ss_state_setflag(&sta,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; - ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; +// ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; VERBO2 strerr_warni2x("Write state file of: ",sv) ; if (!ss_state_write(&sta,state,sv)) { diff --git a/src/lib66/state.c b/src/lib66/state.c index ebef89d97a84b5dba16141d6967cf518aa8ded93..5de2ddca15329a3c454c77c18e788eee2445a87d 100644 --- a/src/lib66/state.c +++ b/src/lib66/state.c @@ -83,12 +83,7 @@ int ss_state_write(ss_state_t *sta, char const *dst, char const *name) ss_state_pack(pack,sta) ; if (!openwritenclose_unsafe(tmp,pack,SS_STATE_SIZE)) return 0 ; - - /*printf("sta.reload:write:%i\n",sta->reload) ; - printf("sta.init::%i\n",sta->init) ; - printf("sta.unsupervise::%i\n",sta->unsupervise) ; - printf("sta.state::%i\n",sta->state) ; - printf("sta.pid:write:%i\n",sta->pid) ;*/ + return 1 ; } @@ -106,11 +101,7 @@ int ss_state_read(ss_state_t *sta, char const *src, char const *name) if (openreadnclose(tmp, pack, SS_STATE_SIZE) < SS_STATE_SIZE) return 0 ; ss_state_unpack(pack, sta) ; - /* printf("sta.reload:read:%i\n",sta->reload) ; - printf("sta.init::%i\n",sta->init) ; - printf("sta.unsupervise::%i\n",sta->unsupervise) ; - printf("sta.state::%i\n",sta->state) ; - printf("sta.pid:read:%i\n",sta->pid) ;*/ + return 1 ; } diff --git a/src/lib66/svc_init.c b/src/lib66/svc_init.c index 84dea548ae5f47347279f72606722139608c9cb8..31a7447cfacb51b1e45df855907202e178629a71 100644 --- a/src/lib66/svc_init.c +++ b/src/lib66/svc_init.c @@ -19,10 +19,9 @@ //#include <stdio.h> #include <oblibs/error2.h> -#include <oblibs/stralist.h> #include <oblibs/string.h> -#include <oblibs/directory.h> #include <oblibs/types.h> +#include <oblibs/sastr.h> #include <skalibs/genalloc.h> #include <skalibs/types.h> @@ -41,13 +40,13 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) { - - int logname ; + size_t namelen, srclen, svscanlen, tmplen, pos, i ; + ssize_t logname ; gid_t gid = getgid() ; uint16_t id ; ftrigr_t fifo = FTRIGR_ZERO ; - genalloc gadown = GENALLOC_ZERO ; + stralloc sadown = STRALLOC_ZERO ; genalloc ids = GENALLOC_ZERO ; // uint16_t ss_state_t sta = STATE_ZERO ; @@ -60,7 +59,7 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) if (!ss_resolve_create_live(info)) { VERBO1 strerr_warnwu1sys("create live state") ; goto err ; } - for (unsigned int i=0 ; i < genalloc_len(ss_resolve_t,ga); i++) + for (i = 0 ; i < genalloc_len(ss_resolve_t,ga); i++) { logname = 0 ; char *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; @@ -80,15 +79,14 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; if (logname > 0) name = string + genalloc_s(ss_resolve_t,ga)[i].logassoc ; - size_t namelen = strlen(name) ; - size_t srclen = strlen(src) ; + namelen = strlen(name) ; + 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 ; if (logname > 0) svscanlen = strlen(string + genalloc_s(ss_resolve_t,ga)[i].runat) - SS_LOG_SUFFIX_LEN ; else svscanlen = strlen(string + genalloc_s(ss_resolve_t,ga)[i].runat) ; char svscan[svscanlen + 6 + 1] ; @@ -116,7 +114,7 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) * check it and create again if doesn't exist */ if (!scan_mode(svscan,S_IFDIR)) { - size_t tmplen = strlen(svsrc) ; + tmplen = strlen(svsrc) ; char tmp[tmplen + 4 + 1] ; memcpy(tmp,svsrc,tmplen) ; memcpy(tmp + tmplen,"/log",4) ; @@ -133,7 +131,7 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) if (!genalloc_s(ss_resolve_t,ga)[i].down) { - if (!stra_add(&gadown,svscan)) + if (!sastr_add_string(&sadown,svscan)) { VERBO3 strerr_warnwu3x("add: ",svscan," to genalloc") ; goto err ; @@ -177,17 +175,17 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) if (ftrigr_wait_and_g(&fifo, genalloc_s(uint16_t, &ids), genalloc_len(uint16_t, &ids), &deadline) < 0) goto err ; - for (unsigned int i = 0 ; i < genalloc_len(stralist,&gadown) ; i++) + for (pos = 0 ; pos < sadown.len; pos += strlen(sadown.s + pos) + 1) { - VERBO3 strerr_warnt2x("Delete down file at: ",gaistr(&gadown,i)) ; - if (unlink(gaistr(&gadown,i)) < 0 && errno != ENOENT) goto err ; + VERBO3 strerr_warnt2x("Delete down file at: ",sadown.s + pos) ; + if (unlink(sadown.s + pos) < 0 && errno != ENOENT) goto err ; } - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) + for (pos = 0 ; pos < genalloc_len(ss_resolve_t,ga) ; pos++) { - char const *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; - char const *name = string + genalloc_s(ss_resolve_t,ga)[i].name ; - char const *state = string + genalloc_s(ss_resolve_t,ga)[i].state ; + char const *string = genalloc_s(ss_resolve_t,ga)[pos].sa.s ; + char const *name = string + genalloc_s(ss_resolve_t,ga)[pos].name ; + char const *state = string + genalloc_s(ss_resolve_t,ga)[pos].state ; VERBO2 strerr_warni2x("Write state file of: ",name) ; if (!ss_state_write(&sta,state,name)) @@ -199,14 +197,14 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) } } ftrigr_end(&fifo) ; - genalloc_deepfree(stralist,&gadown,stra_free) ; + stralloc_free(&sadown) ; genalloc_free(uint16_t, &ids) ; return 1 ; err: ftrigr_end(&fifo) ; genalloc_free(uint16_t, &ids) ; - genalloc_deepfree(stralist,&gadown,stra_free) ; + stralloc_free(&sadown) ; ftrigr_end(&fifo) ; return 0 ; diff --git a/src/lib66/svc_init_pipe.c b/src/lib66/svc_init_pipe.c index 7658cfafabb2abd31c3fec6d8994d9fe27c3fe0c..6e2fc4a5453ddeae81db2756f57ad6e62eaaf551 100644 --- a/src/lib66/svc_init_pipe.c +++ b/src/lib66/svc_init_pipe.c @@ -12,11 +12,10 @@ * except according to the terms contained in the LICENSE file./ */ -#include <stddef.h> -#include <stdlib.h> - #include <66/svc.h> +#include <string.h> + #include <oblibs/error2.h> #include <skalibs/genalloc.h> @@ -33,12 +32,13 @@ int svc_init_pipe(ftrigr_t *fifo,genalloc *gasv,tain_t *deadline) { + size_t i = 0 ; ss_resolve_sig_t *svc ; if (!ftrigr_startf_g(fifo, deadline)) VERBO3 { strerr_warnwu1sys("initiate fifo") ; return 0 ; } - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_sig_t,gasv) ; i++) + for (; i < genalloc_len(ss_resolve_sig_t,gasv) ; i++) { svc = &genalloc_s(ss_resolve_sig_t,gasv)[i] ; char *svok = svc->res.sa.s + svc->res.runat ; diff --git a/src/lib66/svc_send.c b/src/lib66/svc_send.c index 8519a437f9bb91f3bd2e1393613ae6bdfb05774e..3a238c7566ca153910c89df4ae78a725c1a131ec 100644 --- a/src/lib66/svc_send.c +++ b/src/lib66/svc_send.c @@ -14,8 +14,7 @@ #include <66/svc.h> -#include <string.h> -#include <stdlib.h> +#include <stddef.h> #include <skalibs/genalloc.h> @@ -24,7 +23,7 @@ int svc_send(ssexec_t *info,genalloc *ga,char const *sig,char const *const *envp) { - unsigned int i = 0 ; + size_t i = 0 ; int nargc = 3 + genalloc_len(ss_resolve_t,ga) ; char const *newargv[nargc] ; unsigned int m = 0 ; diff --git a/src/lib66/svc_switch_to.c b/src/lib66/svc_switch_to.c index 806ff4f309eee9f785be74c1452b921e2914efe9..8ace91de40667737ef419058da0136302bf24695 100644 --- a/src/lib66/svc_switch_to.c +++ b/src/lib66/svc_switch_to.c @@ -15,6 +15,8 @@ #include <oblibs/error2.h> +#include <string.h> + #include <skalibs/types.h> #include <66/backup.h> diff --git a/src/lib66/svc_unsupervise.c b/src/lib66/svc_unsupervise.c index 1b2747fc2e5803a0e966f240a0098159423834a3..3b2cb3e2822c0688ddd0c0fb3267e72ffc1db51d 100644 --- a/src/lib66/svc_unsupervise.c +++ b/src/lib66/svc_unsupervise.c @@ -15,7 +15,6 @@ #include <66/svc.h> #include <string.h> -#include <unistd.h>//access #include <oblibs/error2.h> @@ -30,6 +29,7 @@ int svc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *const *envp) { + size_t i = 0 ; ss_state_t sta = STATE_ZERO ; ss_resolve_t_ref pres ; stralloc sares = STRALLOC_ZERO ; @@ -40,7 +40,7 @@ int svc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *cons goto err ; } - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) + for (; i < genalloc_len(ss_resolve_t,ga) ; i++) { char const *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; VERBO2 strerr_warni2x("delete directory service: ",string + genalloc_s(ss_resolve_t,ga)[i].runat) ; @@ -55,7 +55,7 @@ int svc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *cons strerr_warnwu1sys("set revolve pointer to source") ; goto err ; } - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) + for (i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) { pres = &genalloc_s(ss_resolve_t,ga)[i] ; char const *string = pres->sa.s ; @@ -73,7 +73,7 @@ int svc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *cons { ss_state_setflag(&sta,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_INIT,SS_FLAGS_TRUE) ; - ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; + // ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_PID,SS_FLAGS_FALSE) ; VERBO2 strerr_warni2x("Write state file of: ",name) ; diff --git a/src/lib66/tree_cmd_state.c b/src/lib66/tree_cmd_state.c index ab2a5a125dd785d5e1cd339ba5fc018928c2570c..e3e6c257d7c5ff595a263d7e8394d1bf6c86e02d 100644 --- a/src/lib66/tree_cmd_state.c +++ b/src/lib66/tree_cmd_state.c @@ -20,12 +20,10 @@ #include <oblibs/error2.h> #include <oblibs/string.h> #include <oblibs/types.h> -#include <oblibs/directory.h> #include <oblibs/files.h> -#include <oblibs/stralist.h> +#include <oblibs/sastr.h> #include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> #include <skalibs/types.h> #include <skalibs/djbunix.h> @@ -36,23 +34,14 @@ int tree_state(int argc, char const *const *argv) { - int r, fd, err ; - unsigned int add, del, sch, verbosity ; - size_t statesize ; - size_t treelen ; - size_t statelen ; - - char const *tree = NULL ; - - stralloc base = STRALLOC_ZERO ; - stralloc contents = STRALLOC_ZERO ; - genalloc in = GENALLOC_ZERO ; //type stralist - - verbosity = err = 1 ; - + int r, fd,skip = -1 ; + unsigned int add, del, sch, verbosity, err ; + size_t statesize = 0, treelen, statelen, pos = 0 ; uid_t owner = MYUID ; - - add = del = sch = 0 ; + char const *tree = 0 ; + + verbosity = 1 ; + add = del = sch = err = 0 ; { subgetopt_t l = SUBGETOPT_ZERO ; @@ -60,33 +49,35 @@ int tree_state(int argc, char const *const *argv) { int opt = getopt_args(argc,argv, "v:sad", &l) ; if (opt == -1) break ; - if (opt == -2){ strerr_warnw1x("options must be set first") ; return -1 ; } + if (opt == -2){ strerr_warnw1x("options must be set first") ; return 0 ; } switch (opt) { - case 'v' : if (!uint0_scan(l.arg, &verbosity)) return -1 ; break ; - case 'a' : add = 1 ; if (del) return -1 ; break ; - case 'd' : del = 1 ; if (add) return -1 ; break ; + case 'v' : if (!uint0_scan(l.arg, &verbosity)) return 0 ; break ; + case 'a' : add = 1 ; if (del) return 0 ; break ; + case 'd' : del = 1 ; if (add) return 0 ; break ; case 's' : sch = 1 ; break ; - default : return -1 ; + default : return 0 ; } } argc -= l.ind ; argv += l.ind ; } - if (argc < 1) return -1 ; - + if (argc < 1) return 0 ; + + stralloc base = STRALLOC_ZERO ; + stralloc contents = STRALLOC_ZERO ; + tree = *argv ; treelen = strlen(tree) ; if (!set_ownersysdir(&base,owner)) { VERBO3 strerr_warnwu1sys("set owner directory") ; - return -1 ; + stralloc_free(&base) ; + stralloc_free(&contents) ; + return 0 ; } - /** /system/state */ - //base.len-- ; - char state[base.len + SS_SYSTEM_LEN + SS_STATE_LEN + 1] ; memcpy(state,base.s,base.len) ; memcpy(state + base.len,SS_SYSTEM,SS_SYSTEM_LEN) ; @@ -95,41 +86,35 @@ int tree_state(int argc, char const *const *argv) state[statelen] = 0 ; r = scan_mode(state,S_IFREG) ; - if (r < 0) { errno = EEXIST ; err = -1 ; goto out ; } + if (r == -1) { errno = EEXIST ; goto out ; } if (!r) { VERBO3 strerr_warnwu2sys("find: ",state) ; - { err = -1 ; goto out ; } + goto out ; } statesize = file_get_size(state) ; - r = openreadfileclose(state,&contents,statesize) ; if(!r) { VERBO3 strerr_warnwu2sys("open: ", state) ; - { err = -1 ; goto out ; } + goto out ; } - /** ensure that we have an empty line at the end of the string*/ - if (!stralloc_cats(&contents,"\n")) retstralloc(-1,"tree_registrer") ; - if (!stralloc_0(&contents)) retstralloc(-1,"tree_registrer") ; - if (!clean_val(&in,contents.s)) + if (contents.len) { - VERBO3 strerr_warnwu2x("clean: ",contents.s) ; - { err = -1 ; goto out ; } + if (!sastr_split_string_in_nline(&contents)) goto out ; } - if (add) { - if (!stra_cmp(&in,tree)) + if (sastr_cmp(&contents,tree) == -1) { fd = open_append(state) ; if (fd < 0) { VERBO3 strerr_warnwu2sys("open: ",state) ; - { err = -1 ; goto out ; } + goto out ; } r = write(fd, tree,treelen); r = write(fd, "\n",1); @@ -137,91 +122,92 @@ int tree_state(int argc, char const *const *argv) { VERBO3 strerr_warnwu5sys("write: ",state," with ", tree," as content") ; fd_close(fd) ; - { err = -1 ; goto out ; } + goto out ; } fd_close(fd) ; } + else + { + err = 2 ; + goto out ; + } } if (del) { - - if (stra_cmp(&in,tree)) + skip = sastr_cmp(&contents,tree) ; + if (skip >= 0) { - if (!stra_remove(&in,tree)) - { - VERBO3 strerr_warnwu4x("to remove: ",tree," in: ",state) ; - { err = -1 ; goto out ; } - } fd = open_trunc(state) ; if (fd < 0) { VERBO3 strerr_warnwu2sys("open_trunc ", state) ; - { err = -1 ; goto out ; } - }/* - fd = open_append(state) ; - if (fd < 0) - { - VERBO3 strerr_warnwu2sys("open: ",state) ; - { err = -1 ; goto out ; } - }*/ - + goto out ; + } + /*** replace it by write_file_unsafe*/ - for (unsigned int i = 0 ; i < genalloc_len(stralist,&in) ; i++) + for (;pos < contents.len ; pos += strlen(contents.s + pos) + 1) { - r = write(fd, gaistr(&in,i),gaistrlen(&in,i)); + if (pos == (size_t)skip) continue ; + char *name = contents.s + pos ; + size_t namelen = strlen(contents.s + pos) ; + r = write(fd, name,namelen); if (r < 0) { - VERBO3 strerr_warnwu5sys("write: ",state," with ", gaistr(&in,i)," as content") ; + VERBO3 strerr_warnwu5sys("write: ",state," with ", name," as content") ; fd_close(fd) ; - { err = -1 ; goto out ; } + goto out ; } r = write(fd, "\n",1); if (r < 0) { - VERBO3 strerr_warnwu5sys("write: ",state," with ", gaistr(&in,i)," as content") ; + VERBO3 strerr_warnwu5sys("write: ",state," with ", name," as content") ; fd_close(fd) ; - { err = -1 ; goto out ; } + goto out ; } } fd_close(fd) ; } + else + { + err = 2 ; + goto out ; + } } if (sch) { - if (stra_cmp(&in,tree)) + if (sastr_cmp(&contents,tree) >= 0) { err = 1 ; goto out ; } else { - err = 0 ; + err = 2 ; goto out ; } } - + err = 1 ; out: stralloc_free(&base) ; stralloc_free(&contents) ; - genalloc_deepfree(stralist,&in,stra_free) ; return err ; - } int tree_cmd_state(unsigned int verbosity,char const *cmd, char const *tree) { int r ; + size_t pos = 0 ; + stralloc opts = STRALLOC_ZERO ; - genalloc opts = GENALLOC_ZERO ; - - if (!clean_val(&opts,cmd)) + if (!sastr_clean_string(&opts,cmd)) { VERBO3 strerr_warnwu2x("clean: ",cmd) ; - return -1 ; + stralloc_free(&opts) ; + return 0 ; } - int newopts = 5 + genalloc_len(stralist,&opts) ; + int newopts = 5 + sastr_len(&opts) ; char const *newargv[newopts] ; unsigned int m = 0 ; char fmt[UINT_FMT] ; @@ -231,15 +217,15 @@ int tree_cmd_state(unsigned int verbosity,char const *cmd, char const *tree) newargv[m++] = "-v" ; newargv[m++] = fmt ; - for (unsigned int i = 0; i < genalloc_len(stralist,&opts); i++) - newargv[m++] = gaistr(&opts,i) ; - + for (;pos < opts.len; pos += strlen(opts.s + pos) + 1) + newargv[m++] = opts.s + pos ; + newargv[m++] = tree ; newargv[m++] = 0 ; r = tree_state(newopts,newargv) ; - genalloc_deepfree(stralist,&opts,stra_free) ; + stralloc_free(&opts) ; return r ; } diff --git a/src/lib66/tree_copy.c b/src/lib66/tree_copy.c index b5f61989bacff4caddb9ff7a5e0499a138dbf696..5e076b578271bfb9f7f572c6c27ba604563e9b13 100644 --- a/src/lib66/tree_copy.c +++ b/src/lib66/tree_copy.c @@ -16,7 +16,6 @@ #include <string.h> -#include <oblibs/string.h> #include <oblibs/directory.h> #include <oblibs/error2.h> @@ -24,8 +23,7 @@ #include <skalibs/djbunix.h> #include <66/constants.h> -#include <66/utils.h> -#include <stdio.h> + int tree_copy(stralloc *dir, char const *tree,char const *treename) { char *fdir = 0 ; diff --git a/src/lib66/tree_find_current.c b/src/lib66/tree_find_current.c index 7a5c8db6381fe818ed0f17ede80955616c6884af..05ae9a0221025d5e0263239c3dac02dc72502629 100644 --- a/src/lib66/tree_find_current.c +++ b/src/lib66/tree_find_current.c @@ -15,11 +15,12 @@ #include <66/utils.h> #include <sys/stat.h> +#include <sys/types.h> +#include <string.h> #include <oblibs/error2.h> #include <oblibs/types.h> -#include <skalibs/uint32.h> #include <skalibs/types.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> @@ -30,7 +31,7 @@ int tree_find_current(stralloc *tree, char const *base,uid_t owner) { ssize_t r ; size_t baselen = strlen(base) ; - char pack[256] ; + char pack[UID_FMT] ; uint32_pack(pack,owner) ; size_t packlen = uint_fmt(pack,owner) ; diff --git a/src/lib66/tree_get_permissions.c b/src/lib66/tree_get_permissions.c index 2cd08d2a1b8be907615b7ac08a19d8c2afc1240d..e0275272ca9ef3d031fec8a7adb5576c92f28a05 100644 --- a/src/lib66/tree_get_permissions.c +++ b/src/lib66/tree_get_permissions.c @@ -18,7 +18,6 @@ #include <sys/stat.h> #include <oblibs/error2.h> -#include <oblibs/directory.h> #include <oblibs/types.h> #include <skalibs/stralloc.h> @@ -32,16 +31,19 @@ int tree_get_permissions(char const *tree,uid_t owner) ssize_t r ; size_t treelen = strlen(tree) ; char pack[UID_FMT] ; - char tmp[treelen + SS_RULES_LEN + 1] ; - uint32_pack(pack,owner) ; - pack[uint_fmt(pack,owner)] = 0 ; + size_t packlen = uint_fmt(pack,owner) ; + pack[packlen] = 0 ; + + char tmp[treelen + SS_RULES_LEN + 1 + packlen + 1] ; memcpy(tmp,tree,treelen) ; memcpy(tmp + treelen,SS_RULES,SS_RULES_LEN) ; - tmp[treelen + SS_RULES_LEN] = 0 ; - - r = dir_search(tmp,pack,S_IFREG) ; + tmp[treelen + SS_RULES_LEN] = '/' ; + memcpy(tmp + treelen + SS_RULES_LEN + 1, pack,packlen) ; + tmp[treelen + SS_RULES_LEN + 1 + packlen] = 0 ; + + r = scan_mode(tmp,S_IFREG) ; if (r != 1) return 0 ; return 1 ; diff --git a/src/lib66/tree_sethome.c b/src/lib66/tree_sethome.c index bfcb8f069914f7a02ced54d3395c6a70b1bb68ce..129ed214159c60419b01165ff26a398fd4aeeeea 100644 --- a/src/lib66/tree_sethome.c +++ b/src/lib66/tree_sethome.c @@ -17,6 +17,7 @@ #include <string.h> #include <sys/stat.h> #include <errno.h> +#include <sys/types.h> #include <oblibs/types.h> #include <oblibs/error2.h> diff --git a/src/lib66/tree_setname.c b/src/lib66/tree_setname.c index 33230fef4fccbc332e41972a167ef493361c6970..02be80bb31577b8fb27db4273daeec1b724d57d0 100644 --- a/src/lib66/tree_setname.c +++ b/src/lib66/tree_setname.c @@ -14,10 +14,13 @@ #include <66/tree.h> -#include <stddef.h> +#include <string.h> +#include <sys/types.h>//ssize #include <oblibs/string.h> +#include <skalibs/stralloc.h> + char tree_setname(stralloc *sa,char const *tree) { size_t tlen = strlen(tree) ; diff --git a/src/lib66/tree_switch_current.c b/src/lib66/tree_switch_current.c index 1ef0c4df6081f61ff2b89c9b5ee159da8ce42371..fbc076d69ee39c66cbfa5c66700644c0c23c052f 100644 --- a/src/lib66/tree_switch_current.c +++ b/src/lib66/tree_switch_current.c @@ -16,7 +16,6 @@ #include <sys/types.h> #include <string.h> - #include <sys/stat.h> #include <oblibs/error2.h> @@ -39,36 +38,37 @@ int tree_switch_current(char const *base, char const *treename) size_t treelen = strlen(treename) ; size_t newlen ; size_t packlen ; - char dst[baselen + SS_TREE_CURRENT_LEN + treelen + 2 + 1] ; - struct stat st ; - packlen = uint_fmt(pack,MYUID) ; pack[packlen] = 0 ; - + char dst[baselen + SS_TREE_CURRENT_LEN + 1 + packlen + treelen + 2 + 1] ; + struct stat st ; + memcpy(dst,base,baselen) ; memcpy(dst + baselen,SS_SYSTEM,SS_SYSTEM_LEN) ; - dst[baselen + SS_SYSTEM_LEN] = 0 ; - - r = dir_search(dst,treename,S_IFDIR) ; + dst[baselen + SS_SYSTEM_LEN] = '/' ; + memcpy(dst + baselen + SS_SYSTEM_LEN + 1,treename,treelen) ; + dst[baselen + SS_SYSTEM_LEN + 1 + treelen] = 0 ; + + r = scan_mode(dst,S_IFDIR) ; if (r <= 0) return 0 ; memcpy(dst + baselen,SS_TREE_CURRENT,SS_TREE_CURRENT_LEN) ; - newlen = baselen + SS_TREE_CURRENT_LEN ; + dst[baselen + SS_TREE_CURRENT_LEN] = '/' ; + memcpy(dst + baselen + SS_TREE_CURRENT_LEN + 1, pack, packlen) ; + newlen = baselen + SS_TREE_CURRENT_LEN + 1 + packlen ; dst[newlen] = 0 ; - r = dir_search(dst,pack,S_IFDIR) ; + r = scan_mode(dst,S_IFDIR) ; if (!r){ - if (!dir_create_under(dst,pack,0755)) return 0 ; + if (!dir_create_parent(dst,0755)) return 0 ; } - if(r < 0) return 0 ; + if(r == -1) return 0 ; - char current[newlen + 1 + packlen + 1 + SS_TREE_CURRENT_LEN + 1] ; + char current[newlen + 1 + SS_TREE_CURRENT_LEN + 1] ; memcpy(current,dst,newlen) ; current[newlen] = '/' ; - memcpy(current + newlen + 1, pack,packlen) ; - current[newlen + 1 + packlen] = '/' ; - memcpy(current + newlen + 1 + packlen + 1, SS_TREE_CURRENT, SS_TREE_CURRENT_LEN) ; - current[newlen + 1 + packlen + 1 + SS_TREE_CURRENT_LEN] = 0 ; + memcpy(current + newlen + 1, SS_TREE_CURRENT, SS_TREE_CURRENT_LEN) ; + current[newlen + 1 + SS_TREE_CURRENT_LEN] = 0 ; memcpy(dst + baselen,SS_SYSTEM,SS_SYSTEM_LEN) ; memcpy(dst + baselen + SS_SYSTEM_LEN,"/",1) ;