mirror of
https://github.com/ItsBlurf/BFpilot.git
synced 2026-10-18 23:06:53 -05:00
Release: v0.3.1-test9-exit - loopback accept wakeup, background thread cleanup on shutdown
This commit is contained in:
1 parent
34f471dade
commit
005911f824
6 files changed
+43
No files matched your search
Binary file not shown.
BIN
Binary file not shown.
@@ -2023,8 +2023,13 @@ MarkInterruptedArchiveStatus(const std::string &old_status) {
|
||||
LogLine("archive interrupted status recovered old_status=%s", sample.c_str());
|
||||
}
|
||||
|
||||
static volatile int g_archive_daemon_exit = 0;
|
||||
static volatile int g_archive_daemon_running = 0;
|
||||
|
||||
static void *
|
||||
ArchiveDaemonMain(void *arg) {
|
||||
g_archive_daemon_running = 1;
|
||||
g_archive_daemon_exit = 0;
|
||||
if(!MkdirAll(BFPILOT_ARCHIVE_DIR)) {
|
||||
LogLine("archive daemon mkdir failed errno=%d", errno);
|
||||
return (void*)2;
|
||||
@@ -2073,6 +2078,7 @@ ArchiveDaemonMain(void *arg) {
|
||||
|
||||
std::string last_job;
|
||||
for(;;) {
|
||||
if(g_archive_daemon_exit) break;
|
||||
std::string status;
|
||||
bool prepared = ReadSmallFile(BFPILOT_ARCHIVE_STATUS, status, 32768) &&
|
||||
status.find("\"state\":\"prepared\"") != std::string::npos;
|
||||
@@ -2089,6 +2095,7 @@ ArchiveDaemonMain(void *arg) {
|
||||
usleep(250000);
|
||||
}
|
||||
close(lock_fd);
|
||||
g_archive_daemon_running = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2116,6 +2123,15 @@ bfpilot_archive_start_daemon(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
bfpilot_archive_stop_daemon(void) {
|
||||
g_archive_daemon_exit = 1;
|
||||
for(int i = 0; i < 50; i++) {
|
||||
if(!g_archive_daemon_running) break;
|
||||
usleep(20000);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef BFPILOT_ARCHIVE_NO_MAIN
|
||||
int
|
||||
main(void) {
|
||||
|
||||
@@ -10,6 +10,7 @@ extern "C" {
|
||||
|
||||
int bfpilot_archive_run_prepared_job(void);
|
||||
int bfpilot_archive_start_daemon(void);
|
||||
void bfpilot_archive_stop_daemon(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "transfer.h"
|
||||
#include "version.h"
|
||||
#include "websrv.h"
|
||||
#include "archive_worker.h"
|
||||
#include "search.h"
|
||||
|
||||
#define BFPILOT_RELOAD_TOKEN "bs5fm-local-reload"
|
||||
|
||||
@@ -395,6 +397,12 @@ main(int argc, char **argv) {
|
||||
}
|
||||
sleep(rc == -EADDRINUSE || rc == -EACCES ? 5 : 2);
|
||||
}
|
||||
|
||||
#if BFPILOT_ENABLE_INTEGRATED_ARCHIVE
|
||||
bfpilot_archive_stop_daemon();
|
||||
#endif
|
||||
bfpilot_search_shutdown();
|
||||
|
||||
_exit(0);
|
||||
return 0;
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <strings.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
@@ -171,12 +172,28 @@ websrv_request_exit(void) {
|
||||
g_websrv_exit_requested = 1;
|
||||
int srvfd = g_websrv_srvfd;
|
||||
g_websrv_srvfd = -1;
|
||||
unsigned short port = g_websrv_port;
|
||||
pthread_mutex_unlock(&g_websrv_lock);
|
||||
|
||||
if(srvfd >= 0) {
|
||||
shutdown(srvfd, SHUT_RDWR);
|
||||
close(srvfd);
|
||||
}
|
||||
|
||||
if(port > 0) {
|
||||
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(fd >= 0) {
|
||||
struct sockaddr_in addr = {0};
|
||||
addr.sin_len = sizeof(addr);
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
int flags = fcntl(fd, F_GETFL, 0);
|
||||
if(flags >= 0) fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
connect(fd, (struct sockaddr *)&addr, sizeof(addr));
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -717,6 +734,7 @@ websrv_listen(unsigned short port, websrv_ready_cb_t ready_cb,
|
||||
|
||||
pthread_mutex_lock(&g_websrv_lock);
|
||||
g_websrv_srvfd = srvfd;
|
||||
g_websrv_port = port;
|
||||
pthread_mutex_unlock(&g_websrv_lock);
|
||||
|
||||
if(ready_cb) ready_cb(port, ready_arg);
|
||||
|
||||
Reference in new issue
Block a user