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 1 commit
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
36 changes: 36 additions & 0 deletions err.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ 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. */

static int parsedverbosity()
yabberyabber marked this conversation as resolved.
Show resolved Hide resolved
{
char *pszVerbosity = getenv("BST_VERBOSITY");
if (pszVerbosity == NULL) {
return 1;
}
char *endPtr;
int iVerbosity = strtol(pszVerbosity, &endPtr, 10);
if (*endPtr != '\0') {
// Soemthing went wrong during parsing. This isn't
yabberyabber marked this conversation as resolved.
Show resolved Hide resolved
// critical so let's just ignore the parameter.
return 1;
}
return iVerbosity;
}

void init_logverbosity()
yabberyabber marked this conversation as resolved.
Show resolved Hide resolved
{
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 +94,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 +108,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,
yabberyabber marked this conversation as resolved.
Show resolved Hide resolved
};

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

#endif /* !ERRUTIL_H */
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,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