From 3d9f4c786ee1bce0ded8871f405b11e7eb62df13 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Tue, 12 Feb 2019 15:10:40 +0000 Subject: Add envfile; prepare for 2.5.1.0 --- COPYING | 2 +- INSTALL | 2 +- NEWS | 7 ++++ doc/envfile.html | 95 +++++++++++++++++++++++++++++++++++++++++++ doc/index.html | 5 ++- doc/upgrade.html | 7 ++++ package/deps.mak | 3 ++ package/info | 2 +- package/modes | 1 + package/targets.mak | 1 + src/execline/deps-exe/envfile | 1 + src/execline/envfile.c | 93 ++++++++++++++++++++++++++++++++++++++++++ 12 files changed, 214 insertions(+), 5 deletions(-) create mode 100644 doc/envfile.html create mode 100644 src/execline/deps-exe/envfile create mode 100644 src/execline/envfile.c diff --git a/COPYING b/COPYING index 1629e84..f019bc7 100644 --- a/COPYING +++ b/COPYING @@ -1,4 +1,4 @@ -Copyright (c) 2011-2018 Laurent Bercot +Copyright (c) 2011-2019 Laurent Bercot Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/INSTALL b/INSTALL index 206a376..f2d9caa 100644 --- a/INSTALL +++ b/INSTALL @@ -6,7 +6,7 @@ Build Instructions - A POSIX-compliant C development environment - GNU make version 3.81 or later - - skalibs version 2.7.0.0 or later: http://skarnet.org/software/skalibs/ + - skalibs version 2.8.0.0 or later: http://skarnet.org/software/skalibs/ This software will run on any operating system that implements POSIX.1-2008, available at: diff --git a/NEWS b/NEWS index 42c8dff..17647c5 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,12 @@ Changelog for execline. +In 2.5.1.0 +---------- + + - Bugfixes. + - New command: envfile. + + In 2.5.0.1 ---------- diff --git a/doc/envfile.html b/doc/envfile.html new file mode 100644 index 0000000..49b88f9 --- /dev/null +++ b/doc/envfile.html @@ -0,0 +1,95 @@ + + + + + + execline: the envfile program + + + + + + +

+execline
+Software
+skarnet.org +

+ +

The envfile program

+ +

+envfile reads a file containing variable assignments, +adds the variables to the environment, then executes a program. +

+ +

Interface

+ +
+     envfile file prog...
+
+ +

+envfile reads file and adds the key-value pairs +defined in file to the environment. Then it +execs into prog..., i.e. the rest of its command line, +with the modified environment. +

+ +

Exit codes

+ +
    +
  • 1: syntax error in file
  • +
  • 100: wrong usage
  • +
  • 111: system call failed
  • +
  • 126: execve() on prog failed (unknown reason)
  • +
  • 127: execve() on prog failed (prog could not be found)
  • +
+ +

+ 0 is not listed because on success, envfile does not exit: +it execs into prog. +

+ +

File syntax

+ +

+ file is a text file containing lines of the form key = value. +Whitespace is permitted before and after key, and before or after value, +but key or value can never contain whitespace. No quoting +is possible. +

+ +

+ Empty lines, or lines containing only whitespace, are ignored. +Lines beginning with # (possibly after some whitespace) +are ignored (and typically used for comments). +Comments are also possible at the end of lines: +key = value # comment is a valid line. Note that there +must be whitespace between value and # +in this case (else # is just read as a part of value). +

+ +

+ If value is empty, key is still +added to the environment, with an empty value. If you do not want +key to be added to the environment at all, comment out the line. +envfile does not offer a way to remove variables from +the environment. +

+ +

Notes

+ +
    +
  • If file is - then envfile reads +and parses its standard input instead. To read a file literally named +-, you can use ./- for instance.
  • +
  • The variables and values that can be defined with envfile +are purposefully restricted in order to keep the parsing extremely simple. +If you need fancy values, for instance values that contain whitespace or +a newline, you should use an envdir instead: see +s6-envdir.
  • +
