diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-02-11 03:12:21 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-02-11 03:12:21 +0000 |
commit | 774654ad56fc9304e4a064232760835c7a2a6c13 (patch) | |
tree | 3f539521073866497ff0370d8a6464c9356cadb4 /src/skaembutils/s6-dumpenv.c | |
parent | 790c8681d3451b61a536871dad234fc294796fd8 (diff) | |
download | s6-portable-utils-774654ad56fc9304e4a064232760835c7a2a6c13.tar.xz |
Add multicall configuration
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/skaembutils/s6-dumpenv.c')
-rw-r--r-- | src/skaembutils/s6-dumpenv.c | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/src/skaembutils/s6-dumpenv.c b/src/skaembutils/s6-dumpenv.c deleted file mode 100644 index 4b79170..0000000 --- a/src/skaembutils/s6-dumpenv.c +++ /dev/null @@ -1,72 +0,0 @@ -/* ISC license. */ - -#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/strerr.h> -#include <skalibs/djbunix.h> - -#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, "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() ; - } - } - 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 = strlen(argv[0]) ; - - 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 (!openwritevnclose_suffix(fn, v, 1 + chomp, "=.tmp")) - strerr_diefu2sys(111, "open ", fn) ; - } - return 0 ; -} |