posix Module

posix module provides functions of or related to POSIX. This module consists of posix.jar and libposix_jni.so (On Mac, libposix_jni.jnilib).

Functions

Reading Files

readlink( path )
stat( path )
lstat( path )
access( path , mode )
readlink("/etc/grub.conf")  ==> "../boot/grub/grub.conf"
stat("/etc/rc")  ==> {st_nlink=1, st_rdev=0, st_blocks=8, st_ctime=1079703239,
                      st_atime=1080106262, st_mode=33261, st_blksize=4096,
                      st_ino=467319, st_gid=0, st_size=2338, st_dev=773, st_uid=0,
                      st_mtime=1045604048}
access("/etc/rc", R_OK)  ==> 0

Writing Files

symlink( oldpath , newpath )
link( oldpath , newpath )
chmod( path , mode)
chown( path , uid , gid )
utimes( path , times[] )
symlink("/etc/rc", "/tmp/rc")
chmod(".profile", 0600)
utimes("/etc/rc", null)   // touch

Getting Process Specific Information

ctermid( )
getpid( )
getppid( )
getuid( )
getgid( )
geteuid( )
getegid( )
getlogin( )
getgroups( )
getcwd( )
getenv( name )
geterrno( )
getenv("CLASSPATH")
getcwd()

geterrno() is the only function that is not defined in POSIX spec. It returns errno.

Modifying Process Specific Information

nice( inc )
umask( mask )
setgid( gid )
seteuid( uid )
setegid( gid )
chdir( path )
setenv( name , value )
unsetenv( name )
chdir("/tmp")

Getting System-wide Information

uname( )
getpwnam( name )
getgrnam( name )
getpwuid( uid )
getgrgid( gid )
getrlimit( resource )
getrusage( { who } )
strerror( errno )
sysconf( param )
pathconf( path , name )
getpwuid(getuid())   == > {pw_uid=21231, pw_shell=/bin/bash, pw_passwd=x,
                           pw_dir=/home/tomatsu, pw_gecos=Toyokazu Tomatsu,
                           pw_gid=1600, pw_name=tomatsu}

uname()     ==>   {release=2.4.20-8, sysname=Linux, machine=i686,
                   version=#1 Thu Mar 13 17:54:28 EST 2003, nodename=tr2b}
strerror(EACCES)       ==> "Permission denied"

Modifying System-wide Information

kill( pid , sig )
sync( )
openlog(ident, option, facility )
syslog(prio, msg )
setlogmask( maskpri )
closelog( )
openlog("test", LOG_CONS, LOG_USER)
syslog(6, "hogehoge")
closelog()

Constants

The names of the the constants used with the functions in this module are available, e.g. EACCES in "errno.h".

Security Control

Category Permission
Getting System-wide Information permission org.pnuts.posix.PosixPermission "system.read";
Modifying System-wide Information permission org.pnuts.posix.PosixPermission "system.write";
Getting Process Specific Information permission org.pnuts.posix.PosixPermission "process.read";
Modifying Process Specific Information permission org.pnuts.posix.PosixPermission "process.write";
Reading Files permission org.pnuts.posix.PosixPermission "file.read", path;
Writing Files permission org.pnuts.posix.PosixPermission "file.write", path";