summaryrefslogtreecommitdiff
path: root/src/skaembutils/s6-dumpenv.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2022-02-27 02:52:20 +0000
committerLaurent Bercot <ska@appnovation.com>2022-02-27 02:52:20 +0000
commita80a1304ff86b8cf493265696d517aea2cf7a703 (patch)
tree8368824fc484acc7fdb68b281f56c1e6966d46b3 /src/skaembutils/s6-dumpenv.c
parent35c2366d1f09bb2805e3edcdff9966f7d40d14b0 (diff)
downloads6-portable-utils-a80a1304ff86b8cf493265696d517aea2cf7a703.tar.xz
Prepare for 2.2.4.0; add -N option to s6-dumpenv
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/skaembutils/s6-dumpenv.c')
-rw-r--r--src/skaembutils/s6-dumpenv.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/skaembutils/s6-dumpenv.c b/src/skaembutils/s6-dumpenv.c
index 87950d0..53d9f84 100644
--- a/src/skaembutils/s6-dumpenv.c
+++ b/src/skaembutils/s6-dumpenv.c
@@ -3,29 +3,33 @@
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
+#include <sys/uio.h>
+
#include <skalibs/types.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 USAGE "s6-dumpenv [ -N | -n ] [ -m mode ] envdir"
#define dieusage() strerr_dieusage(100, USAGE)
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 ;
+ int chomp = 0 ;
size_t dirlen ;
-
PROG = "s6-dumpenv" ;
{
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "m:", &l) ;
+ int opt = subgetopt_r(argc, argv, "nNm:", &l) ;
if (opt == -1) break ;
switch (opt)
{
+ case 'n' : chomp = 0 ; break ;
+ case 'N' : chomp = 1 ; break ;
case 'm' : if (!uint0_oscan(l.arg, &mode)) dieusage() ; break ;
default : dieusage() ;
}
@@ -51,12 +55,17 @@ int main (int argc, char const *const *argv, char const *const *envp)
for (; *envp ; envp++)
{
size_t varlen = str_chr(*envp, '=') ;
+ struct iovec const v[2] =
+ {
+ { .iov_base = (char *)*envp + varlen + 1, .iov_len = strlen(*envp + varlen + 1) },
+ { .iov_base = "\n", .iov_len = 1 }
+ } ;
char fn[dirlen + varlen + 2] ;
memcpy(fn, argv[0], dirlen) ;
fn[dirlen] = '/' ;
memcpy(fn + dirlen + 1, *envp, varlen) ;
fn[dirlen + 1 + varlen] = 0 ;
- if (!openwritenclose_suffix(fn, *envp + varlen + 1, strlen(*envp + varlen + 1), "=.tmp"))
+ if (!openwritevnclose_suffix(fn, v, 1 + chomp, "=.tmp"))
strerr_diefu2sys(111, "open ", fn) ;
}
return 0 ;