Rombobjörn

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Persson <bjorn@rombobjörn.se>2013-02-18 02:03:31 +0100
committerBjörn Persson <bjorn@rombobjörn.se>2013-02-18 02:03:31 +0100
commite60a03a6e27467326f729c40d08c82f9a2667984 (patch)
tree060e6007fab8bbc41c2ef14dc2d0746a442fdfd6
parent833e03605f4fdea27e05ed360934bfd378d023e2 (diff)
Use Open_Socket.
-rw-r--r--test/test_milter_package.adb62
1 files changed, 21 insertions, 41 deletions
diff --git a/test/test_milter_package.adb b/test/test_milter_package.adb
index fddb5e7..6a8becc 100644
--- a/test/test_milter_package.adb
+++ b/test/test_milter_package.adb
@@ -13,9 +13,7 @@ with System_Log; use System_Log;
with Ada.Unchecked_Deallocation;
with Interfaces.C;
with Ada.Exceptions;
-with Ada.Directories;
with Ada.Text_IO;
-with GNAT.OS_Lib;
package body Test_Milter_Package is
@@ -31,8 +29,6 @@ package body Test_Milter_Package is
procedure Free is new Ada.Unchecked_Deallocation(Message_Data,
Message_Data_Pointer);
- Socket_Obstructed : exception;
-
function Private_Data(Context : SMFICTX_Pointer) return Message_Data_Pointer
is
@@ -215,48 +211,21 @@ package body Test_Milter_Package is
end Handle_Close;
- procedure Clean_And_Set_Socket is
- Socket_Name : constant String := "/var/spool/test_milter/milter_socket";
- function umask(mask : Interfaces.C.unsigned) return Interfaces.C.unsigned;
- pragma import(C, umask);
- mask : Interfaces.C.unsigned; -- dummy to soak up the result from umask
- pragma Unreferenced(mask);
- begin
- -- Delete the socket file if it exists, assuming it was left behind
- -- because of a crash.
- if Ada.Directories.Exists(Socket_Name) then
- Log(Warning, Socket_Name & " exists. Deleting it.");
- -- GNAT's implementation of Ada.Directories.Delete_File calls a
- -- function named Is_Regular_File and refuses to delete a socket file,
- -- so GNAT.OS_Lib.Delete_File must be used instead.
- -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56055
- declare
- OK : Boolean;
- begin
- GNAT.OS_Lib.Delete_File(Socket_Name, OK);
- if not OK then
- raise Socket_Obstructed with
- Socket_Name & " can't be created because a file with that " &
- "name exists and can't be deleted.";
- end if;
- end;
- end if;
- -- Clear the permissions mask to allow the MTA to use the socket.
- mask := umask(0);
- -- Tell the milter library where to create the socket.
- Set_Socket("unix:" & Socket_Name);
- end Clean_And_Set_Socket;
-
-
function Run return Ada.Command_Line.Exit_Status is
use Ada.Exceptions;
use Berkeley_Exit_Codes;
use Ada.Text_IO;
+
+ function umask(mask : Interfaces.C.unsigned) return Interfaces.C.unsigned;
+ pragma Import(C, umask);
+ Dummy : Interfaces.C.unsigned; -- to soak up the result from umask
+ pragma Unreferenced(Dummy);
+
+ Socket_Name : constant String := "/var/spool/test_milter/milter_socket";
begin
Log(Info,
"Starting. Milter API version " & Milter_API.Binding_Version_String &
", Libmilter version " & Milter_API.Libmilter_Version_String);
- Clean_And_Set_Socket;
Register(Name => "test_milter/libmilter",
Connected => Handle_Connection'Access,
Helo => Handle_Helo'Access,
@@ -270,6 +239,20 @@ package body Test_Milter_Package is
End_Of_Message => Handle_End_Of_Message'Access,
Aborted => Handle_Abort'Access,
Closed => Handle_Close'Access);
+ -- Clear the permissions mask to allow the MTA to use the socket.
+ Dummy := umask(0);
+ -- Tell Libmilter where to create the socket.
+ Set_Socket("unix:" & Socket_Name);
+ -- Open the socket. Delete any existing socket, assuming it was left
+ -- behind because of a crash.
+ begin
+ Open_Socket(Remove_Old_Socket => True);
+ exception
+ when Milter_API.Failure =>
+ -- Libmilter has already logged sufficient error messages.
+ return Cannot_Create_File;
+ end;
+ -- Hand over control to Libmilter.
Milter_API.Main;
return Ada.Command_Line.Success;
exception
@@ -279,9 +262,6 @@ package body Test_Milter_Package is
when E : Milter_API.Unknown_Error =>
Log(Error, Exception_Message(E));
return Software_Error;
- when E : Socket_Obstructed =>
- Log(Error, Exception_Message(E));
- return Cannot_Create_File;
when E : others =>
Put_Line(Standard_Error, Exception_Information(E));
Log(Error,