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

-q, quiet: Only display needed information #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all 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: 23 additions & 12 deletions modsec-sdbm-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define p printf
#define v if (verbose) printf
#endif
#define p2 if (!quiet) printf

#define IS_EXPIRED 128

Expand All @@ -51,7 +52,7 @@
#define EXTRACT 64


int verbose = 0;
int verbose = 0, quiet = 0;
static char progress_feedback[] = {'|', '/', '-', '\\'};


Expand Down Expand Up @@ -231,6 +232,12 @@ static int dump_database(apr_pool_t *pool, apr_sdbm_t *db, int action, char *new
char *file_name = "/new_db";
int full_len = 1 + strlen(new_db_path) + strlen(file_name);
char *full_path = (char *) malloc(full_len);
if (!full_path) {
v("Cannot allocate memory.\n");
fret = -1;
goto end;
}

strcpy(full_path, new_db_path);
strcat(full_path, file_name);
full_path[full_len] = '\0';
Expand Down Expand Up @@ -343,13 +350,13 @@ static int dump_database(apr_pool_t *pool, apr_sdbm_t *db, int action, char *new
}
if (action & SHRINK || action & STATUS)
{
printf("\n");
printf("Total of %.0f elements processed.\n", elements);
printf("%d elements removed.\n", removed);
printf("Expired elements: %d, inconsistent items: %d\n", expired_datum,
p2("\n");
p2("Total of %.0f elements processed.\n", elements);
p2("%d elements removed.\n", removed);
p2("Expired elements: %d, inconsistent items: %d\n", expired_datum,
bad_datum);
if (expired_datum+bad_datum != 0 && elements !=0)
printf("Fragmentation rate: %2.2f%% of the database is/was dirty " \
p2("Fragmentation rate: %2.2f%% of the database is/was dirty " \
"data.\n", 100*(expired_datum+bad_datum)/elements);
}

Expand Down Expand Up @@ -397,6 +404,7 @@ void help (void) {
p(" -r, remove: Expects to receive a key as a paramter to be removed;\n");
p(" -V. version: Print version information.\n");
p(" -v, verbose: Some extra information about what this utility is doing.\n");
p(" -q, quiet: Only display needed information.\n");
p(" -h, help: this message.\n\n");

}
Expand All @@ -416,7 +424,7 @@ int main (int argc, char **argv)
return 0;
}

while ((c = getopt (argc, argv, "nkxsdahVvur:D:")) != -1)
while ((c = getopt (argc, argv, "qnkxsdahVvur:D:")) != -1)
switch (c)
{
case 'd':
Expand Down Expand Up @@ -447,6 +455,9 @@ int main (int argc, char **argv)
case 'v':
verbose = 1;
break;
case 'q':
quiet = 1;
break;
case 'V':
version();
return 0;
Expand Down Expand Up @@ -485,27 +496,27 @@ int main (int argc, char **argv)
apr_dir_t *db_dest_dir;

// test to see if the target directory exists
printf ("Checking target directory: %s\n", new_db_path);
p2("Checking target directory: %s\n", new_db_path);
ret = apr_dir_open(&db_dest_dir, new_db_path, pool);
if (ret != APR_SUCCESS) {
char errmsg[120];
p("Could not open target directory %s: %s\n", new_db_path, apr_strerror(ret, errmsg, sizeof errmsg));
goto that_is_all_folks;
}
apr_dir_close(db_dest_dir);
printf("Target directory exists.\n");
p2("Target directory exists.\n");

printf ("Opening file: %s\n", file);
p2("Opening file: %s\n", file);
ret = open_sdbm(pool, &db, argv[index]);
if (ret < 0)
{
printf("Failed to open sdbm: %s\n", file);
goto that_is_all_folks;
}
printf("Database ready to be used.\n");
p2("Database ready to be used.\n");

if (to_remove) {
printf("Removing key: %s\n", to_remove);
p2("Removing key: %s\n", to_remove);
remove_key(pool, db, to_remove);
continue;
}
Expand Down