Amanda::Util - Runtime support for Amanda applications
Application initialization generally looks like this:
use Amanda::Config qw( :init ); use Amanda::Util qw( :check_running_as_flags ); use Amanda::Debug;
Amanda::Util::setup_application("myapp", "server", "cmdline"); # .. command-line processing .. Amanda::Config::config_init(...); Amanda::Util::finish_setup($RUNNING_AS_DUMPUSER);
setup_application($name, $type, $context)
Set up the operating environment for an application, without requiring any configuration.
$name
is the name of the application, used in log messages, etc. $type
is usualy one of ``server'' or ``client''. It specifies the subdirectory in which
debug logfiles will be created. $context
indicates the usual manner in
which this application is invoked; one of "cmdline"
for a user-invoked
command-line utility (e.g., amadmin
) which should send human-readable error
messages to stderr; "daemon"
for a program started by amandad
, e.g.,
sendbackup
; or "scriptutil"
for a small program used from shell scripts,
e.g., amgetconf
Based on $type
and $context
, this function does the following:
sets up debug logging;
configures internationalization
sets the umask;
sets the current working directory to the debug or temporary directory;
closes any unnecessary file descriptors as a security meaasure;
ignores SIGPIPE
; and
sets the appropriate target for error messages.
finish_setup($running_as_flags)
Perform final initialization tasks that require a loaded configuration. Specifically, move the debug log into a configuration-specific subdirectory, and check that the current userid is appropriate for this applciation.
The user is specified by one of the following flags, which are
available in export tag :check_running_as_flags
:
$RUNNING_AS_ROOT # root $RUNNING_AS_DUMPUSER # dumpuser, from configuration $RUNNING_AS_DUMPUSER_PREFERRED # dumpuser, but client_login is OK too $RUNNING_AS_CLIENT_LOGIN # client_login (--with-user at build time)
If the flag $RUNNING_AS_UID_ONLY
is bit-or'd into $running_as_flags
, then
the euid is ignored; this is used for programs that expect to be setuid-root.
safe_env()
Return a ``safe'' environment hash. For non-setuid programs, this means filtering out any localization variables.
This page was automatically generated Mon Nov 17 19:29:37 2008 from the Amanda source tree, and documents the most recent development version of Amanda. For documentation specific to the version of Amanda on your system, use the 'perldoc' command.