+ + + diff --git a/doc/index.html b/doc/index.html index 9a68d5f..3efad3a 100644 --- a/doc/index.html +++ b/doc/index.html @@ -51,7 +51,7 @@ shell's syntax, and has no security issues.
  • A POSIX-compliant system with a standard C development environment
  • GNU make, version 3.81 or later.
  • skalibs version -2.7.0.0 or later. It's a build-time requirement. It's also a run-time +2.8.0.0 or later. It's a build-time requirement. It's also a run-time requirement if you link against the shared version of the skalibs library.
  • @@ -66,7 +66,7 @@ library.

    Download

      -
    • The current released version of execline is 2.5.0.1.
    • +
    • The current released version of execline is 2.5.1.0.
    • Alternatively, you can checkout a copy of the execline git repository: @@ -128,6 +128,7 @@ to your installation: the shebang lines for your system might be something like
    • The cd program
    • The umask program
    • The emptyenv program
    • +
    • The envfile program
    • The export program
    • The unexport program
    • The fdclose program
    • diff --git a/doc/upgrade.html b/doc/upgrade.html index 5eed0d8..80c5dea 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -18,6 +18,13 @@

      What has changed in execline

      +

      in 2.5.1.0

      + +
        +
      • skalibs dependency bumped to 2.8.0.0
      • +
      • New command: envfile.
      • +
      +

      in 2.5.0.1

        diff --git a/package/deps.mak b/package/deps.mak index db14ec6..e058e9f 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -11,6 +11,7 @@ src/execline/elgetopt.o src/execline/elgetopt.lo: src/execline/elgetopt.c src/in src/execline/elgetpositionals.o src/execline/elgetpositionals.lo: src/execline/elgetpositionals.c src/include-local/exlsn.h src/execline/elglob.o src/execline/elglob.lo: src/execline/elglob.c src/include-local/exlsn.h src/execline/emptyenv.o src/execline/emptyenv.lo: src/execline/emptyenv.c src/include/execline/execline.h +src/execline/envfile.o src/execline/envfile.lo: src/execline/envfile.c src/execline/exec.o src/execline/exec.lo: src/execline/exec.c src/execline/execlineb.o src/execline/execlineb.lo: src/execline/execlineb.c src/include/execline/execline.h src/include-local/exlsn.h src/execline/exit.o src/execline/exit.lo: src/execline/exit.c @@ -89,6 +90,8 @@ elglob: EXTRA_LIBS := elglob: src/execline/elglob.o ${LIBEXECLINE} -lskarnet emptyenv: EXTRA_LIBS := emptyenv: src/execline/emptyenv.o ${LIBEXECLINE} -lskarnet +envfile: EXTRA_LIBS := +envfile: src/execline/envfile.o -lskarnet exec: EXTRA_LIBS := exec: src/execline/exec.o -lskarnet execlineb: EXTRA_LIBS := diff --git a/package/info b/package/info index 7325953..e66a0ee 100644 --- a/package/info +++ b/package/info @@ -1,4 +1,4 @@ package=execline -version=2.5.0.1 +version=2.5.1.0 category=admin package_macro_name=EXECLINE diff --git a/package/modes b/package/modes index 76ae052..7852d06 100644 --- a/package/modes +++ b/package/modes @@ -9,6 +9,7 @@ elglob 0755 multidefine 0755 multisubstitute 0755 emptyenv 0755 +envfile 0755 exec 0755 exit 0755 execlineb 0755 diff --git a/package/targets.mak b/package/targets.mak index 678393f..c076fa3 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -8,6 +8,7 @@ elgetopt \ elgetpositionals \ elglob \ emptyenv \ +envfile \ exec \ execlineb \ exit \ diff --git a/src/execline/deps-exe/envfile b/src/execline/deps-exe/envfile new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/execline/deps-exe/envfile @@ -0,0 +1 @@ +-lskarnet diff --git a/src/execline/envfile.c b/src/execline/envfile.c new file mode 100644 index 0000000..638b182 --- /dev/null +++ b/src/execline/envfile.c @@ -0,0 +1,93 @@ +/* ISC license. */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#define USAGE "envfile file prog..." +#define dieusage() strerr_dieusage(100, USAGE) +#define dienomem() strerr_diefu1sys(111, "stralloc_catb") + +static inline uint8_t cclass (char c) +{ + switch (c) + { + case 0 : return 0 ; + case '#' : return 1 ; + case '\n' : return 2 ; + case '=' : return 3 ; + case ' ' : + case '\t' : + case '\f' : + case '\r' : return 4 ; + default : return 5 ; + } +} + +static inline char next (char const *file, buffer *b) +{ + char c ; + ssize_t r = buffer_get(b, &c, 1) ; + if (r < 0) strerr_diefu2sys(111, "read from ", file) ; + if (!r) c = 0 ; + return c ; +} + +static inline void parse_config (char const *file, buffer *b, stralloc *modif) +{ + static uint8_t const table[7][6] = + { + { 0x07, 0x01, 0x80, 0x08, 0x00, 0x22 }, + { 0x07, 0x01, 0x80, 0x01, 0x01, 0x01 }, + { 0x08, 0x08, 0x08, 0x24, 0x03, 0x22 }, + { 0x08, 0x08, 0x08, 0x24, 0x03, 0x08 }, + { 0x47, 0x41, 0xc0, 0x25, 0x04, 0x25 }, + { 0x47, 0x41, 0xc0, 0x25, 0x46, 0x25 }, + { 0x07, 0x01, 0x80, 0x08, 0x06, 0x08 } + } ; + unsigned int line = 1 ; + uint8_t state = 0 ; + while (state < 7) + { + char c = next(file, b) ; + uint8_t what = table[state][cclass(c)] ; + state = what & 0x0f ; + if (what & 0x20) + if (!stralloc_catb(modif, &c, 1)) dienomem() ; + if (what & 0x40) + if (!stralloc_0(modif)) dienomem() ; + if (what & 0x80) line++ ; + } + if (state > 7) + { + char fmt[UINT_FMT] ; + fmt[uint_fmt(fmt, line)] = 0 ; + strerr_dief4x(1, "syntax error line ", fmt, " while parsing ", file) ; + } +} + +int main (int argc, char const *const *argv, char const *const *envp) +{ + stralloc modif = STRALLOC_ZERO ; + PROG = "envfile" ; + if (argc < 3) dieusage() ; + if (!strcmp(argv[1], "-")) + parse_config("standard input", buffer_0, &modif) ; + else + { + buffer b ; + char buf[BUFFER_INSIZE] ; + int fd = open_readb(argv[1]) ; + if (fd == -1) strerr_diefu2sys(111, "open ", argv[1]) ; + buffer_init(&b, &buffer_read, fd, buf, BUFFER_INSIZE) ; + parse_config(argv[1], &b, &modif) ; + fd_close(fd) ; + } + xpathexec_r(argv + 2, envp, env_len(envp), modif.s, modif.len) ; +} -- cgit v1.3.1