This change introduces a new procedure GNAT.Sockets.Set_Close_On_Exec, allowing users to indicate that a given socket should not be inherited by spawned processes (on platforms where this is supported).
Tested on x86_64-pc-linux-gnu, committed on trunk 2013-04-23 Thomas Quinot <qui...@adacore.com> * g-socket.adb, g-socket.ads (Set_Close_On_Exec): New subprogram.
Index: g-socket.adb =================================================================== --- g-socket.adb (revision 198175) +++ g-socket.adb (working copy) @@ -2211,6 +2211,24 @@ Insert_Socket_In_Set (Item.Set'Access, C.int (Socket)); end Set; + ----------------------- + -- Set_Close_On_Exec -- + ----------------------- + + procedure Set_Close_On_Exec + (Socket : Socket_Type; + Close_On_Exec : Boolean; + Status : out Boolean) + is + function C_Set_Close_On_Exec + (Socket : Socket_Type; Close_On_Exec : C.int) + return C.int; + pragma Import (C, C_Set_Close_On_Exec, "__gnat_set_close_on_exec"); + + begin + Status := C_Set_Close_On_Exec (Socket, Boolean'Pos (Close_On_Exec)) = 0; + end Set_Close_On_Exec; + ---------------------- -- Set_Forced_Flags -- ---------------------- Index: g-socket.ads =================================================================== --- g-socket.ads (revision 198175) +++ g-socket.ads (working copy) @@ -979,6 +979,17 @@ -- socket. Count is set to the count of transmitted stream elements. Flags -- allow control over transmission. + procedure Set_Close_On_Exec + (Socket : Socket_Type; + Close_On_Exec : Boolean; + Status : out Boolean); + -- When Close_On_Exec is True, mark Socket to be closed automatically when + -- a new program is executed by the calling process (i.e. prevent Socket + -- from being inherited by child processes). When Close_On_Exec is False, + -- mark Socket to not be closed on exec (i.e. allow it to be inherited). + -- Status is False if the operation could not be performed, or is not + -- supported on the target platform. + procedure Set_Socket_Option (Socket : Socket_Type; Level : Level_Type := Socket_Level;