Merge pull request #838 from pi-hole/fix/revert_portfile

Revert "Remove portfile not used by the current web interface any longer"
This commit is contained in:
DL6ER
2020-07-17 11:35:51 +02:00
committed by GitHub
8 changed files with 52 additions and 2 deletions
+2 -1
View File
@@ -7,7 +7,8 @@ pihole-FTL
# Versioning files (generated by Makefile)
version*
# CMake files
# CMake files generated during compilation
/cmake/
/cmake-build-debug/
/cmake-build-release/
+23
View File
@@ -34,6 +34,29 @@ bool dualstack = false;
bool ipv4telnet = false, ipv6telnet = false, sock_avail = false;
bool istelnet[MAXCONNS];
void saveport(int port)
{
FILE *f;
// Open "w" for truncation/creating file
if((f = fopen(FTLfiles.port, "w")) == NULL)
{
// Opening failed (permissions, path does not exist, etc.)
logg("WARNING: Unable to write used port to file");
logg(" (API might not find the port)");
}
else if(port > 0)
{
// Save port to file
fprintf(f, "%i", port);
fclose(f);
}
else
{
// FTL is terminating: Leave file truncated
fclose(f);
}
}
static bool bind_to_telnet_port_IPv4(int *socketdescriptor)
{
// IPv4 socket
+1
View File
@@ -10,6 +10,7 @@
#ifndef SOCKET_H
#define SOCKET_H
void saveport(int port);
void close_telnet_socket(void);
void close_unix_socket(bool unlink_file);
void seom(const int sock);
+7
View File
@@ -15,6 +15,8 @@
#include "log.h"
// nice()
#include <unistd.h>
// saveport()
#include "api/socket.h"
ConfigStruct config;
FTLFileNamesStruct FTLfiles = {
@@ -29,6 +31,7 @@ FTLFileNamesStruct FTLfiles = {
NULL,
NULL,
NULL,
NULL,
NULL
};
@@ -300,6 +303,10 @@ void read_FTLconf(void)
// PIDFILE
getpath(fp, "PIDFILE", "/run/pihole-FTL.pid", &FTLfiles.pid);
// PORTFILE
getpath(fp, "PORTFILE", "/run/pihole-FTL.port", &FTLfiles.port);
saveport(config.port);
// SOCKETFILE
getpath(fp, "SOCKETFILE", "/run/pihole/FTL.sock", &FTLfiles.socketfile);
+1
View File
@@ -50,6 +50,7 @@ typedef struct {
const char* snapConf;
char* log;
char* pid;
char* port;
char* socketfile;
char* FTL_db;
char* gravity_db;
+3
View File
@@ -112,6 +112,9 @@ int main (int argc, char* argv[])
close_telnet_socket();
close_unix_socket(true);
// Empty API port file, port 0 = truncate file
saveport(0);
// Close gravity database connection
gravityDB_close();
+9 -1
View File
@@ -11,8 +11,16 @@ if ! id -u pihole &> /dev/null; then
useradd -m -s /usr/sbin/nologin pihole
fi
# Kill possibly running pihole-FTL process
while pidof -s pihole-FTL > /dev/null; do
pid="$(pidof -s pihole-FTL)"
echo "Terminating running pihole-FTL process with PID ${pid}"
kill $pid
sleep 1
done
# Clean up possible old files from earlier test runs
rm -f /etc/pihole/gravity.db /etc/pihole/pihole-FTL.db /var/log/pihole.log /var/log/pihole-FTL.log
rm -f /etc/pihole/gravity.db /etc/pihole/pihole-FTL.db /var/log/pihole.log /var/log/pihole-FTL.log /dev/shm/FTL-*
# Create necessary directories and files
mkdir -p /etc/pihole /run/pihole /var/log
+6
View File
@@ -456,3 +456,9 @@
printf "%s\n" "${lines[@]}"
[[ ${lines[0]} == "2" ]]
}
@test "Port file exists and contains expected API port" {
run bash -c 'cat /run/pihole-FTL.port'
printf "%s\n" "${lines[@]}"
[[ ${lines[0]} == "4711" ]]
}