about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-03-01 13:56:46 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-03-01 13:56:46 +0000
commit3d4285c7580f3fda1c66fa9ab3c0463d9edb6449 (patch)
treeba248bef99aa2564078d3dc1d290946ae5ee57e9
parentfe1f70d5f729e331facf481ec45cc1c64e095d85 (diff)
downloads6-portable-utils-3d4285c7580f3fda1c66fa9ab3c0463d9edb6449.tar.gz
s6-portable-utils-3d4285c7580f3fda1c66fa9ab3c0463d9edb6449.tar.xz
s6-portable-utils-3d4285c7580f3fda1c66fa9ab3c0463d9edb6449.zip
- New command: dumpenv
 - Version: 2.0.3.0 rc
-rw-r--r--doc/index.html3
-rw-r--r--doc/s6-dumpenv.html55
-rw-r--r--doc/upgrade.html6
-rw-r--r--package/deps.mak3
-rw-r--r--package/info2
-rw-r--r--package/modes1
-rw-r--r--package/targets.mak1
-rw-r--r--src/skaembutils/deps-exe/s6-dumpenv1
-rw-r--r--src/skaembutils/s6-dumpenv.c63
9 files changed, 133 insertions, 2 deletions
diff --git a/doc/index.html b/doc/index.html
index 95b4372..6f18572 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -76,7 +76,7 @@ library. </li>
 
 <ul>
  <li> The current released version of s6-portable-utils is
-<a href="s6-portable-utils-2.0.2.0.tar.gz">2.0.2.0</a>. </li>
+<a href="s6-portable-utils-2.0.3.0.tar.gz">2.0.3.0</a>. </li>
  <li> Alternatively, you can checkout a copy of the s6-portable-utils git repository:
 <pre> git clone git://git.skarnet.org/s6-portable-utils </pre> </li>
 </ul>
@@ -113,6 +113,7 @@ the previous versions of s6-portable-utils and the current one. </li>
  <li> The <a href="s6-clock.html"><tt>s6-clock</tt></a> program </li>
  <li> The <a href="s6-cut.html"><tt>s6-cut</tt></a> program </li>
  <li> The <a href="s6-dirname.html"><tt>s6-dirname</tt></a> program </li>
+ <li> The <a href="s6-dumpenv.html"><tt>s6-dumpenv</tt></a> program </li>
  <li> The <a href="s6-echo.html"><tt>s6-echo</tt></a> program </li>
  <li> The <a href="s6-env.html"><tt>s6-env</tt></a> program </li>
  <li> The <a href="s6-expr.html"><tt>s6-expr</tt></a> program </li>
diff --git a/doc/s6-dumpenv.html b/doc/s6-dumpenv.html
new file mode 100644
index 0000000..7de65ae
--- /dev/null
+++ b/doc/s6-dumpenv.html
@@ -0,0 +1,55 @@
+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+    <meta http-equiv="Content-Language" content="en" />
+    <title>s6-portable-utils: the s6-dumpenv program</title>
+    <meta name="Description" content="s6-portable-utils: the s6-dumpenv program" />
+    <meta name="Keywords" content="s6-portable-utils command s6-dumpenv environment variables" />
+    <!-- <link rel="stylesheet" type="text/css" href="http://skarnet.org/default.css" /> -->
+  </head>
+<body>
+
+<p>
+<a href="index.html">s6-portable-utils</a><br />
+<a href="http://skarnet.org/software/">Software</a><br />
+<a href="http://skarnet.org/">skarnet.org</a>
+</p>
+
+<h1> The <tt>s6-dumpenv</tt> program </h1>
+
+<p>
+ s6-dumpenv stores its environment variables into a directory.
+</p>
+
+<h2> Interface </h2>
+
+<pre>
+     s6-dumpenv [ -m <em>mode</em> ] <em>dir</em>
+</pre>
+
+<ul>
+ <li> s6-dumpenv creates the directory <em>dir</em> if it does not exist
+yet. </li>
+ <li> For every environment variable <em>x</em> with value <em>y</em>
+that it has, it creates a file <em>dir</em>/<em>x</em> containing
+<em>y</em>. </li>
+ <li> It then exits 0. </li>
+</ul>
+
+<h2> Options </h2>
+
+<ul>
+ <li> <tt>-m</tt>&nbsp;<em>mode</em>&nbsp;: create <em>dir</em> with
+mode <em>mode</em> if it doesn't exist yet. Default is 0755. </li>
+</ul>
+
+<h2> Notes </h2>
+
+<ul>
+ <li> A program <em>prog</em> can be run with the environment in dir
+by using <tt><a href="http://skarnet.org/software/s6/s6-envdir.html">s6-envdir</a>
+-fn -- <em>dir</em> <em>prog</em></tt>. </li>
+</ul>
+
+</body>
+</html>
diff --git a/doc/upgrade.html b/doc/upgrade.html
index 26bb1a8..1b5cdbb 100644
--- a/doc/upgrade.html
+++ b/doc/upgrade.html
@@ -17,6 +17,12 @@
 
 <h1> What has changed in s6-portable-utils </h1>
 
+<h2> in 2.0.3.0 </h2>
+
+<ul>
+ <li> New command: <a href="s6-dumpenv.html">s6-dumpenv</a>. </li>
+</ul>
+
 <h2> in 2.0.2.0 </h2>
 
 <ul>
