Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Create BST_VERBOSITY to enable/disable warnings #92

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions err.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,35 @@ void (*err_exit)(int) = exit;
const char *err_line_ending = "\n";
int err_flags = 0;

/* Parse the BST_VERBOSITY environment variable to determine the requested
verbosity. Higher numbers are associated with more verbosity, with 9
being the most verbose and 0 being the least verbose. The default
verbosity level is 1. */

noreturn void err(int eval, const char *fmt, ...);
vzxv marked this conversation as resolved.
Show resolved Hide resolved
static int parsedverbosity(void)
{
char *pszVerbosity = getenv("BST_VERBOSITY");
if (pszVerbosity == NULL) {
return 1;
}
char *endPtr;
int iVerbosity = strtol(pszVerbosity, &endPtr, 10);
if (*endPtr != '\0') {
err(2, "un-parsable value of BST_VERBOSITY");
yabberyabber marked this conversation as resolved.
Show resolved Hide resolved
}
return iVerbosity;
}

void init_logverbosity(void)
{
int iVerbosity = parsedverbosity();

if (iVerbosity >= 1) {
err_flags |= ERR_VERBOSE;
}
}

/* fdprintf and vfdprintf are fork-safe versions of fprintf and vfprintf. */

static void vfdprintf(int fd, const char *fmt, va_list vl)
Expand Down Expand Up @@ -64,6 +93,9 @@ static void vwarnsyslog(int errcode, const char *fmt, va_list vl)

void vwarn(const char *fmt, va_list vl)
{
if (!(err_flags & ERR_VERBOSE)) {
return;
}
if (err_flags & ERR_USE_SYSLOG) {
vwarnsyslog(errno, fmt, vl);
return;
Expand All @@ -75,6 +107,9 @@ void vwarn(const char *fmt, va_list vl)

void vwarnx(const char *fmt, va_list vl)
{
if (!(err_flags & ERR_VERBOSE)) {
return;
}
if (err_flags & ERR_USE_SYSLOG) {
vwarnsyslog(0, fmt, vl);
return;
Expand Down
3 changes: 3 additions & 0 deletions errutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@

enum {
ERR_USE_SYSLOG = 1,

ERR_VERBOSE = 2,
};

extern void (*err_exit)(int);
extern const char *err_line_ending;
void init_logverbosity();
extern int err_flags;

#endif /* !ERRUTIL_H */
2 changes: 2 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "capable.h"
#include "compat.h"
#include "enter.h"
#include "errutil.h"
#include "kvlist.h"
#include "util.h"
#include "path.h"
Expand Down Expand Up @@ -263,6 +264,7 @@ int usage(int error, char *argv0)

int main(int argc, char *argv[], char *envp[])
{
init_logverbosity();
init_capabilities();

static struct entry_settings opts;
Expand Down
Loading