Fix TLogger.AddStdLine to work with Wine 1.6
authorMegaBrutal <code+git@megabrutal.com>
Wed, 17 Oct 2018 15:30:30 +0000 (17:30 +0200)
committerMegaBrutal <code+git@megabrutal.com>
Wed, 17 Oct 2018 15:30:30 +0000 (17:30 +0200)
Wine 1.6 gives a standard output handle to the service process,
albeit all writes to it fails. Because of this, TLogger.AddStdLine
did not even write to the log file due to short-circuit evaluation.
Now I made sure to attempt both stdout and logfile writes.

Native Windows doesn't provide an stdout handle for service processes
(GetStdHandle returns 0), in which case MgSMTP detects it has no
stdout and redirects its output to mgsmtp_stdout.log. Wine 3.0 behaves
the same, so I deemed the Wine 1.6 behaviour a bug. Therefore, I find
this quick fix sufficient - there is no need to bother with Wine 1.6
compatibility any further, e.g. by checking if Wine 1.6 gave a writable
stdout handle or not. Users of MgSMTP on Wine are rather suggested to
update to Wine 3.0.

modified:   Log.pas
modified:   MgSMTP.pas

Log.pas
MgSMTP.pas

diff --git a/Log.pas b/Log.pas
index 98001213fde6ed53527bc56414f5d05a01ac29c3..46538b234fd0fb3bda1adf915d78c2d81dd7c43b 100644 (file)
--- a/Log.pas
+++ b/Log.pas
@@ -1,6 +1,6 @@
 {
    MegaBrutal's SMTP Server (MgSMTP)
-   Copyright (C) 2010-2014 MegaBrutal
+   Copyright (C) 2010-2018 MegaBrutal
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
@@ -146,14 +146,20 @@ end;
 
 function TLogger.AddStdLine(Line: string): boolean;
 { Log message to both stdout and smtp.log. }
+var outresult, logresult: boolean;
 begin
-   Result:= Out.AddLine(Line) and AddLine(Line);
+   outresult:= Out.AddLine(Line);
+   logresult:= AddLine(Line);
+   Result:= outresult and logresult;
 end;
 
 function TLogger.AddStdLine(Agent, Line: string): boolean;
 { Log message to both stdout and smtp.log. }
+var outresult, logresult: boolean;
 begin
-   Result:= Out.AddLine(Agent, Line) and AddLine(Agent, Line);
+   outresult:= Out.AddLine(Agent, Line);
+   logresult:= AddLine(Agent, Line);
+   Result:= outresult and logresult;
 end;
 
 
index 79821d9ca761c9eff4a5676df38ee630d9f24813..438f0b628423b008181a7c5785b214d8d691b5cc 100644 (file)
@@ -49,7 +49,7 @@ const
      document what bugfix/feature are you testing with the actual build.
      This will be logged to help you differentiate outputs of subsequent
      builds in your logs. If left empty, it won't be added to the logs. }
-   DEVCOMMENT  =  'ListenAddress';
+   DEVCOMMENT  =  'Wine 1.6 AddStdLine fix';
 
 var