mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Remove obsolete test singularity function
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -252,7 +252,6 @@ extern unsigned char blockingstatus;
|
||||
extern char ** wildcarddomains;
|
||||
|
||||
extern memoryStruct memory;
|
||||
extern bool runtest;
|
||||
|
||||
extern char * username;
|
||||
extern char timestamp[16];
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -9,105 +9,14 @@
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "FTL.h"
|
||||
#include <dirent.h>
|
||||
|
||||
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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user