-- -- -------------------------------------------------------------------------------- -- -- OSI_Processes -- -- This package defines interfaces for executing and passing -- parameters to processes and reading attributes of the current -- process. -- -- -- -- -- Gerardo A. Colon -- 11 July 1990 -- -- Science Applications International Corporation --
311 Park Place Boulevard, Suite 360 --
Clearwater, Florida 34619 -- -- Developed for the STARS program under task S40. -- -- -- -- -- Dependencies => -- ( Operating_System => AIX , -- Compiler => None , -- Device => None ) ; -- -- -------------------------------------------------------------------------------- with C_String_Utilities ; with Interface_Definitions ; with OSI_Error_Handler ; with OSI_Exceptions ; with Runtime_Support_Library ; use Interface_Definitions ; use Runtime_Support_Library ; pragma Elaborate ( C_String_Utilities ) ; pragma Elaborate ( Interface_Definitions ) ; pragma Elaborate ( OSI_Error_Handler ) ; pragma Elaborate ( OSI_Exceptions ) ; pragma Elaborate ( Runtime_Support_Library ) ; pragma Page ; -------------------------------------------------------------------------------- -- package OSI_Processes (body). -------------------------------------------------------------------------------- package body OSI_Processes is Null_String : C_String_Utilities.String_Pointer ; -- -- This constant defines a null C string. -- -------------------------------------------------------------------------------- -- Local Subprograms. -------------------------------------------------------------------------------- procedure Assert ( The_Filename : in OSI_String ) is -------------------------------------------------------------------------------- -- -- Assert -- -- This procedure asserts that the filename given by the -- parameter The_Filename is a correct filename. -- -- Filename_Syntax_Error => -- The_Filename contains one or more characters not supported -- by the implementation for a filename. -- Filename_Too_Long => -- The length of The_Filename exceeds its maximum. -- -- -------------------------------------------------------------------------------- begin -- Assert -- Check that the length is not greater the its limit. if The_Filename'Length > Portable_Pathname_Limit then raise OSI_Exceptions.Filename_Too_Long ; end if ; -- for The_Index in The_Filename'Range loop case The_Filename ( The_Index ) is when 'a' .. 'z' => null ; when 'A' .. 'Z' => null ; when '0' .. '9' => null ; when '-' => if The_Index = The_Filename'First then raise OSI_Exceptions.Filename_Syntax_Error ; end if ; when '.' | '_' | '/' => null ; when others => raise OSI_Exceptions.Filename_Syntax_Error ; end case ; end loop ; end Assert ; -------------------------------------------------------------------------------- -- External Subprograms. -------------------------------------------------------------------------------- procedure Invoke_Process ( File_Name : in OSI_String ; Parameter_List : in OSI_String ) is -------------------------------------------------------------------------------- -- -- Invoke_Process -- -- For a complete description of this subprogram see the -- specification of this package. -- -- For a complete description of the exceptions raised by this -- subprogram see the specification of this package. -- -- -------------------------------------------------------------------------------- Return_Value : Interface_Definitions.Interface_Integer ; Return_Process_ID : Process_ID ; The_File_String : constant String := To_String ( File_Name ) & ASCII.Nul ; The_Parameter_String : constant String := To_String ( Parameter_List ) & ASCII.Nul ; The_Process_ID : Process_ID ; The_Rusage_Link : Rusage_Record_Link ; The_Status_Link : Status_Type_Link ; The_Options : Interface_Definitions.Interface_Integer := W_No_Hang; begin -- Invoke_Process Assert ( The_Filename => File_Name ) ; -- Create a new process. The_Process_ID := Fork ; -- Check the returned process id. if The_Process_ID < 0 then -- Fork was unsuccessful. OSI_Error_Handler.Map_Last_Error ; elsif The_Process_ID > 0 then -- This is the child process executing. Execute the program. Return_Value := Execvp ( File => The_File_String'Address , Argv => ( 1 => The_File_String'Address , 2 => The_Parameter_String'Address , 3 => Null_String ) ) ; else -- This is the parent process executing. -- Wait for the termination of the child process. Return_Process_ID := Wait3 ( Status => The_Status_Link , Options => The_Options , Rusage => The_Rusage_Link ) ; end if ; -- Check the return value. if Return_Value < 0 then -- Unsuccessful execution. OSI_Error_Handler.Map_Last_Error ; end if ; end Invoke_Process ; function Parameter_List return String is -------------------------------------------------------------------------------- -- -- Parameter_List -- -- For a complete description of this subprogram see the -- specification of this package. -- -- For a complete description of the exceptions raised by this -- subprogram see the specification of this package. -- -- -------------------------------------------------------------------------------- begin -- Parameter_List return "" ; end Parameter_List ; function Environment_Value_Of ( Name : in OSI_String ) return String is -------------------------------------------------------------------------------- -- -- Environment_Value_Of -- -- For a complete description of this subprogram see the -- specification of this package. -- -- For a complete description of the exceptions raised by this -- subprogram see the specification of this package. -- -- -------------------------------------------------------------------------------- The_Name_String : constant String := To_String ( Name ) & ASCII.Nul ; begin -- Environment_Value_Of return C_String_Utilities.String_Of ( Getenv ( Name => The_Name_String'Address ) ) ; end Environment_Value_Of ; function Get_Effective_User_Login_Name return String is -------------------------------------------------------------------------------- -- -- Get_Effective_User_Login_Name -- -- For a complete description of this subprogram see the -- specification of this package. -- -- For a complete description of the exceptions raised by this -- subprogram see the specification of this package. -- -- -------------------------------------------------------------------------------- begin -- Get_Effective_User_Login_Name return C_String_Utilities.String_Of ( Getlogin ) ; end Get_Effective_User_Login_Name ; end OSI_Processes ; --