diff --git a/package/deps.mak b/package/deps.mak
index 8ea0be0..d5b641d 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -9,6 +9,7 @@ src/skaembutils/s6-chown.o src/skaembutils/s6-chown.lo: src/skaembutils/s6-chown
 src/skaembutils/s6-clock.o src/skaembutils/s6-clock.lo: src/skaembutils/s6-clock.c
 src/skaembutils/s6-cut.o src/skaembutils/s6-cut.lo: src/skaembutils/s6-cut.c
 src/skaembutils/s6-dirname.o src/skaembutils/s6-dirname.lo: src/skaembutils/s6-dirname.c
+src/skaembutils/s6-dumpenv.o src/skaembutils/s6-dumpenv.lo: src/skaembutils/s6-dumpenv.c
 src/skaembutils/s6-echo.o src/skaembutils/s6-echo.lo: src/skaembutils/s6-echo.c
 src/skaembutils/s6-env.o src/skaembutils/s6-env.lo: src/skaembutils/s6-env.c src/include/s6-portable-utils/config.h
 src/skaembutils/s6-expr.o src/skaembutils/s6-expr.lo: src/skaembutils/s6-expr.c
@@ -58,6 +59,8 @@ s6-cut: private EXTRA_LIBS :=
 s6-cut: src/skaembutils/s6-cut.o -lskarnet
 s6-dirname: private EXTRA_LIBS :=
 s6-dirname: src/skaembutils/s6-dirname.o -lskarnet
+s6-dumpenv: private EXTRA_LIBS :=
+s6-dumpenv: src/skaembutils/s6-dumpenv.o -lskarnet
 s6-echo: private EXTRA_LIBS :=
 s6-echo: src/skaembutils/s6-echo.o -lskarnet
 s6-env: private EXTRA_LIBS :=
diff --git a/package/info b/package/info
index 150bf47..5eb0354 100644
--- a/package/info
+++ b/package/info
@@ -1,4 +1,4 @@
 package=s6-portable-utils
-version=2.0.2.0
+version=2.0.3.0
 category=admin
 package_macro_name=S6_PORTABLE_UTILS
diff --git a/package/modes b/package/modes
index 2704081..325eb60 100644
--- a/package/modes
+++ b/package/modes
@@ -5,6 +5,7 @@ s6-chown		0755
 s6-clock		0755
 s6-cut			0755
 s6-dirname		0755
+s6-dumpenv		0755
 s6-echo			0755
 s6-env			0755
 s6-expr			0755
diff --git a/package/targets.mak b/package/targets.mak
index ffdd6f0..f7b3869 100644
--- a/package/targets.mak
+++ b/package/targets.mak
@@ -6,6 +6,7 @@ s6-chown \
 s6-clock \
 s6-cut \
 s6-dirname \
+s6-dumpenv \
 s6-echo \
 s6-env \
 s6-expr \
diff --git a/src/skaembutils/deps-exe/s6-dumpenv b/src/skaembutils/deps-exe/s6-dumpenv
new file mode 100644
index 0000000..e7187fe
--- /dev/null
+++ b/src/skaembutils/deps-exe/s6-dumpenv
@@ -0,0 +1 @@
+-lskarnet
diff --git a/src/skaembutils/s6-dumpenv.c b/src/skaembutils/s6-dumpenv.c
new file mode 100644
index 0000000..4bed6c8
--- /dev/null
+++ b/src/skaembutils/s6-dumpenv.c
@@ -0,0 +1,63 @@
+/* ISC license. */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <skalibs/uint.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/djbunix.h>
+
+#define USAGE "s6-dumpenv [ -m mode ] envdir"
+#define dieusage() strerr_dieusage(100, USAGE)
+
+int main (int argc, char const *const *argv, char const *const *envp)
+{
+  mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ;
+  unsigned int dirlen ;
+
+  PROG = "s6-printenv" ;
+  {
+    subgetopt_t l = SUBGETOPT_ZERO ;
+    for (;;)
+    {
+      register int opt = subgetopt_r(argc, argv, "m:", &l) ;
+      if (opt == -1) break ;
+      switch (opt)
+      {
+        case 'm' : if (!uint0_oscan(l.arg, &mode)) dieusage() ; break ;
+        default : dieusage() ;
+      }
+    }
+    argc -= l.ind ; argv += l.ind ;
+  }
+  if (!argc) dieusage() ;
+
+  if (mkdir(argv[0], mode) < 0)
+  {
+    struct stat st ;
+    if (errno != EEXIST) strerr_diefu2sys(111, "mkdir ", argv[0]) ;
+    if (stat(argv[0], &st) < 0)
+      strerr_diefu2sys(111, "stat ", argv[0]) ;
+    if (!S_ISDIR(st.st_mode))
+    {
+      errno = ENOTDIR ;
+      strerr_diefu2sys(111, "mkdir ", argv[0]) ;
+    }
+  }
+  dirlen = str_len(argv[0]) ;
+    
+  for (; *envp ; envp++)
+  {
+    unsigned int varlen = str_chr(*envp, '=') ;
+    char fn[dirlen + varlen + 2] ;
+    byte_copy(fn, dirlen, argv[0]) ;
+    fn[dirlen] = '/' ;
+    byte_copy(fn + dirlen + 1, varlen, *envp) ;
+    fn[dirlen + 1 + varlen] = 0 ;
+    if (!openwritenclose_suffix(fn, *envp + varlen + 1, str_len(*envp + varlen + 1), "=.tmp"))
+      strerr_diefu2sys(111, "open ", fn) ;
+  }
+  return 0 ;
+}