sends lib log to /dev/null in posix and added option (v) to reactivate

There in an error handling and messaging inside
This commit is contained in:
Unknown 2020-06-25 23:32:03 +02:00
parent 3f4b7a037a
commit 4e922e8194

View file

@ -54,6 +54,12 @@
#include <string.h>
#include <ctype.h>
#ifndef _WIN32
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#include <nfc/nfc.h>
#include "mifare.h"
@ -571,7 +577,11 @@ static void
print_usage(const char *pcProgramName)
{
printf("Usage: ");
#ifndef _WIN32
printf("%s f|r|R|w|W a|b u|U<01ab23cd> <dump.mfd> [<keys.mfd> [f] [v]]\n", pcProgramName);
#else
printf("%s f|r|R|w|W a|b u|U<01ab23cd> <dump.mfd> [<keys.mfd> [f]]\n", pcProgramName);
#endif
printf(" f|r|R|w|W - Perform format (f) or read from (r) or unlocked read from (R) or write to (w) or unlocked write to (W) card\n");
printf(" *** format will reset all keys to FFFFFFFFFFFF and all data to 00 and all ACLs to default\n");
printf(" *** unlocked read does not require authentication and will reveal A and B keys\n");
@ -582,7 +592,9 @@ print_usage(const char *pcProgramName)
printf(" <dump.mfd> - MiFare Dump (MFD) used to write (card to MFD) or (MFD to card)\n");
printf(" <keys.mfd> - MiFare Dump (MFD) that contain the keys (optional)\n");
printf(" f - Force using the keyfile even if UID does not match (optional)\n");
#ifndef _WIN32
printf(" v - Sends libnfc log output to console (optional)\n");
#endif
printf("Examples: \n\n");
printf(" Read card to file, using key A:\n\n");
printf(" %s r a u mycard.mfd\n\n", pcProgramName);
@ -706,6 +718,21 @@ main(int argc, const char *argv[])
tag_uid = NULL;
}
#ifndef _WIN32
// Send noise from lib to /dev/null
bool verbose = false;
if (argv[7]) {
if (strcmp(argv[7], "v") == 0) verbose = true;
} else {
if (strcmp(argv[6], "v") == 0) verbose = true;
}
if (!verbose) {
int fd = open("/dev/null", O_WRONLY);
dup2(fd, 2);
close(fd);
}
#endif
if (atAction == ACTION_USAGE) {
print_usage(argv[0]);
exit(EXIT_FAILURE);