Updated README.md to show how `FEATURE` flags are defined and used now.

Fortune for sink's current commit: Great curse − 大凶
master
Avril 2 years ago
parent eba77a5d85
commit 9a50132e90
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -19,7 +19,7 @@
# * `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) # * `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)
PROJECT=sink PROJECT=sink
DESCRIPTION=sink all input and output of a program to /dev/null DESCRIPTION=sink all input and output of a program to /dev/null
VERSION=0.1.0 VERSION=0.2.0
AUTHOR=Avril <avril@cumallover.me> AUTHOR=Avril <avril@cumallover.me>
LICENSE=GPL3+ LICENSE=GPL3+

@ -19,11 +19,15 @@ Run `make && sudo make install` to build with full optimisations and install `si
To build for debugging, run `make debug`. To build for debugging, run `make debug`.
### Compiler flags ### Feature flags
* `-DREPLACE_STDERR` - Add to `CFLAGS` when building a target to re-route the child program's `stderr` stream to the sink as well. By default, it is passed through as default.
* `-DNO_SEARCH_PATH` - Add to `CFLAGS` when building to prevent the program looking up its argument in the `PATH` environment variable. 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`.)
* `-DNO_ENV` - Add to `CFLAGS` when building to prevent `envp` passthrough to the `execve()`'d program. When a debug-mode splash screen is printed, the features the binary was compiled with are also printed.
* `-DDEBUG_IGNORE_SPLASH` - Do not print project and version info in debug builds on startup.
* `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 ### Installation
The program must have been built before installation, and installation and uninstallation must be done as root. The program must have been built before installation, and installation and uninstallation must be done as root.

@ -8,7 +8,8 @@
#include "comp_features.h" #include "comp_features.h"
static const enum compiled_features compiled_features = FEATURE_FLAGS; __attribute__((used)) // For loading debug binary symbol
const enum compiled_features sink_compiled_features = FEATURE_FLAGS;
#define r_stdin 0 #define r_stdin 0
#define r_stdout 1 #define r_stdout 1
@ -153,6 +154,7 @@ static inline size_t count_list(const void*const* p)
while(*p++) n+=1; while(*p++) n+=1;
return n; return n;
} }
#if !FEATURE_HAS_FLAG(DEBUG_IGNORE_SPLASH)
static void print_compiled_features() static void print_compiled_features()
{ {
#define _X "\t%s\n" #define _X "\t%s\n"
@ -176,15 +178,22 @@ static void print_compiled_features()
#undef X #undef X
#undef _X #undef _X
} }
#endif
static void print_debug_info(int argc, char* const* argv, char* const* envp) static void print_debug_info(int argc, char* const* argv, char* const* envp)
{ {
#ifndef RELEASE
fprintf(stderr, "[DEBUG BUILD]\n"); fprintf(stderr, "[DEBUG BUILD]\n");
#else
fprintf(stderr, "[RELEASE BUILD]\n");
#endif
#if ! FEATURE_HAS_FLAG(DEBUG_IGNORE_SPLASH) #if ! FEATURE_HAS_FLAG(DEBUG_IGNORE_SPLASH)
fprintf(stderr, _PROJECT " v" _VERSION ": " _DESCRIPTION "\n"); fprintf(stderr, _PROJECT " v" _VERSION ": " _DESCRIPTION "\n");
fprintf(stderr, " :: written by " _AUTHOR " with <3 (License " _LICENSE ")\n---\n"); fprintf(stderr, " :: written by " _AUTHOR " with <3 (License " _LICENSE ")\n");
#endif fprintf(stderr, "Built with features:\n");
fprintf(stderr, "> features:\n");
print_compiled_features(); print_compiled_features();
fprintf(stderr, "---\n");
#endif
fprintf(stderr, "> program: %s (path lookup: " fprintf(stderr, "> program: %s (path lookup: "
#if FEATURE_HAS_FLAG(NO_SEARCH_PATH) #if FEATURE_HAS_FLAG(NO_SEARCH_PATH)

Loading…
Cancel
Save