Start timer thread keeping an eye on timed blocking mode changes

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2023-05-07 08:51:30 +02:00
parent 7f0bd7481e
commit b97d99ae3e
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
7 changed files with 27 additions and 7 deletions

View File

@ -164,7 +164,10 @@ int api_handler(struct mg_connection *conn, void *ignored)
}
// Call the API function and get the return code
log_debug(DEBUG_API, "Sending to %s", api_request[i].uri);
log_debug(DEBUG_API, "Processing %s %s in %s",
api.request->request_method,
api.request->local_uri_raw,
api_request[i].uri);
ret = api_request[i].func(&api);
log_debug(DEBUG_API, "Done");
break;

View File

@ -205,7 +205,7 @@ int check_client_auth(struct ftl_conn *api)
{
char timestr[128];
get_timestr(timestr, auth_data[user_id].valid_until, false, false);
log_debug(DEBUG_API, "Recognized known user: user_id %i valid_until: %s remote_addr %s",
log_debug(DEBUG_API, "Recognized known user: user_id %i, valid_until: %s, remote_addr %s",
user_id, timestr, auth_data[user_id].remote_addr);
}
}

View File

@ -88,6 +88,8 @@ static int set_blocking(struct ftl_conn *api)
// Delete a possibly running timer
set_blockingmode_timer(-1, true);
log_debug(DEBUG_API, "No change in blocking mode, resetting timer");
}
else
{
@ -96,6 +98,8 @@ static int set_blocking(struct ftl_conn *api)
// Start timer (-1 disables all running timers)
set_blockingmode_timer(timer, !target_status);
log_debug(DEBUG_API, "%sd Pi-hole, timer set to %d seconds", target_status ? "Enable" : "Disable", timer);
}
// Return GET property as result of POST/PUT/PATCH action

View File

@ -2829,7 +2829,7 @@ void FTL_fork_and_bind_sockets(struct passwd *ent_pw)
// Start database thread if database is used
if(pthread_create( &threads[DB], &attr, DB_thread, NULL ) != 0)
{
log_crit("Unable to open database thread. Exiting...");
log_crit("Unable to creeate database thread. Exiting...");
exit(EXIT_FAILURE);
}
@ -2837,7 +2837,7 @@ void FTL_fork_and_bind_sockets(struct passwd *ent_pw)
// collection needs to be done
if(pthread_create( &threads[GC], &attr, GC_thread, NULL ) != 0)
{
log_crit("Unable to open GC thread. Exiting...");
log_crit("Unable to create GC thread. Exiting...");
exit(EXIT_FAILURE);
}
@ -2846,7 +2846,15 @@ void FTL_fork_and_bind_sockets(struct passwd *ent_pw)
// (e.g. on CI builds), the thread is never started)
if(resolve_names() && pthread_create( &threads[DNSclient], &attr, DNSclient_thread, NULL ) != 0)
{
log_crit("Unable to open DNS client thread. Exiting...");
log_crit("Unable to create DNS client thread. Exiting...");
exit(EXIT_FAILURE);
}
// Start thread that checks various timers, e.g., for automatic changing
// blocking mode (enabled/disabled for a given amount of time)
if(pthread_create( &threads[TIMER], &attr, timer, NULL ) != 0)
{
log_crit("Unable to create timer thread. Exiting...");
exit(EXIT_FAILURE);
}

View File

@ -242,6 +242,7 @@ enum thread_types {
GC,
DNSclient,
CONF_READER,
TIMER,
THREADS_MAX
} __attribute__ ((packed));

View File

@ -92,10 +92,16 @@ void *timer(void *val)
{
if(timer_delay > 0)
{
log_debug(DEBUG_EXTRA, "Pi-hole will be %s in %d seconds...",
timer_target_status ? "enabled" : "disabled", timer_delay);
timer_delay--;
}
else if(timer_delay == 0)
{
log_debug(DEBUG_EXTRA, "Timer expired, setting blocking mode to %s",
timer_target_status ? "enabled" : "disabled");
set_blockingstatus(timer_target_status);
timer_delay = -1;
}

View File

@ -75,8 +75,6 @@ int request_handler(struct mg_connection *conn, void *cbdata)
api.conn = conn;
api.request = req_info;
log_info("Webserver: %s %s vs. %s", req_info->request_method, req_info->local_uri_raw, admin_api_uri);
// Check if the request is for the API under /admin/api
// (it is posted at /api)
if(strncmp(req_info->local_uri_raw, admin_api_uri, strlen(admin_api_uri)) == 0)