MDK::Common::System.3pm

Langue: en

Autres versions - même langue

Version: 2008-04-03 (mandriva - 01/05/08)

Section: 3 (Bibliothèques de fonctions)

NAME

MDK::Common::System - system-related useful functions

SYNOPSIS

     use MDK::Common::System qw(:all);
 
 

EXPORTS

%compat_arch
architecture compatibility mapping (eg: k6 => i586, k7 => k6 ...)
%printable_chars
7 bit ascii characters
$sizeof_int
sizeof(int)
$bitof_int
$sizeof_int * 8
arch()
return the architecture (eg: i686, ppc, ia64, k7...)
typeFromMagic(FILENAME, LIST)
find the first corresponding magic in FILENAME. eg of LIST:
     [ 'empty', 0, "\0\0\0\0" ],
     [ 'grub', 0, "\xEBG", 0x17d, "stage1 \0" ],
     [ 'lilo', 0x2,  "LILO" ],
 
 

where each entry is [ magic_name, offset, string, offset, string, ... ].

list_passwd()
return the list of users as given by "getpwent" (see perlfunc)
list_home()
return the list of home (eg: /home/foo, /home/pixel, ...)
list_skels()
return the directories where we can find dot files: homes, /root and /etc/skel
list_users()
return the list of unprivilegied users (aka those whose uid is greater than 500 and who are not ``nobody'').
syscall_(NAME, PARA)
calls the syscall NAME
psizeof(STRING)
useful to know the length of a "pack" format string.
     psizeof("I I I C C S") = 4 + 4 + 4 + 1 + 1 + 2 = 16
 
 
availableMemory()
size of swap + memory
availableRamMB()
size of RAM as reported by the BIOS (it is a round number that can be displayed or given as ``mem=128M'' to the kernel)

!! ``mem=...'' is dangerous in 2.4 kernels

gettimeofday()
returns the epoch in microseconds
unix2dos(STRING)
takes care of CR/LF translation
whereis_binary(STRING)
return the first absolute file in $PATH (similar to which(1) and whereis(1))
getVarsFromSh(FILENAME)
returns a hash associating shell variables to their value. useful for config files such as /etc/sysconfig files
setVarsInSh(FILENAME, HASH REF)
write file in shell format association a shell variable + value for each key/value
setVarsInSh(FILENAME, HASH REF, LIST)
restrict the fields that will be printed to LIST
setVarsInShMode(FILENAME, INT, HASH REF, LIST)
like setVarsInSh with INT being the chmod value for the config file
addVarsInSh(FILENAME, HASH REF)
like setVarsInSh but keeping the entries in the file
addVarsInSh(FILENAME, HASH REF, LIST)
like setVarsInSh but keeping the entries in the file
addVarsInShMode(FILENAME, INT, HASH REF, LIST)
like addVarsInShMode but keeping the entries in the file
setExportedVarsInCsh(FILENAME, HASH REF, LIST)
same as "setExportedVarsInSh" for csh format
template2file(FILENAME_IN, FILENAME_OUT, HASH)
read in a template file, replace keys @@@key@@@ with value, save it in out file
template2userfile(PREFIX, FILENAME_IN, FILENAME_OUT, BOOL, HASH)
read in a template file, replace keys @@@key@@@ with value, save it in every homes. If BOOL is true, overwrite existing files. FILENAME_OUT must be a relative filename
read_gnomekderc(FILENAME, STRING)
reads GNOME-like and KDE-like config files (aka windows-like). You must give a category. eg:
     read_gnomekderc("/etc/skels/.kderc", 'KDE')
 
 
update_gnomekderc(FILENAME, STRING, HASH)
modifies GNOME-like and KDE-like config files (aka windows-like). If the category doesn't exist, it creates it. eg:
     update_gnomekderc("/etc/skels/.kderc", 'KDE', 
                       kfmIconStyle => "Large")
 
 
fuzzy_pidofs(REGEXP)
return the list of process ids matching the regexp

OTHER

better_arch(ARCH1, ARCH2)
is ARCH1 compatible with ARCH2?

better_arch('i386', 'ia64') and better_arch('ia64', 'i386') are false

better_arch('k7', 'k6') is true and better_arch('k6', 'k7') is false

compat_arch(STRING)
test the architecture compatibility. eg:

compat_arch('i386') is false on a ia64

compat_arch('k6') is true on a k6 and k7 but false on a i386 and i686

SEE ALSO

MDK::Common