Skip to content
Snippets Groups Projects
Commit ab33ff99 authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

split extra-tools

parent 9d412a73
No related branches found
No related tags found
No related merge requests found
Showing
with 1 addition and 1265 deletions
<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>
<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/&ltpid&gt/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&nbsp;</tt>&nbsp;: prints this help. </li>
<li>
<tt>-x&nbsp;</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&nbsp;<em>delim</em>&nbsp;</tt>&nbsp;: 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/&ltpid&gt/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&mdash;see <tt>proc(5)</tt> for futher informations.</p>
</body>
</html>
<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&nbsp;</tt>&nbsp;: prints this help. </li>
<li>
<tt>-x&nbsp;</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&nbsp;<em>mode</em>&nbsp;</tt>&nbsp;: create <em>dir</em> with mode <em>mode</em> if it doesn't exist yet. Default is 0755.
</li>
</ul>
</body>
</html>
<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>&nbsp;&nbsp;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>
<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&nbsp;</tt>&nbsp;: prints this help. </li>
<li>
<tt>-m&nbsp;<em>mode</em>&nbsp;</tt>&nbsp;: create <em>dir</em> with mode <em>mode</em> if it doesn't exist yet. Default is 0755.
</li>
</ul>
</body>
</html>
<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&nbsp;</tt>&nbsp;: 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>
<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>
<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>
...@@ -81,7 +81,6 @@ ...@@ -81,7 +81,6 @@
<li><a href="66-hpr.html"><tt>66-hpr</tt></a></li> <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-shutdownd.html"><tt>66-shutdownd</tt></a></li>
<li><a href="66-parser.html"><tt>66-parser</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> </ul>
<h3> User tools </h3> <h3> User tools </h3>
...@@ -102,15 +101,8 @@ ...@@ -102,15 +101,8 @@
<h3> Extra tools </h3> <h3> Extra tools </h3>
<ul> <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-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> </ul>
<h2> Why is 66 necessary? </h2> <h2> Why is 66 necessary? </h2>
......
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)
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&mdash;see *proc*(5) for futher informations.
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.
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'.
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
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 } }
```
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)
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)
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
```
/*
* 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) ;
}
/*
* 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 ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment