sink a program's input and output to /dev/null
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Avril 9a50132e90
Updated README.md to show how `FEATURE` flags are defined and used now.
3 years ago
.gitignore Added sink program and Makefile 3 years ago
LICENSE Create LICENSE 3 years ago
Makefile Updated README.md to show how `FEATURE` flags are defined and used now. 3 years ago
README.md Updated README.md to show how `FEATURE` flags are defined and used now. 3 years ago
comp_features.h Added feature flags instead of raw -D compiler flags. 3 years ago
sink.c Updated README.md to show how `FEATURE` flags are defined and used now. 3 years ago

README.md

sink - sinks all input into /dev/null

Small and fast util that re-routes stdin, stdout (and optionally, stderr) of a program to /dev/null without needing to spawn a (sub-)shell. Can be useful in some situations (see example below.)

Usage

Command usage is in the form of: ./sink [<program name> [<arguments...>]].

Example:

$ sink cat sink.c # Identical to `>>/dev/null 0>&1 cat sink.c`, but will not cause cat to error on `stdin` being a redirect to an output stream.

When invoked with <program name>: execve()s into the program (if it exists or is found in $PATH) with <arguments....> and a passed-through envp (see below in Compiler flags on changing this behaviour.)

Building

Run make && sudo make install to build with full optimisations and install sink to /usr/local/bin/sink. (run sudo make uninstall to remove.)

To build for debugging, run make debug.

Feature flags

Set the following to the environment variable FEATURES when invoking make to build with the speficied features' behaviour (e.g. FEATURES=NO_SEARCH_PATH\ NO_ENV make.) When a debug-mode splash screen is printed, the features the binary was compiled with are also printed.

  • REPLACE_STDERR - Re-route the child program's stderr stream to the sink as well. By default, it is passed through as default.
  • NO_SEARCH_PATH - Prevent the program looking up its argument in the PATH environment variable.
  • NO_ENV - Prevent envp passthrough to the execve()'d program.
  • DEBUG_IGNORE_SPLASH - Do not print project and version info in debug builds on startup.

Installation

The program must have been built before installation, and installation and uninstallation must be done as root. By default, make install will install sink to $(DESTDIR)$(PREFIX)/bin. You can override this by setting PREFIX=/path/to/usr make install

To install a different target, for example, debug, run make debug && sudo make install OUTPUT=sink-debug (OUTPUT is the binary name.) NOTE: You must specify the same OUTPUT value for make uninstall if done this way.

Target CPU

If building on a VPS, you may want to run TARGET_ARCH= make instead of make, to build for generic CPU instead of the default native target for optimised (release) builds.

Static linkage

By default, the program is entirely statically linked. To override this, run SHARED=yes make, for any building target.

Stripping

To build optimised without stripping the symbol table, run make release or make STRIP=:. For installing without stripping the symbol table, run sudo make install STRIP=true; the effect is the same as STRIP=: which does not work for the install target.

Other targets

  • sink (default): stripped release target. output: sink
  • release: optimised build. output: sink-release
  • debug: unoptimised build with debuginfo. output: sink-debug
  • clean: remove all previous object and binary output files

Environment variables

  • PREFIX - The installation path prefix. Defaults to /usr/local if not set.
  • SHARED - set to "yes" to prevent passing --static to cc
  • TARGET_ARCH - target arch (-march=), or set TARGET_ARCH= to force set to generic target. (default [release only]: native)
  • CFLAGS, COMMON_FLAGS - passthrough to cc
  • LDFLAGS - passthrough to ld
  • DEBUG_CFLAGS, DEBUG_LDFLAGS - passthrough to cc / ld on target debug
  • RELEASE_CFLAGS, RELEASE_LDFLAGS - passthrough to cc / ld on target release

Make overridable only

  • STRIP - Strip command for default output (stripped release) target (make sink). set make STRIP=: to prevent stripping entirely. (NOTE: When using make install, STRIP=: will not work, instead, paradoxically, set STRIP=true, they have the same effect for all targets)
  • OUTPUT - The name of the output binary from the default target, and the binary that install/uninstall targets look for.

License

GPL'd with <3