Overview | Index by: file name | procedure name | procedure call | annotation

helper.tcl Annotations

Created from source/helper.tcl
Procedures that facilitate module writting. It should be loaded from the Master only, not Sessions.

Procedure Summary
ask { args }
          A convenience proc to prompt the user for some value.
blocks { script }
          
break_event { sid }
          
busybox_has { feature }
          Check that the installed busybox supports a specific
checkfs { type path {flags {}} {text {}} }
          Check that a filesystem entity exists and it has specific properties.
isdomainname { str }
          Checks that a string is a valid IP domain name.
isemail { str }
          
ishostname { str }
          Checks that a string is a valid IP hostname.
isip { str }
          Checks if an string represents a legal IP address (v4 or
isip4 { str }
          Checks if an string represents a legal IPv4
isip6 { str }
          Checks if an string represents a legal IPv6
isipport { port }
          Check if a string is a valid TCP/UDP port
isrunning { name }
          Find if a certain executable (usually a daemon) is
kernel_has { feature }
          Check that the running kernel supports a specific
kill { sig ps }
          Send a signal to a process.
killall { name }
          Kill all processses with the specified name.
parseconf { gvar filepath args }
          
pidof { name }
          Return a list of process ids for all the processes with executable
removeline { filepath pattern }
          Remove lines from a file that match a given pattern.
secs2age { secs {format -full} }
          Convert a duration in secs to a string describing the duration, involving days, hours, mins & secs.
sflush { args }
          Access the version of "flush" of the
sgets { args }
          Access the version of "gets" of the
sputs { args }
          Access the version of "puts" of the
sread { args }
          Access the version of "read" of the
timeout { secs script }
          Execute a script in the context of the caller, but wait up to $secs number of secs for the script to finish evaluation.

Procedure Detail

ask

proc ask { args }
A convenience proc to prompt the user for some value. This is an interactive procedure that operates in a Session thread. ask ?options? question The following options are supported: -type : The answer is accepted only if it is of type , which can be any of the types supported by "string is ". Default type: "ascii". -default : Specifies the default value which is used when the user presses enter without providing a value. -list : The list of possible answers (can be used in conjuction with -type, or on its own). -min : When the answer is a number, this is the minimum acceptable. -max : When the answer is a number, this is the maximum acceptable. -check : Execute the specifies procedure with a single argument the user's answer, and it should return a boolean. If true the answer is valid, otherwise is not acceptable. -eval : Similar to -check , but this is a Tcl script that is evaluated on global scope. Any occurence of %% inside is substituted with the provided answer by the user. -switch : This switch simplifies execution of external programs that accept command line switches, that depend on user's answers. For boolean answers "ask" will return verbatim, whereas for any other type it will return " ". -neg : When -type is boolean, this switch will reverse the normal return value. Instead of returning when answer is true, it returns it when it evaluates to false. -noswitch : When used together with -default, this switch will cause "ask" to return nothing (no switch), when the user provided the default value. -hidedef : This will hide the the square brackets after the question with the default answer. -nonewline : See the "nbgets" procedure in thread.tcl. -noecho : See the "nbgets" procedure in thread.tcl. -end : See the "nbgets" procedure in thread.tcl. -length : See the "nbgets" procedure in thread.tcl.
Parameters:
args - See description above.
Returns:
Either the empty list or a string. @error
Defined in:
helper.tcl, line 480

blocks

proc blocks { script }
Defined in:
helper.tcl, line 327

break_event

proc break_event { sid }
Defined in:
helper.tcl, line 332

busybox_has

proc busybox_has { feature }
Check that the installed busybox supports a specific feature.
Parameters:
feature - The name of the feature to be checked, e.g. CONFIG_ASH
Returns:
'1' if supported, '0' otherwise. @error
Defined in:
helper.tcl, line 353

checkfs

proc checkfs { type path {flags {}} {text {}} }
Check that a filesystem entity exists and it has specific properties. The following flags are supported: r : Entity is readable w : Entity is writable x : Entity is executable f : Entity is a file d : Entity is a directory c : Create entity if it does not exist Any combinatio of these flags can be used.
Parameters:
type - "-dir" or "-file"
path - The path of the entity.
flags - A list of flags to check.
text - The text to write to the file, if it is being created (flag 'c'). @error
Defined in:
helper.tcl, line 104

isdomainname

proc isdomainname { str }
Checks that a string is a valid IP domain name. Validity: Like hostnames (see above) but also the underscore character can be used. @todo Verify validity. @todo Support for international domain names (e.g. with greek characters in them) @link http://tools.ietf.org/html/rfc1034
Parameters:
str - The input string to check.
Returns:
'1' is it is hostname is legal, otherwise '0'.
Defined in:
helper.tcl, line 192

isemail

proc isemail { str }
Parameters:
str - The input string to check.
Returns:
'1' is it is valid email address, otherwise '0'.
Defined in:
helper.tcl, line 230

ishostname

proc ishostname { str }
Checks that a string is a valid IP hostname. Validity: Hostnames, like all domain names[1], are made up of a series of "labels", with each label being separated by a dot. Each label must be between 1 and 63 characters long, and there is a maximum of 255 characters when all labels are combined. Unlike domain names, hostname labels can only be made up of the ASCII letters 'a' through 'z' (case-insensitive), the digits '0' through '9', and the hyphen. Labels cannot start nor end with a hyphen. Special characters other than the hyphen (and the dot between labels) are not allowed, although they are sometimes used anyway. @todo How many labels? @todo Can a label start with [0-9]? (currently we don't allow)? @link http://tools.ietf.org/html/rfc952
Parameters:
str - The input string to check.
Returns:
'1' is it is hostname is legal, otherwise '0'.
Defined in:
helper.tcl, line 175

isip

proc isip { str }
Checks if an string represents a legal IP address (v4 or v6).
Parameters:
str - The input string to check.
Returns:
'1' is it is a legal IP, otherwise '0'.
Defined in:
helper.tcl, line 219

isip4

proc isip4 { str }
Checks if an string represents a legal IPv4 address.
Parameters:
str - The input string to check.
Returns:
'1' is it is a legal IPv4, otherwise '0'.
Defined in:
helper.tcl, line 201

isip6

proc isip6 { str }
Checks if an string represents a legal IPv6 address.
Parameters:
str - The input string to check.
Returns:
'1' is it is a legal IPv6, otherwise '0'.
Defined in:
helper.tcl, line 211

isipport

proc isipport { port }
Check if a string is a valid TCP/UDP port number.
Defined in:
helper.tcl, line 236

isrunning

proc isrunning { name }
Find if a certain executable (usually a daemon) is running.
Parameters:
name - Name of executable e.g. syslogd
Defined in:
helper.tcl, line 363

kernel_has

proc kernel_has { feature }
Check that the running kernel supports a specific feature.
Parameters:
feature - The name of the feature to be checked, e.g. CONFIG_INOTIFY.
Returns:
'1' if supported, '0' otherwise. @error
Defined in:
helper.tcl, line 341

kill

proc kill { sig ps }
Send a signal to a process. @todo Check to see if it was actually killed, and log error if not.
Defined in:
helper.tcl, line 386

killall

proc killall { name }
Kill all processses with the specified name. First try -TERM, then try -KILL. Log errors.
Parameters:
name - Name of executable e.g. syslogd @todo Check to see if it was actually killed, and log error if not.
Defined in:
helper.tcl, line 396

parseconf

proc parseconf { gvar filepath args }
Defined in:
helper.tcl, line 66

pidof

proc pidof { name }
Return a list of process ids for all the processes with executable $name.
Parameters:
name - Name of executable e.g. syslogd
Returns:
A list of PIDs, or the empty list.
Defined in:
helper.tcl, line 375

removeline

proc removeline { filepath pattern }
Remove lines from a file that match a given pattern. Update file in place. A temporary file $filepath.new is used internally.
Parameters:
filepath - The filepath of the file. The file must pre-exist.
pattern - A "string match" pattern. @error
Defined in:
helper.tcl, line 246

secs2age

proc secs2age { secs {format -full} }
Convert a duration in secs to a string describing the duration, involving days, hours, mins & secs. @assume Input argument is sane.
Parameters:
secs - Absolute number of seconds.
format - Requests a specific format for the returned string. Supported: -full -simple
Returns:
A string.
Defined in:
helper.tcl, line 274

sflush

proc sflush { args }
Access the version of "flush" of the Session.
Parameters:
args - The standard "flush" arguments.
Defined in:
helper.tcl, line 405

sgets

proc sgets { args }
Access the version of "gets" of the Session.
Parameters:
args - The standard "flush" arguments.
Defined in:
helper.tcl, line 415

sputs

proc sputs { args }
Access the version of "puts" of the Session.
Parameters:
args - The standard "flush" arguments.
Defined in:
helper.tcl, line 435

sread

proc sread { args }
Access the version of "read" of the Session.
Parameters:
args - The standard "flush" arguments.
Defined in:
helper.tcl, line 425

timeout

proc timeout { secs script }
Execute a script in the context of the caller, but wait up to $secs number of secs for the script to finish evaluation. If after $secs seconds the script is still executing then it will be forcefully interrupted. The interruption will seem to the caller like an error that the script generated. This procedure should be used always to avoid blocking the Master for an unknown period of time. However notice that this procedure alone doesn't safeguards the Master from blocking. See ::helper::blocks for mitigating this. @todo Make to interrupt script evaluation when Ctrl ^ + x is presssed.
Parameters:
secs - Number of seconds to wait.
script - Script to execute. @error
Defined in:
helper.tcl, line 314

Overview | Index by: file name | procedure name | procedure call | annotation
File generated 2010-03-13 at 22:28.