Module lib

Configi standard library.

Lua extensions and some unix utilities. Depends on cimicida and Luaposix.

VENDOR= lib cimicida
VENDOR_C= posix

Functions

write(fd, buf)
Write to a file descriptor. Wrapper to luaposix unistd.write.

Parameters:

  • fd int file descriptor
  • buf string string to write

Returns:

    true if successfully written.
ret_path(path)
Checks the existence of a given path.

Parameters:

  • path string the path to check for

Returns:

    string the path if path exists.
bin_path(bin)
Deduce the complete path name of an executable. Only checks standard locations.

Parameters:

  • bin string executable name

Returns:

    string full path name
exec(args)
Execute a file. The sequence part of args are the arguments passed to the executable
The dictionary part of args has options and override. See the following.

Parameters:

  • args
    • _bin override path to binary
    • _env environment variables
    • _cwd current working directory
    • _stdin string as standard input
    • _stdout path to file as standard output
    • _stderr path to file as standard error
    • _return_code return the exit code instead of boolean true
    • _ignore_error always return boolean true

Returns:

  1. bool true if no errors, nil otherwise
  2. table result
  3. result.stdout (table) sequence of stdout lines
  4. result.stderr (table) sequence of stderr lines
  5. result.pid (int) pid of terminated executable, if successful; nil otherwise
  6. result.status (string) status: "exited", "killed" or "stopped"; otherwise, an error message
  7. result.code (int) exit status, or signal number responsible for "killed" or "stopped"; otherwise, an errnum
  8. result.bin (string) executable path
qexec(args)
Execute a file. Use if caller does not care for STDIN, STDOUT or STDERR.
The sequence part of args are the arguments passed to the executable
The dictionary part of args has options and override. See the following.

Parameters:

  • args
    • _bin override path to binary
    • _env environment variables
    • _cwd current working directory
    • _stdin string as standard input
    • _stdout path to file as standard output
    • _stderr path to file as standard error
    • _return_code return the exit code instead of boolean true
    • _ignore_error always return boolean true

Returns:

  1. bool true if no errors, nil otherwise
  2. table result
  3. result.stdout (table) sequence of stdout lines
  4. result.stderr (table) sequence of stderr lines
  5. result.pid (int) pid of terminated executable, if successful; nil otherwise
  6. result.status (string) status: "exited", "killed" or "stopped"; otherwise, an error message
  7. result.code (int) exit status, or signal number responsible for "killed" or "stopped"; otherwise, an errnum
  8. result.bin (string) executable path
readin(sz)
Read string from a polled STDIN.

Parameters:

  • sz int bytes to read

Returns:

    string string read
fdwrite(path, str)
Write to given path name. Wraps lib.write().

Parameters:

  • path string name
  • str string string to write

Returns:

    bool true if successfully written; otherwise it returns nil
awrite(path, str, mode)
Write to give path name atomically. Wraps lib.write().

Parameters:

  • path string name
  • str string string to write
  • mode number octal mode when opening file

Returns:

  1. bool true when successfully writing; otherwise, return nil
  2. string successful message string; otherwise, return a string describing the error
is_dir(path)
Check if a given path name is a directory.

Parameters:

  • path string name

Returns:

    bool true if a directory; otherwise, return nil
is_file(path)
Check if a given path name is a file.

Parameters:

  • path string name

Returns:

    bool true if a file; otherwise, return nil
is_link(path)
Check if a given path name is a symbolic link.

Parameters:

  • path string name

Returns:

    bool true if a symbolic link; otherwise, return nil
log(file, ident, msg, option, facility, level)
Write to the syslog and a file if given.

Parameters:

  • file string path name to log to.
  • ident string arbitrary identification string
  • msg string message body
  • option int see luaposix syslog constants
  • facility int see luaposix syslog constants
  • level int see luaposix syslog constants
diff_time(finish, start)
Calculate difference in time. From luaposix.

Parameters:

  • finish int end time
  • start int start time

Returns:

    {sec, usec} a table of results
effective_username()
Get effective username.

Returns:

    string username
real_username()
Get real username.

Returns:

    string username
cmd()
Execute command or executable as the key for this function-table. Wraps lib.exec and lib.qexec so you can execute a given executable as the index to cmd. See lib.exec() and lib.qexec() for the possible options and results.

The invocation cmd.ls should also work since lib.bin_path() is called on the command. Prepend '-' to the command to ignore the output ala lib.qexec().

Usage:

  • cmd["/bin/ls"]{ "/tmp" }
  • cmd.ls{"/tmp"}
  • cmd["-/bin/ls"]{ "/tmp" }
basename(file)
File part of a path. Same as posix.libgen.basename. Copied here for convenience.

Parameters:

  • file string to act on

Returns:

    string filename part of path
dirname(file)
Directory name of path. Same as posix.libgen.dirname. Copied here for convenience.

Parameters:

  • file string to act on

Returns:

    string directory parth of path
decomp_path(str)
Split a file name.

Parameters:

  • str string path name

Returns:

  1. string path Directory component
  2. string base Basename minus the extension
  3. string ext The extension
retry_f(on_fail, delay, retries)
Retry factory.

Parameters:

  • on_fail function function to run in case of failure. Takes in the second return value from the retried function as an argument.
  • delay number seconds to sleep after a failure. Default is 30 seconds.
  • retries number number of tries. Default is to retry indefinitely.

Returns:

    function a function that runs ...

Usage:

    run = retry_f(function() end, 3, 1)
    run(string.match, "match", "match")
generated by LDoc 1.4.6 Last updated 2017-05-09 15:50:37