From f28cc2b8fb97ee1bcab6ad819ab329dc375e0bb2 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 12 May 2018 14:46:02 +0200 Subject: [PATCH] Remove obsolete test singularity function Signed-off-by: DL6ER --- FTL.h | 1 - args.c | 14 --------- daemon.c | 91 -------------------------------------------------------- 3 files changed, 106 deletions(-) diff --git a/FTL.h b/FTL.h index b4058b4e..6b155e6b 100644 --- a/FTL.h +++ b/FTL.h @@ -252,7 +252,6 @@ extern unsigned char blockingstatus; extern char ** wildcarddomains; extern memoryStruct memory; -extern bool runtest; extern char * username; extern char timestamp[16]; diff --git a/args.c b/args.c index 83ab7106..923f3133 100644 --- a/args.c +++ b/args.c @@ -16,7 +16,6 @@ bool daemonmode = true; bool debugthreads = false; bool debugclients = false; bool debugGC = false; -bool runtest = false; bool debugDB = false; bool travis = false; int argc_dnsmasq = 0; @@ -114,15 +113,6 @@ void parse_args(int argc, char* argv[]) exit(EXIT_SUCCESS); } - // pihole-FTL running - // will test if another pihole-FTL process is running - // and exits even if not (instead of starting a new one) - if(strcmp(argv[i], "running") == 0) - { - runtest = true; - ok = true; - } - // Don't go into background if(strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "no-daemon") == 0) @@ -186,10 +176,6 @@ void parse_args(int argc, char* argv[]) printf("\t-v, version Return version\n"); printf("\t-t, tag Return git tag\n"); printf("\t-b, branch Return git branch\n"); - printf("\t running Test if another pihole-FTL\n"); - printf("\t process is running and exit\n"); - printf("\t even if not (instead of\n"); - printf("\t starting a new one)\n"); printf("\t-f, no-daemon Don't go into daemon mode\n"); printf("\t-h, help Display this help and exit\n"); printf("\tdnsmasq-test Test syntax of dnsmasq's\n"); diff --git a/daemon.c b/daemon.c index 8a740660..c535f857 100644 --- a/daemon.c +++ b/daemon.c @@ -9,105 +9,14 @@ * Please see LICENSE file for your rights under this license. */ #include "FTL.h" -#include struct timeval t0[NUMTIMERS]; -int detect_FTL_process(void) -{ - DIR* dir = opendir("/proc"); - - if(dir) - { - struct dirent* de = 0; - while((de = readdir(dir)) != 0) - { - // Skip "." and ".." - if(strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) - continue; - - int pid = -1; - if(sscanf(de->d_name, "%d", &pid) == 1) - { - // Test if that is our own process - if(pid == getpid()) - continue; - - char buffer[512] = { 0 }; - sprintf(buffer, "/proc/%d/cmdline", pid); - - FILE* fp; - if((fp = fopen(buffer, "r")) != NULL) - { - char *linebuffer = NULL; - size_t size = 0; - - errno = 0; - if (getline(&linebuffer, &size, fp) != -1) - { - if (strstr(linebuffer, "pihole-FTL") != 0) - { - fclose(fp); - logg("%i - %s", pid, linebuffer); - return pid; - } - } - - if(errno == ENOMEM) - logg("WARN: process_pihole_log failed: could not allocate memory for getline"); - - if(linebuffer != NULL) - { - free(linebuffer); - linebuffer = NULL; - } - fclose(fp); - } - } - } - closedir(dir); - } - return -1; -} - -void test_singularity(void) -{ - if(runtest) - { - if(detect_FTL_process() > -1) - { - printf("Yes: Found a running FTL process\n"); - exit(EXIT_FAILURE); - } - else - { - printf("No: Did not find a running FTL process\n"); - exit(EXIT_SUCCESS); - } - } - - int pid; - while((pid = detect_FTL_process()) > -1) - { - printf("Found pihole-FTL process with PID %i (my PID %i) - killing it ...\n", pid, getpid()); - logg("Found pihole-FTL process with PID %i (my PID %i) - killing it ...", pid, getpid()); - if(kill(pid, SIGTERM) != 0) - { - printf("Killing failed (%s) ... Exiting now ...\n", strerror(errno)); - logg("Killing failed (%s) ... Exiting now ...", strerror(errno)); - exit(EXIT_FAILURE); - } - } - logg("Found no other running pihole-FTL process"); -} - void go_daemon(void) { pid_t process_id = 0; pid_t sid = 0; - test_singularity(); - // Create child process process_id = fork();