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/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-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-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/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-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 e25e157e5b437887daf1cd5a5675f86440db6e37..0000000000000000000000000000000000000000 --- a/src/extra-tools/deps-exe/execl-envfile +++ /dev/null @@ -1,6 +0,0 @@ -${LIB66} -${LIBEXECLINE} --loblibs --lexecline --lskarnet - diff --git a/src/extra-tools/deps-exe/execl-subuidgid b/src/extra-tools/deps-exe/execl-subuidgid deleted file mode 100644 index 84a128c2c444222aa2d2803ee5682450abb82aa8..0000000000000000000000000000000000000000 --- a/src/extra-tools/deps-exe/execl-subuidgid +++ /dev/null @@ -1,5 +0,0 @@ -${LIB66} --loblibs --lexecline --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 682f6d9b8b0d20426cc21d04aeba071d6cb66ee5..0000000000000000000000000000000000000000 --- a/src/extra-tools/execl-envfile.c +++ /dev/null @@ -1,226 +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/directory.h> -#include <oblibs/files.h> -#include <oblibs/environ.h> -#include <oblibs/sastr.h> - -#include <skalibs/bytestr.h> -#include <skalibs/stralloc.h> -#include <skalibs/env.h> -#include <skalibs/djbunix.h> -#include <skalibs/env.h> -#include <skalibs/sgetopt.h> - -#include <execline/execline.h> - -#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") ; -} - -void clean_n_unexport(stralloc *modifs, stralloc *dst, stralloc *src) -{ - if (!environ_clean_envfile(modifs,src)) strerr_diefu2sys(111,"prepare modified environment of: ",src->s) ; - if (!sastr_split_string_in_nline(modifs)) strerr_diefu2sys(111,"build environment line of: ",src->s) ; ; - if (!stralloc_cats(dst,src->s)) exitstralloc("clean_n_unexport") ; -} - -int main (int argc, char const *const *argv, char const *const *envp) -{ - int r = 0, unexport = 0, insist = 1, nfile = 0, nvar = 0 ; - size_t pos = 0, pathlen = 0 ; - char const *path = 0, *file = 0 ; - char tpath[MAXENV + 1], tfile[MAXENV+1] ; - stralloc src = STRALLOC_ZERO ; - stralloc modifs = STRALLOC_ZERO ; - stralloc dst = STRALLOC_ZERO ; - stralloc toparse = STRALLOC_ZERO ; - stralloc key = STRALLOC_ZERO ; - stralloc val = STRALLOC_ZERO ; - - exlsn_t info = EXLSN_ZERO ; - - PROG = "execl-envfile" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - - for (;;) - { - int opt = subgetopt_r(argc,argv, "hlf:", &l) ; - if (opt == -1) break ; - 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 && insist) strerr_diefu2sys(111,"find: ",path) ; - if (r < 0) - { - r = scan_mode(path,S_IFDIR) ; - if (!r && insist) 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 = sastr_dir_get(&toparse,path,"",S_IFREG) ; - if (!r && insist) strerr_diefu2sys(111,"get file from: ",path) ; - else if ((!r && !insist) || !toparse.len) - { - xpathexec_run(argv[0],argv,envp) ; - } - if (file) - { - ssize_t r = sastr_cmp(&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) ; - clean_n_unexport(&modifs,&dst,&src) ; - } - else - { - for (;pos < toparse.len; pos += strlen(toparse.s + pos) + 1) - { - nfile++; - src.len = 0 ; - if (nfile > MAXFILE) strerr_dief2x(111,"to many file to parse in: ",path) ; - if (!file_readputsa(&src,path,toparse.s+pos)) strerr_diefu4sys(111,"read file: ",path,"/",toparse.s+pos) ; - clean_n_unexport(&modifs,&dst,&src) ; - nvar = environ_get_num_of_line(&src) ; - if (nvar == -1) strerr_diefu4sys(111,"get number of line of:",path,"/",toparse.s+pos) ; - if (nvar > MAXVAR) strerr_dief4x(111,"to many variables in file: ",path,"/",toparse.s+pos) ; - } - } - 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") ; - - if (!sastr_split_string_in_nline(&dst)) strerr_diefu1x(111,"split line") ; - pos = 0 ; - while (pos < dst.len) - { - unexport = 0 ; - key.len = val.len = 0 ; - if (!stralloc_copy(&key,&dst) || - !stralloc_copy(&val,&dst)) retstralloc(111,"main") ; - - if (!environ_get_key_nclean(&key,&pos)) strerr_diefu2x(111,"get key from line: ",key.s) ; - pos-- ;// retrieve the '=' character - if (!environ_get_val(&val,&pos)) strerr_diefu2x(111,"get value from line: ",val.s) ; - - char *uval = val.s ; - if (val.s[0] == VAR_UNEXPORT) - { - uval = val.s+1 ; - unexport = 1 ; - } - if(sastr_cmp(&info.vars,key.s) == -1) - if (!environ_substitute(key.s,uval,&info,newenv,unexport)) - strerr_diefu4x(111,"substitute value of: ",key.s," by: ",uval) ; - } - stralloc_free(&key) ; - stralloc_free(&val) ; - stralloc_free(&dst) ; - stralloc_free(&modifs) ; - - 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 50a35602c0c9fe284dc2e8eb0a94349a067e68c1..0000000000000000000000000000000000000000 --- a/src/extra-tools/execl-subuidgid.c +++ /dev/null @@ -1,142 +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 <errno.h> -#include <pwd.h> - -#include <oblibs/error2.h> -#include <oblibs/environ.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> - -#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") ; -} - -/** Implement again this function coming from - * 66. This is avoid the dependency from it*/ -static int youruid(uid_t *passto,char const *owner) -{ - int e ; - e = errno ; - errno = 0 ; - struct passwd *st ; - if (!(st = getpwnam(owner)) || errno) - { - if (!errno) errno = EINVAL ; - return 0 ; - } - *passto = st->pw_uid ; - errno = e ; - return 1 ; -} - -static int yourgid(gid_t *passto,uid_t owner) -{ - int e ; - e = errno ; - errno = 0 ; - struct passwd *st ; - if (!(st = getpwuid(owner)) || errno) - { - if (!errno) errno = EINVAL ; - return 0 ; - } - *passto = st->pw_gid ; - errno = e ; - return 1 ; -} - -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 (!environ_add_key_val("UID",cuid,&info)) strerr_diefu1sys(111,"set UID") ; - if (!environ_add_key_val("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 ; -}