Opsys.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
-------------------------> GNU Sather - sourcefile <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute and/or modify it under the terms of the GNU Library General --
-- Public License (LGPL) as published by the Free Software Foundation; --
-- either version 2 of the license, or (at your option) any later version. --
-- This library is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details. --
-- The license text is also available from: Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
--------------> Please email comments to <bug-sather@gnu.org> <--------------
class OPSYS < $OPERATING_SYS
class OPSYS < $OPERATING_SYS is
-- This class contains only those functions necessary to provide an
-- interface to the underlying operating system by a Sather program using
-- only the standard library. This excludes services provided by other
-- interface classes which model specific OS features.
-- This version is defined for Posix conformant unix implementations!
-- Reference should be made to Posix specifications for further detail.
-- Version 1.2 Oct 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 8 Nov 96 kh Original from Sather unix class, etc.
-- 18 Apr 97 kh Reorganised for OS commonality!
-- 15 Oct 98 kh Added is_super_user, pre/post conditions
private const Super_User : CARD := 0 ; -- standard value for Posix
system(
cli_cmd : STR
) : CARD
pre ~void(cli_cmd) -- and SHOULD be a valid cli_cmd!
post (result > 0)
is
-- This routine provides a service to invoke an OS-dependent command
-- line interpreter. The returned value is zero if successful, otherwise
-- an OS-dependent number indicating in an OS-dependent manner what caused
-- the failure.
res : INT := OS_SYS::system(cli_cmd.array_ptr) ;
if res.is_zero then
return 0
else
return OS_SYS::error_code
end
end ;
get_env(
var_name : STR
) : STR
pre ~void(var_name)
post true
is
-- This routine returns the value of the environment variable named in
-- the parameter, if it exists, otherwise void.
res : REFERENCE := OS_SYS::getenv(var_name.array_ptr) ;
if void(res) then
return void
else
return STR::create_from_external_string(res,var_name.index_lib)
end
end ;
resource_location(
lib : LIBCHARS
) : STR
pre true
post ~void(result) -- otherwise an exception has been raised!
is
-- This routine returns an encoding of the dynamic resource path for
-- all Sather libraries, the first element of which is expected to be
-- the standard language library.
path : STR := get_env(lib.culture.Home_ref) ;
if void(path) then -- can't find resources!
SYS_ERROR::create.error(self,SYS_EXCEPT::Bad_Environment,
lib.culture.Home_ref) ;
return void -- to keep compiler happy!
else
return path
end
end ;
-- The next four routines return the user and project
-- identities as known to the operating system indicated by their
-- name. Since these are OS-dependent codes, they are only of use
-- for interaction with the operating system.
get_user_id : USER is
return USER::create(OS_SYS::getuid)
end ;
get_effective_user_id : USER is
return USER::create(OS_SYS::geteuid)
end ;
get_project_id : GROUP is
return GROUP::create(OS_SYS::getgid)
end ;
get_effective_project_id : GROUP is
return GROUP::create(OS_SYS::getegid)
end ;
is_super_user : BOOL is
-- This predicate returns true if and only if the current program is
-- being executed by the effective super-user, otherwise false.
return OS_SYS::geteuid = Super_User
end ;
get_pid : CARD is
-- This routine obtains the process identity from the execution
-- environment.
return OS_SYS::get_pid
end ;
exec(
prog_name : STR,
argv : ARRAY{STR},
envp : ARRAY{STR}
) : CARD
pre ~void(prog_name)
post (result > 0) -- a failure -- otherwise never returns!
is
-- This routine takes its first argument to be the name of an executable
-- file. This is invoked and passed the second and third parameters as
-- arguments and environment variables respectively. If this routine
-- returns then an error will have occurred. The kind of error is provided
-- in the returned value in an OS-dependent way.
args : REFERENCE := void ;
if ~void(argv) then
args := STR::concat_all(argv).array_ptr
end ;
environment : REFERENCE := void ;
if ~void(envp) then
environment := STR::concat_all(envp).array_ptr
end ;
res : INT := OS_SYS::execve(prog_name.array_ptr,args,environment) ;
-- If code gets here then an error has occurred!
return OS_SYS::error_code
end ;
exit(
code : INT
)
pre true
post false -- This never returns!
is
-- This routine performs OS-dependent termination action, which may
-- include passing 'code' to the invoker.
OS_SYS::exit(code)
end ;
abort
pre true
post false -- This never returns!
is
-- This routine performs the OS-dependent actions associated with
-- stopping program execution as quickly as possible.
OS_SYS::abort
end ;
end ; -- OPSYS
external class OS_SYS
external class OS_SYS is
-- This is the interface class to the operating system defined service
-- library.
-- This version is defined for Posix conformant unix implementations!
-- Reference should be made to Posix specifications for further detail.
-- Version 1.1 Apr 99. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 18 Apr 97 kh Original for Portability (incl int to card).
-- 5 Apr 99 kh Revised for reference strings
abort ;
-- This routine aborts program activity in an OS-dependent manner.
exit(
code : INT
) ;
-- This routine passes the code value back to the program invoker.
error_code : CARD ;
-- This routine returns a coded error number which must be interpreted
-- in the light of the most recently used OS service.
execve(
prog_file_name : REFERENCE,
new_argv : REFERENCE,
new_envp : REFERENCE
) : INT ;
-- This routine attempte to load the program contained in the named
-- file, passing it the arguments and environment specified. This routine
-- does not return unless an error has occurred.
getenv(
var_name : REFERENCE
) : REFERENCE ;
-- This routine determines the value of the environment variable named
-- if it exists, otherwise void is returned.
system(
cli_cmd : REFERENCE
) : INT ;
-- This routine attempts to use the OS command line interpreter to
-- evaluate/execute the given string command. Zero is returned if
-- successful otherwise -1, indicating that errno contains an error value.
getuid : CARD ;
geteuid : CARD ;
getgid : CARD ;
getegid : CARD ;
-- These routines get respectively the user identity, the effective user
-- identity, the project/group identity and the effective project/group
-- identity from the underlying operating system.
get_pid : CARD ;
-- This routine returns the current prograzm process identity.
end ; -- OS_SYS