From d110948129b61505621c9bacd3b86fbea232047f Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Wed, 29 Jul 2020 20:37:59 +0200 Subject: [PATCH] closing #2: made the program silent turned off the "error" messages by default and using the -v flag to turn them back on as they are not useful for normal use, also now those messages are printed to stdout --- hkd.1 | 4 ++-- hkd.c | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/hkd.1 b/hkd.1 index 6b3ffd0..03f1871 100644 --- a/hkd.1 +++ b/hkd.1 @@ -21,8 +21,8 @@ correctly. .SH OPTIONS .IP \-v -verbose, prints the internal pressed key buffer upon change acting as a crude -keylogger :^) +verbose, prints debug information and the internal pressed key buffer upon +change acting as a crude keylogger :^) .IP "\-c file" override default configuration file location, instead using the specified .I file diff --git a/hkd.c b/hkd.c index cf11023..d439d78 100644 --- a/hkd.c +++ b/hkd.c @@ -411,7 +411,8 @@ void int_handler (int signum) { switch (signum) { case SIGINT: - fprintf(stderr, yellow("Received interrupt signal, exiting gracefully...\n")); + if (vflag) + printf(yellow("Received interrupt signal, exiting gracefully...\n")); dead = 1; break; } @@ -486,19 +487,22 @@ void update_descriptors_list (int **fds, int *fd_num) /* Open device and check if it can give key events otherwise ignore it */ tmp_fd = open(ev_path, O_RDONLY | O_NONBLOCK); if (tmp_fd < 0) { - fprintf(stderr, red("Could not open device %s\n"), ev_path); + if (vflag) + printf(red("Could not open device %s\n"), ev_path); continue; } memset(evtype_b, 0, sizeof(evtype_b)); if (ioctl(tmp_fd, EVIOCGBIT(0, EV_MAX), evtype_b) < 0) { - fprintf(stderr, red("Could not read capabilities of device %s\n"),ev_path); + if (vflag) + printf(red("Could not read capabilities of device %s\n"),ev_path); close(tmp_fd); continue; } if (!test_bit(EV_KEY, evtype_b)) { - fprintf(stderr, yellow("Ignoring device %s\n"), ev_path); + if (vflag) + printf(yellow("Ignoring device %s\n"), ev_path); close(tmp_fd); continue; } @@ -513,10 +517,11 @@ void update_descriptors_list (int **fds, int *fd_num) } closedir(ev_dir); if (*fd_num) { - fprintf(stderr, green("Monitoring %d devices\n"), *fd_num); + if (vflag) + printf(green("Monitoring %d devices\n"), *fd_num); } else { fprintf(stderr, red("Could not open any devices, exiting\n")); - exit(-1); + exit(EXIT_FAILURE); } } @@ -635,7 +640,8 @@ void parse_config_file (void) wordfree(&result); if (fd) break; - perror(yellow("error opening config file")); + if (vflag) + printf(yellow("config file not found at %s\n"), config_paths[i]); } if (!fd) die("could not open any config files, check the log for more details");