summaryrefslogtreecommitdiff
path: root/LinBPQ.c
diff options
context:
space:
mode:
authorDave Hibberd <hibby@debian.org>2026-09-29 21:39:24 +0100
committerDave Hibberd <hibby@debian.org>2026-09-29 21:39:24 +0100
commit592e5967b8fcd79423802071319d0c646f2080df (patch)
tree0eef3a28cfe1a939caf9d61e419a56d79b3c38e3 /LinBPQ.c
parent23de03a0c8bf8a564cc0442f49d050ed11e372b8 (diff)
New upstream version 6.0.25.41+repackupstream/6.0.25.41+repack
Diffstat (limited to 'LinBPQ.c')
-rw-r--r--LinBPQ.c714
1 files changed, 447 insertions, 267 deletions
diff --git a/LinBPQ.c b/LinBPQ.c
index df0e334..8515119 100644
--- a/LinBPQ.c
+++ b/LinBPQ.c
@@ -29,6 +29,7 @@ along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
#else
#include <iconv.h>
#include <errno.h>
+
#ifndef MACBPQ
#ifndef FREEBSD
#include <sys/prctl.h>
@@ -273,7 +274,7 @@ BOOL CLOSING = FALSE;
int ProgramErrors;
int Slowtimer = 0;
-#define REPORTINTERVAL 15 * 549; // Magic Ticks Per Minute for PC's nominal 100 ms timer
+#define REPORTINTERVAL 15 * 600; // 15 mins
int ReportTimer = 0;
// Console Terminal Support
@@ -384,26 +385,88 @@ BOOL CtrlHandler(DWORD fdwCtrlType)
#include <execinfo.h>
#include <signal.h>
+#include <backtrace.h>
+
+static struct backtrace_state *state;
+static char ** lines;
+static char * line;
+
+
+// Callback to print a niely formatted bsack tracre
+
+static int full_callback (void *data, uintptr_t pc, const char *pathname, int line_number, const char *function)
+{
+ if (pathname == NULL || function == NULL || line_number == 0)
+ Debugprintf(line);
+ else
+ {
+ const char *filename = rindex(pathname, '/');
+ if (filename) filename++; else filename = pathname;
+ Debugprintf("%s %s:%d -- %s", line, filename, line_number, function);
+ }
+ return 0;
+};
+
+static void error_callback (void *data, const char *message, int error_number)
+{
+ if (error_number == -1)
+ {
+ fprintf(stderr, "If you want backtraces, you have to compile with -g\n\n");
+ _Exit(1);
+ }
+ else
+ {
+ fprintf(stderr, "Backtrace error %d: %s\n", error_number, message);
+ }
+};
// Linux Signal Handlers
+
+VOID __cdecl DebugprintNOLF(const char * format, ...);
+
static void segvhandler(int sig)
{
- void *array[10];
+ void *array[50];
+
size_t size;
- char msg[] = "\nSIGSEGV Received\n";
+ char msg[] = "\nSIGSEGV Received\n\nBacktrace\n\n";
+ char msg2[] = "\nThere should be a better Backtrace in the Debug Log with source filenames and line numbers\n\n";
+ int n;
- write(STDERR_FILENO, msg, strlen(msg));
+ // Write the basic backtrace() first as this is meant to be signal safe
+
+ // Then try a libbacktrace(), which gives source info may use non-signal safe functions so may not work
+
+ write(STDOUT_FILENO, msg, strlen(msg));
// get void*'s for all entries on the stack
- size = backtrace(array, 10);
+
+ size = backtrace(array, 50);
- // print out all the frames to stderr
+ // normal print
+
+ backtrace_symbols_fd(array, size, STDOUT_FILENO);
- backtrace_symbols_fd(array, size, STDERR_FILENO);
+// if source info for the address is available we want to print it but otherwise print the old style back trace.
- write(STDOUT_FILENO, msg, strlen(msg));
- backtrace_symbols_fd(array, size, STDOUT_FILENO);
+ printf("\n");
+ printf("\n");
+
+ write(STDOUT_FILENO, msg2, strlen(msg2));
+
+ // backtrace_symbols produces an array of the old style records but isn't signal safe.
+ // Easiest probably to always print that and add source info if possible
+ lines = backtrace_symbols(array, size);
+
+ Debugprintf(msg);
+
+ for (n = 0; n < size; n++)
+ {
+ line = lines[n];
+ backtrace_pcinfo(state, (uintptr_t)array[n], full_callback, error_callback, NULL);
+ }
+
hookNodeClosing("sigsegv");
Sleep(500);
@@ -427,6 +490,12 @@ static void abrthandler(int sig)
write(STDOUT_FILENO, msg, strlen(msg));
backtrace_symbols_fd(array, size, STDOUT_FILENO);
+ printf("\n");
+ printf("\n");
+ backtrace_print(state, 0, stdout);
+
+ backtrace_print(state, 0, stderr);
+
hookNodeClosing("sigabrt");
Sleep(500);
@@ -543,7 +612,7 @@ VOID MonitorThread(void * x)
-VOID TIMERINTERRUPT();
+int TIMERINTERRUPT();
BOOL Start();
VOID INITIALISEPORTS();
@@ -672,6 +741,7 @@ void ConTermInput(char * Msg)
if (!ConTerm.CONNECTED)
SessionControl(ConTerm.BPQStream, 1, 0);
+
ConTerm.StackIndex = 0;
// Stack it
@@ -709,8 +779,18 @@ void ConTermPoll()
{
// Connected
+ BPQVECSTRUC * SESS;
+ TRANSPORTENTRY * L4;
+
ConTerm.CONNECTED = TRUE;
ConTerm.SlowTimer = 0;
+
+ SESS = &BPQHOSTVECTOR[ConTerm.BPQStream - 1];
+ if (SESS)
+ {
+ L4 = SESS->HOSTSESSION;
+ L4->Secure_Session = 1;
+ }
}
else
{
@@ -809,6 +889,340 @@ static void abrthandler(int sig);
void GetRestartData();
+void Semaphored100msCode()
+{
+ // code that doesn't need to run every tick - run every 100 mS
+
+ // Runs under semaphore
+
+ if (IPActive) Poll_IP();
+ if (RigActive) Rig_Poll();
+ if (APRSActive) Poll_APRS();
+ CheckWL2KReportTimer();
+
+ if (QCOUNT < 10)
+ {
+ if (CLOSING == FALSE)
+ FindLostBuffers();
+ CLOSING = TRUE;
+ }
+
+ if (CLOSING)
+ {
+ if (RunChat)
+ {
+ CloseChat();
+ RunChat = FALSE;
+ }
+
+ if (RunMail)
+ {
+ int BPQStream, n;
+
+ RunMail = FALSE;
+
+ for (n = 0; n < NumberofStreams; n++)
+ {
+ BPQStream = Connections[n].BPQStream;
+
+ if (BPQStream)
+ {
+ SetAppl(BPQStream, 0, 0);
+ Disconnect(BPQStream);
+ DeallocateStream(BPQStream);
+ }
+ }
+
+ // SaveUserDatabase();
+ SaveMessageDatabase();
+ SaveBIDDatabase();
+ SaveConfig(ConfigName);
+ SaveRestartData();
+ }
+
+ KEEPGOING--; // Give time for links to close
+ setbuf(stdout, NULL);
+ printf("Closing... %d \r", KEEPGOING);
+ }
+
+
+ if (RigReconfigFlag)
+ {
+ RigReconfigFlag = FALSE;
+ Rig_Close();
+ Sleep(2000); // Allow CATPTT threads to close
+ RigActive = Rig_Init();
+
+ Consoleprintf("Rigcontrol Reconfiguration Complete");
+ }
+
+ if (APRSReconfigFlag)
+ {
+ APRSReconfigFlag = FALSE;
+ APRSClose();
+ APRSActive = Init_APRS();
+
+ Consoleprintf("APRS Reconfiguration Complete");
+ }
+
+ if (ReconfigFlag)
+ {
+ int i;
+ BPQVECSTRUC * HOSTVEC;
+ PEXTPORTDATA PORTVEC=(PEXTPORTDATA)PORTTABLE;
+
+ ReconfigFlag = FALSE;
+
+ // SetupBPQDirectory();
+
+ WritetoConsoleLocal("Reconfiguring ...\n\n");
+
+ for (i=0;i<NUMBEROFPORTS;i++)
+ {
+ if (PORTVEC->PORTCONTROL.PORTTYPE == 0x10) // External
+ {
+ if (PORTVEC->PORT_EXT_ADDR)
+ {
+ // SaveWindowPos(PORTVEC->PORTCONTROL.PORTNUMBER);
+ // SaveAXIPWindowPos(PORTVEC->PORTCONTROL.PORTNUMBER);
+ // CloseDriverWindow(PORTVEC->PORTCONTROL.PORTNUMBER);
+ PORTVEC->PORT_EXT_ADDR(5,PORTVEC->PORTCONTROL.PORTNUMBER, NULL); // Close External Ports
+ }
+ }
+ PORTVEC->PORTCONTROL.PORTCLOSECODE(&PORTVEC->PORTCONTROL);
+ PORTVEC=(PEXTPORTDATA)PORTVEC->PORTCONTROL.PORTPOINTER;
+ }
+
+ IPClose();
+ APRSClose();
+ Rig_Close();
+ CloseTNCEmulator();
+
+ if (AGWActive)
+ AGWAPITerminate();
+
+ WL2KReports = NULL;
+
+ // Sleep(2000);
+
+ Consoleprintf("G8BPQ AX25 Packet Switch System Version %s %s", TextVerstring, Datestring);
+ Consoleprintf(VerCopyright);
+
+ Start();
+
+ NETROMTCPResolve();
+
+ INITIALISEPORTS();
+
+ SetApplPorts();
+
+ GetUIConfig();
+
+ FreeConfig();
+
+ for (i=1; i<68; i++) // Include Telnet, APRS, IP Vec
+ {
+ HOSTVEC=&BPQHOSTVECTOR[i-1];
+
+ HOSTVEC->HOSTTRACEQ=0;
+
+ if (HOSTVEC->HOSTSESSION !=0)
+ {
+ // Had a connection
+
+ HOSTVEC->HOSTSESSION=0;
+ HOSTVEC->HOSTFLAGS |=3; // Disconnected
+
+ // PostMessage(HOSTVEC->HOSTHANDLE, BPQMsg, i, 4);
+ }
+ }
+
+ OpenReportingSockets();
+
+ WritetoConsoleLocal("\n\nReconfiguration Complete\n");
+
+ if (IPRequired) IPActive = Init_IP();
+
+ APRSActive = Init_APRS();
+
+ if (ISPort == 0)
+ IGateEnabled = 0;
+
+ RigActive = Rig_Init();
+
+ if (NUMBEROFTNCPORTS)
+ {
+ FreeSemaphore(&Semaphore);
+ InitializeTNCEmulator();
+ GetSemaphore(&Semaphore, 2);
+ }
+
+ FreeSemaphore(&Semaphore);
+ AGWActive = AGWAPIInit();
+ GetSemaphore(&Semaphore, 2);
+
+ WritetoConsoleLocal("BPQ32 Reconfiguration Complete\n");
+ }
+}
+
+void UnSemaphored100msCode()
+{
+
+ if (Redirected == 0)
+ ConTermPoll();
+
+ if (NUMBEROFTNCPORTS)
+ TNCTimer();
+
+ if (AGWActive)
+ Poll_AGW();
+
+ DRATSPoll();
+ RHPPoll();
+
+ if (ReportTimer)
+ {
+ ReportTimer--;
+
+ if (ReportTimer == 0)
+ {
+ ReportTimer = REPORTINTERVAL;
+ SendLocation();
+ }
+ }
+
+ HTTPTimer();
+
+ if (RunChat)
+ {
+ ChatPollStreams();
+ ChatTrytoSend();
+
+ if (Slowtimer > 100) // 10 secs
+ {
+ ChatTimer();
+ }
+ }
+
+ if (RunMail)
+ {
+ PollStreams();
+
+ if ((Slowtimer % 20) == 0)
+ FWDTimerProc();
+
+ if (Slowtimer > 100) // 10 secs
+ {
+ struct tm * tm;
+
+ TCPTimer();
+ BBSSlowTimer();
+
+ if (MaintClock < NOW)
+ {
+ while (MaintClock < NOW) // in case large time step
+ MaintClock += MaintInterval * 3600;
+
+ Debugprintf("|Enter HouseKeeping");
+ DoHouseKeeping(FALSE);
+ }
+
+ if (APIClock < NOW)
+ {
+ SendBBSDataToPktMap();
+ APIClock = NOW + 7200; // Every 2 hours
+ }
+
+
+ tm = gmtime(&NOW);
+
+ if (tm->tm_wday == 0) // Sunday
+ {
+ if (GenerateTrafficReport && (LastTrafficTime + 86400) < NOW)
+ {
+ CreateBBSTrafficReport();
+ LastTrafficTime = NOW;
+ }
+ }
+ }
+
+ TCPFastTimer();
+ TrytoSend();
+ }
+ if (Slowtimer > 100)
+ Slowtimer = 0;
+}
+
+#ifdef WIN32
+
+#include "DbgHelp.h"
+
+HANDLE process;
+
+
+
+
+int inErrorhandling = 0;
+
+LONG WINAPI UnhandledExcepFilter(PEXCEPTION_POINTERS pExcepPointers)
+{
+ DWORD dwDisplacement;
+ IMAGEHLP_LINE64 line;
+ char * fptr;
+
+
+ time_t T;
+ struct tm * tm;
+
+ char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
+ PSYMBOL_INFO symbol = (PSYMBOL_INFO)buffer;
+
+ symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
+ symbol->MaxNameLen = MAX_SYM_NAME;
+
+
+ T = time(NULL);
+ tm = gmtime(&T);
+
+ if (inErrorhandling)
+ {
+ MessageBox(NULL,"Program Error in error handler - program closing. See Debug Log for details","BPQ32",MB_ICONSTOP);
+
+ exit(0);
+ }
+
+ inErrorhandling = 1;
+
+ if(pExcepPointers->ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C)
+ return EXCEPTION_CONTINUE_EXECUTION;
+
+ SymFromAddr( process, ((DWORD)pExcepPointers->ExceptionRecord->ExceptionAddress), 0, symbol );
+
+ Debugprintf("\r\n\r\nProgram error trapped at %02d:%02d:%02d\r\n", tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+ SymGetLineFromAddr64(process, (DWORD)pExcepPointers->ExceptionRecord->ExceptionAddress, &dwDisplacement, &line);
+
+ if (line.FileName)
+ {
+ fptr = line.FileName + (int)strlen(line.FileName); // remove path
+ while (*fptr != '\\' && *fptr != '/')
+ fptr--;
+
+ fptr++;
+
+ Debugprintf("In Procedure %s - %s Line %d Addr %p\r\n", symbol->Name, fptr, line.LineNumber, symbol->Address );
+ }
+
+ printStack();
+
+ CloseDebugLog();
+ MessageBox(NULL,"Program Error - program closing. See Debug Log for details","BPQ32",MB_ICONSTOP);
+
+ exit(0);
+}
+
+
+#endif
int main(int argc, char * argv[])
{
@@ -838,8 +1252,18 @@ int main(int argc, char * argv[])
}
}
+ process = GetCurrentProcess();
+
+ SymSetOptions(SYMOPT_LOAD_LINES);
+ SymInitialize(process, NULL, TRUE );
+
+ AddVectoredExceptionHandler(1, UnhandledExcepFilter);
+
+
#else
+ state = backtrace_create_state(argv[0], 0, error_callback, NULL);
+
signal(SIGSEGV, segvhandler);
signal(SIGABRT, abrthandler);
@@ -866,7 +1290,8 @@ int main(int argc, char * argv[])
printf("%d", sizeof(struct DEST_LIST));
- srand(time(NULL));
+ NOW = time(NULL);
+ srand(NOW);
// look for optarg format parameters
@@ -1432,270 +1857,25 @@ int main(int argc, char * argv[])
while (KEEPGOING)
{
- Sleep(100);
- GetSemaphore(&Semaphore, 2);
-
- if (QCOUNT < 10)
- {
- if (CLOSING == FALSE)
- FindLostBuffers();
- CLOSING = TRUE;
- }
-
- if (CLOSING)
- {
- if (RunChat)
- {
- CloseChat();
- RunChat = FALSE;
- }
-
- if (RunMail)
- {
- int BPQStream, n;
-
- RunMail = FALSE;
+ Sleep(10);
- for (n = 0; n < NumberofStreams; n++)
- {
- BPQStream = Connections[n].BPQStream;
-
- if (BPQStream)
- {
- SetAppl(BPQStream, 0, 0);
- Disconnect(BPQStream);
- DeallocateStream(BPQStream);
- }
- }
-
-// SaveUserDatabase();
- SaveMessageDatabase();
- SaveBIDDatabase();
- SaveConfig(ConfigName);
- SaveRestartData();
- }
-
- KEEPGOING--; // Give time for links to close
- setbuf(stdout, NULL);
- printf("Closing... %d \r", KEEPGOING);
- }
-
-
- if (RigReconfigFlag)
- {
- RigReconfigFlag = FALSE;
- Rig_Close();
- Sleep(2000); // Allow CATPTT threads to close
- RigActive = Rig_Init();
-
- Consoleprintf("Rigcontrol Reconfiguration Complete");
- }
+ NOW = time(NULL);
- if (APRSReconfigFlag)
- {
- APRSReconfigFlag = FALSE;
- APRSClose();
- APRSActive = Init_APRS();
-
- Consoleprintf("APRS Reconfiguration Complete");
- }
+ GetSemaphore(&Semaphore, 2);
- if (ReconfigFlag)
+ if (TIMERINTERRUPT()) // Run background code
{
- int i;
- BPQVECSTRUC * HOSTVEC;
- PEXTPORTDATA PORTVEC=(PEXTPORTDATA)PORTTABLE;
-
- ReconfigFlag = FALSE;
-
-// SetupBPQDirectory();
-
- WritetoConsoleLocal("Reconfiguring ...\n\n");
- OutputDebugString("BPQ32 Reconfiguring ...\n");
-
-
- for (i=0;i<NUMBEROFPORTS;i++)
- {
- if (PORTVEC->PORTCONTROL.PORTTYPE == 0x10) // External
- {
- if (PORTVEC->PORT_EXT_ADDR)
- {
-// SaveWindowPos(PORTVEC->PORTCONTROL.PORTNUMBER);
-// SaveAXIPWindowPos(PORTVEC->PORTCONTROL.PORTNUMBER);
-// CloseDriverWindow(PORTVEC->PORTCONTROL.PORTNUMBER);
- PORTVEC->PORT_EXT_ADDR(5,PORTVEC->PORTCONTROL.PORTNUMBER, NULL); // Close External Ports
- }
- }
- PORTVEC->PORTCONTROL.PORTCLOSECODE(&PORTVEC->PORTCONTROL);
- PORTVEC=(PEXTPORTDATA)PORTVEC->PORTCONTROL.PORTPOINTER;
- }
-
- IPClose();
- APRSClose();
- Rig_Close();
- CloseTNCEmulator();
-
- if (AGWActive)
- AGWAPITerminate();
-
- WL2KReports = NULL;
-
-// Sleep(2000);
-
- Consoleprintf("G8BPQ AX25 Packet Switch System Version %s %s", TextVerstring, Datestring);
- Consoleprintf(VerCopyright);
-
- Start();
-
- NETROMTCPResolve();
-
- INITIALISEPORTS();
-
- SetApplPorts();
-
- GetUIConfig();
-
- FreeConfig();
-
- for (i=1; i<68; i++) // Include Telnet, APRS, IP Vec
- {
- HOSTVEC=&BPQHOSTVECTOR[i-1];
-
- HOSTVEC->HOSTTRACEQ=0;
-
- if (HOSTVEC->HOSTSESSION !=0)
- {
- // Had a connection
-
- HOSTVEC->HOSTSESSION=0;
- HOSTVEC->HOSTFLAGS |=3; // Disconnected
-
-// PostMessage(HOSTVEC->HOSTHANDLE, BPQMsg, i, 4);
- }
- }
-
- OpenReportingSockets();
-
- WritetoConsoleLocal("\n\nReconfiguration Complete\n");
-
- if (IPRequired) IPActive = Init_IP();
-
- APRSActive = Init_APRS();
-
- if (ISPort == 0)
- IGateEnabled = 0;
-
- RigActive = Rig_Init();
-
- if (NUMBEROFTNCPORTS)
- {
- FreeSemaphore(&Semaphore);
- InitializeTNCEmulator();
- GetSemaphore(&Semaphore, 2);
- }
+ // 100mS has elapsed
+ Semaphored100msCode();
+ Slowtimer++;
+
FreeSemaphore(&Semaphore);
- AGWActive = AGWAPIInit();
- GetSemaphore(&Semaphore, 2);
-
- OutputDebugString("BPQ32 Reconfiguration Complete\n");
- }
-
- if (IPActive) Poll_IP();
- if (RigActive) Rig_Poll();
- if (APRSActive) Poll_APRS();
- CheckWL2KReportTimer();
-
- TIMERINTERRUPT();
-
- FreeSemaphore(&Semaphore);
-
- if (Redirected == 0)
- ConTermPoll();
-
- if (NUMBEROFTNCPORTS)
- TNCTimer();
-
- if (AGWActive)
- Poll_AGW();
-
- DRATSPoll();
- RHPPoll();
-
- HTTPTimer();
-
- if (ReportTimer)
- {
- ReportTimer--;
-
- if (ReportTimer == 0)
- {
- ReportTimer = REPORTINTERVAL;
- SendLocation();
- }
- }
-
- Slowtimer++;
-
- if (RunChat)
- {
- ChatPollStreams();
- ChatTrytoSend();
-
- if (Slowtimer > 100) // 10 secs
- {
- ChatTimer();
- }
- }
-
- if (RunMail)
- {
- PollStreams();
-
- if ((Slowtimer % 20) == 0)
- FWDTimerProc();
-
- if (Slowtimer > 100) // 10 secs
- {
- time_t NOW = time(NULL);
- struct tm * tm;
-
- TCPTimer();
- BBSSlowTimer();
- if (MaintClock < NOW)
- {
- while (MaintClock < NOW) // in case large time step
- MaintClock += MaintInterval * 3600;
-
- Debugprintf("|Enter HouseKeeping");
- DoHouseKeeping(FALSE);
- }
-
- if (APIClock < NOW)
- {
- SendBBSDataToPktMap();
- APIClock = NOW + 7200; // Every 2 hours
- }
-
-
- tm = gmtime(&NOW);
-
- if (tm->tm_wday == 0) // Sunday
- {
- if (GenerateTrafficReport && (LastTrafficTime + 86400) < NOW)
- {
- CreateBBSTrafficReport();
- LastTrafficTime = NOW;
- }
- }
- }
- TCPFastTimer();
- TrytoSend();
+ UnSemaphored100msCode();
}
-
- if (Slowtimer > 100)
- Slowtimer = 0;
+ else
+ FreeSemaphore(&Semaphore);
}
hookNodeClosing("Shutdown");