Linux MIS daemon (currently broken for some reason)

This commit is contained in:
mysticbbs 2012-03-16 20:05:48 -04:00
parent 79c447c7fb
commit fbc65082c3
2 changed files with 73 additions and 23 deletions

View File

@ -26,10 +26,13 @@ Program MIS;
Uses Uses
{$IFDEF DEBUG} {$IFDEF DEBUG}
HeapTrc, HeapTrc,
LineInfo,
{$ENDIF} {$ENDIF}
{$IFDEF UNIX} {$IFDEF UNIX}
cThreads, cThreads,
BaseUnix,
{$ENDIF} {$ENDIF}
DOS,
m_Output, m_Output,
m_Input, m_Input,
m_DateTime, m_DateTime,
@ -56,7 +59,7 @@ Const
Var Var
Console : TOutput; Console : TOutput;
Input : TInput; Keyboard : TInput;
TelnetServer : TServerManager; TelnetServer : TServerManager;
FTPServer : TServerManager; FTPServer : TServerManager;
POP3Server : TServerManager; POP3Server : TServerManager;
@ -67,16 +70,22 @@ Var
TopPage : Integer; TopPage : Integer;
BarPos : Integer; BarPos : Integer;
NodeData : TNodeData; NodeData : TNodeData;
DaemonMode : Boolean = False;
{$I MIS_ANSIWFC.PAS} {$I MIS_ANSIWFC.PAS}
Procedure ReadConfiguration; Procedure ReadConfiguration;
Var Var
FileConfig : TBufFile; FileConfig : TBufFile;
DatLoc : String;
Begin Begin
DatLoc := GetEnv('mysticbbs');
If DatLoc <> '' Then DatLoc := DirSlash(DatLoc);
FileConfig := TBufFile.Create(SizeOf(RecConfig)); FileConfig := TBufFile.Create(SizeOf(RecConfig));
If Not FileConfig.Open('mystic.dat', fmOpen, fmReadWrite + fmDenyNone, SizeOf(RecConfig)) Then Begin If Not FileConfig.Open(DatLoc + 'mystic.dat', fmOpen, fmReadWrite + fmDenyNone, SizeOf(RecConfig)) Then Begin
WriteLn; WriteLn;
WriteLn ('ERROR: Unable to read MYSTIC.DAT. This file must exist in the same'); WriteLn ('ERROR: Unable to read MYSTIC.DAT. This file must exist in the same');
WriteLn ('directory as MIS'); WriteLn ('directory as MIS');
@ -90,6 +99,8 @@ Begin
WriteLn('ERROR: Data files are not current and must be upgraded.'); WriteLn('ERROR: Data files are not current and must be upgraded.');
Halt(1); Halt(1);
End; End;
DirChange(bbsConfig.SystemPath);
End; End;
Procedure ReadChatData; Procedure ReadChatData;
@ -114,7 +125,7 @@ Begin
NodeData.SetNodeInfo(NI.Num, NI); NodeData.SetNodeInfo(NI.Num, NI);
End; End;
End; End;
Close (ChatFile); Close (ChatFile);
End; End;
End; End;
@ -290,10 +301,10 @@ Begin
Term.ProcessBuf(Buffer, Res); Term.ProcessBuf(Buffer, Res);
Until Res <> BufferSize; Until Res <> BufferSize;
End Else End Else
If Input.KeyPressed Then Begin If Keyboard.KeyPressed Then Begin
Ch := Input.ReadKey; Ch := Keyboard.ReadKey;
Case Ch of Case Ch of
#00 : Case Input.ReadKey of #00 : Case Keyboard.ReadKey of
#45 : Break; #45 : Break;
#71 : Client.WriteStr(#27 + '[H'); #71 : Client.WriteStr(#27 + '[H');
#72 : Client.WriteStr(#27 + '[A'); #72 : Client.WriteStr(#27 + '[A');
@ -326,6 +337,32 @@ Begin
SwitchFocus; SwitchFocus;
End; End;
{$IFDEF UNIX}
Procedure ExecuteDaemon;
Var
PID : TPID;
SID : TPID;
offset:longint;
Begin
PID := fpFork;
If PID < 0 Then Halt(1);
If PID > 0 Then Halt(0);
SID := fpSetSID;
If SID < 0 Then Halt(1);
Close (Input);
Close (Output);
//CLOSE STDERR
Repeat
WaitMS(60000);
Until False;
End;
{$ENDIF}
Const Const
WinTitle = 'Mystic Internet Server'; WinTitle = 'Mystic Internet Server';
@ -333,6 +370,10 @@ Var
Count : Integer; Count : Integer;
Started : Boolean; Started : Boolean;
Begin Begin
{$IFDEF UNIX}
DaemonMode := Pos('-D', strUpper(ParamStr(1))) > 0;
{$ENDIF}
Randomize; Randomize;
{$IFDEF DEBUG} {$IFDEF DEBUG}
@ -346,11 +387,14 @@ Begin
POP3Server := NIL; POP3Server := NIL;
Started := False; Started := False;
Console := TOutput.Create(True); NodeData := TNodeData.Create(bbsConfig.INetTNNodes);
Input := TInput.Create;
NodeData := TNodeData.Create(bbsConfig.INetTNNodes);
Console.SetWindowTitle(WinTitle); If Not DaemonMode Then Begin
Console := TOutput.Create(True);
Keyboard := TInput.Create;
Console.SetWindowTitle(WinTitle);
End;
If bbsConfig.InetTNUse Then Begin If bbsConfig.InetTNUse Then Begin
TelnetServer := TServerManager.Create(bbsConfig, bbsConfig.InetTNPort, bbsConfig.INetTNNodes, NodeData, @CreateTelnet); TelnetServer := TServerManager.Create(bbsConfig, bbsConfig.InetTNPort, bbsConfig.INetTNNodes, NodeData, @CreateTelnet);
@ -398,13 +442,14 @@ Begin
End; End;
If Not Started Then Begin If Not Started Then Begin
Console.ClearScreen; If Not DaemonMode Then Begin
Console.ClearScreen;
Console.WriteLine('ERROR: No servers are configured as active. Run MYSTIC -CFG to configure'); Console.WriteLine('ERROR: No servers are configured as active. Run MYSTIC -CFG to configure');
Console.WriteLine('Internet server options.'); Console.WriteLine('Internet server options.');
End;
NodeData.Free; NodeData.Free;
Input.Free; Keyboard.Free;
Console.Free; Console.Free;
Halt(10); Halt(10);
@ -412,15 +457,20 @@ Begin
Count := 0; Count := 0;
DrawStatusScreen; If Not DaemonMode Then Begin
DrawStatusScreen;
FocusCurrent := FocusMax;
SwitchFocus;
End;
FocusCurrent := FocusMax; {$IFDEF UNIX}
SwitchFocus; If DaemonMode Then ExecuteDaemon;
{$ENDIF}
Repeat Repeat
If Input.KeyWait(1000) Then If Keyboard.KeyWait(1000) Then
Case Input.ReadKey of Case Keyboard.ReadKey of
#00 : Case Input.ReadKey of #00 : Case Keyboard.ReadKey of
#72 : If BarPos > TopPage Then Begin #72 : If BarPos > TopPage Then Begin
Dec(BarPos); Dec(BarPos);
UpdateConnectionList; UpdateConnectionList;
@ -502,7 +552,7 @@ Begin
Console.WriteLine (' (DONE)'); Console.WriteLine (' (DONE)');
NodeData.Free; NodeData.Free;
Input.Free; Keyboard.Free;
Console.Free; Console.Free;
Halt(255); Halt(255);

View File

@ -166,7 +166,7 @@ Begin
Repeat Repeat
NewClient := Server.WaitConnection; NewClient := Server.WaitConnection;
If NewClient = NIL Then Break; // time to shutdown the server... If NewClient = NIL Then Break; // time to shutdown the server...
If (ClientMax > 0) And (ClientActive >= ClientMax) Then Begin If (ClientMax > 0) And (ClientActive >= ClientMax) Then Begin
Inc (ClientRefused); Inc (ClientRefused);