diff --git a/src/config.c b/src/config.c index e5f04ff06..a03340395 100644 --- a/src/config.c +++ b/src/config.c @@ -716,6 +716,10 @@ void read_debuging_settings(FILE *fp) // defaults to: false setDebugOption(fp, "DEBUG_EVENTS", DEBUG_EVENTS); + // DEBUG_HELPER + // defaults to: false + setDebugOption(fp, "DEBUG_HELPER", DEBUG_HELPER); + if(config.debug) { logg("*****************************"); @@ -739,6 +743,7 @@ void read_debuging_settings(FILE *fp) logg("* DEBUG_EDNS0 %s *", (config.debug & DEBUG_EDNS0)? "YES":"NO "); logg("* DEBUG_CLIENTS %s *", (config.debug & DEBUG_CLIENTS)? "YES":"NO "); logg("* DEBUG_EVENTS %s *", (config.debug & DEBUG_EVENTS)? "YES":"NO "); + logg("* DEBUG_HELPER %s *", (config.debug & DEBUG_HELPER)? "YES":"NO "); logg("*****************************"); } diff --git a/src/dnsmasq/helper.c b/src/dnsmasq/helper.c index 2f32182d0..8cfa1c42c 100644 --- a/src/dnsmasq/helper.c +++ b/src/dnsmasq/helper.c @@ -241,6 +241,9 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd) else continue; + /************************** Pi-hole modification **************************/ + FTL_log_helper(1, action_str); + /**************************************************************************/ /* stringify MAC into dhcp_buff */ p = daemon->dhcp_buff; @@ -640,6 +643,12 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd) fcntl(event_fd, F_SETFD, i | FD_CLOEXEC); close(pipefd[0]); + /**************************** Pi-hole modification ****************************/ + FTL_log_helper(5, daemon->lease_change_command, action_str, + (is6 && data.action != ACTION_ARP) ? daemon->packet : daemon->dhcp_buff, + daemon->addrbuff, hostname); + /******************************************************************************/ + p = strrchr(daemon->lease_change_command, '/'); if (err == 0) { @@ -650,6 +659,9 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd) err = errno; } /* failed, send event so the main process logs the problem */ + /**************************** Pi-hole modification ****************************/ + FTL_log_helper(2, daemon->lease_change_command, strerror(err)); + /******************************************************************************/ send_event(event_fd, EVENT_EXEC_ERR, err, NULL); _exit(0); } diff --git a/src/enums.h b/src/enums.h index 1de6f3e9b..7bd1d37f6 100644 --- a/src/enums.h +++ b/src/enums.h @@ -137,6 +137,7 @@ enum debug_flags { DEBUG_EDNS0 = (1 << 16), /* 00000000 00000001 00000000 00000000 */ DEBUG_CLIENTS = (1 << 17), /* 00000000 00000010 00000000 00000000 */ DEBUG_EVENTS = (1 << 18), /* 00000000 00000100 00000000 00000000 */ + DEBUG_HELPER = (1 << 19), /* 00000000 00001000 00000000 00000000 */ } __attribute__ ((packed)); enum events { diff --git a/src/log.c b/src/log.c index a6bfdaf3b..e61387a06 100644 --- a/src/log.c +++ b/src/log.c @@ -166,6 +166,44 @@ void _FTL_log(const bool newline, const char *format, ...) pthread_mutex_unlock(&lock); } +// Log helper activity (may be script or lua) +void FTL_log_helper(const unsigned char n, ...) +{ + // Only log helper debug messages if enabled + if(!(config.debug & DEBUG_HELPER)) + return; + + // Extract all variable arguments + va_list args; + char *arg[n]; + va_start(args, n); + for(unsigned char i = 0; i < n; i++) + arg[i] = strdup(va_arg(args, char*)); + va_end(args); + + // Select appropriate logging format + switch (n) + { + case 1: + logg("Script: Starting helper for action \"%s\"", arg[0]); + break; + case 2: + logg("Script: FAILED to execute \"%s\": %s", arg[0], arg[1]); + break; + case 5: + logg("Script: Executing \"%s\" with arguments: \"%s %s %s %s\"", + arg[0], arg[1], arg[2], arg[3], arg[4]); + break; + default: + logg("ERROR: Unsupported number of arguments passed to FTL_log_helper(): %u", n); + break; + } + + // Free allocated memory + for(unsigned char i = 0; i < n; i++) + free(arg[i]); +} + void format_memory_size(char * const prefix, const unsigned long long int bytes, double * const formated) { diff --git a/src/log.h b/src/log.h index 141d4208c..ba5d20bc9 100644 --- a/src/log.h +++ b/src/log.h @@ -30,5 +30,6 @@ const char *get_ordinal_suffix(unsigned int number) __attribute__ ((const)); #define logg_sameline(format, ...) _FTL_log(false, format, ## __VA_ARGS__) void _FTL_log(const bool newline, const char* format, ...) __attribute__ ((format (gnu_printf, 2, 3))); void log_ctrl(bool vlog, bool vstdout); +void FTL_log_helper(const unsigned char n, ...); #endif //LOG_H