📄 util.pm
字号:
# This file was automatically generated by SWIG (http://www.swig.org).# Version 1.3.31## Don't modify this file, modify the SWIG interface instead.package Amanda::Util;require Exporter;require DynaLoader;@ISA = qw(Exporter DynaLoader);package Amanda::Utilc;bootstrap Amanda::Util;package Amanda::Util;@EXPORT = qw( );# ---------- BASE METHODS -------------package Amanda::Util;sub TIEHASH { my ($classname,$obj) = @_; return bless $obj, $classname;}sub CLEAR { }sub FIRSTKEY { }sub NEXTKEY { }sub FETCH { my ($self,$field) = @_; my $member_func = "swig_${field}_get"; $self->$member_func();}sub STORE { my ($self,$field,$newval) = @_; my $member_func = "swig_${field}_set"; $self->$member_func($newval);}sub this { my $ptr = shift; return tied(%$ptr);}# ------- FUNCTION WRAPPERS --------package Amanda::Util;*set_pname = *Amanda::Utilc::set_pname;*safe_cd = *Amanda::Utilc::safe_cd;*check_running_as = *Amanda::Utilc::check_running_as;*set_erroutput_type = *Amanda::Utilc::set_erroutput_type;# ------- VARIABLE STUBS --------package Amanda::Util;*RUNNING_AS_ROOT = *Amanda::Utilc::RUNNING_AS_ROOT;*RUNNING_AS_DUMPUSER = *Amanda::Utilc::RUNNING_AS_DUMPUSER;*RUNNING_AS_DUMPUSER_PREFERRED = *Amanda::Utilc::RUNNING_AS_DUMPUSER_PREFERRED;*RUNNING_AS_CLIENT_LOGIN = *Amanda::Utilc::RUNNING_AS_CLIENT_LOGIN;*RUNNING_AS_UID_ONLY = *Amanda::Utilc::RUNNING_AS_UID_ONLY;@EXPORT_OK = ();%EXPORT_TAGS = ();use Amanda::Debug qw(:init);use Carp;use POSIX qw(:fcntl_h);=head1 NAMEAmanda::Util - Runtime support for Amanda applications=head1 Application InitializationApplication 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);=over=item C<setup_application($name, $type, $context)>Set up the operating environment for an application, without requiringany configuration.=over=item C<$name> is the name of the application, used in log messages, etc.=item C<$type> is one of "server" or "client".=item C<$context> is one of "cmdline" for a user-invoked command-lineutility (e.g., C<amadmin>) or "daemon" for a program started byC<amandad>. (TODO: daemon is not supported yet)=backBased on C<$type> and C<$context>, this function does the following:=over=item sets up debug logging;=item configures internationalization=item sets the umask;=item sets the current working directory to the debug or temporary directory;=item closes any unnecessary file descriptors as a security meaasure;=item ignores C<SIGPIPE>; and=item sets the appropriate target for error messages.=back=cut# private package variablesmy $_pname;my $_ptype;my $_pcontext;sub setup_application { my ($name, $type, $context) = @_; # sanity check croak("no name given") unless ($name); croak("no type given") unless ($type); croak("no context given") unless ($context); # store these as perl values $_pname = $name; $_ptype = $type; $_pcontext = $context; # and let the C side know about the pname set_pname($name); safe_cd(); # (also sets umask) check_std_fds(); # set up debugging for this application type dbopen($type); # ignore SIGPIPE $SIG{'PIPE'} = 'IGNORE'; set_erroutput_type($type, $context);}=item C<finish_setup($running_as_flags)>Perform final initialization tasks that require a loaded configuration.Specifically, move the debug log into a configuration-specificsubdirectory, and check that the current userid is appropriate forthis applciation.The user is specified by one of the following flags, which areavailable in export tag C<: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 C<$RUNNING_AS_UID_ONLY> is bit-or'd into C<$running_as_flags>, thenthe euid is ignored; this is used for programs that expect to be setuid-root.=cutsub finish_setup { my ($running_as) = @_; my $config_name = Amanda::Config::get_config_name(); if ($config_name) { dbrename($config_name, $_ptype); } check_running_as($running_as);}=item safe_envReturn a "safe" environment hash. For non-setuid programs, this means filtering out anylocalization variables.=cutsub safe_env { my %rv = %ENV; delete @rv{qw(IFS CDPATH ENV BASH_ENV LANG)}; # delete all LC_* variables for my $var (grep /^LC_/, keys %rv) { delete $rv{$var}; } return %rv;}push @EXPORT_OK, qw(running_as_flags_to_strings);push @{$EXPORT_TAGS{"running_as_flags"}}, qw(running_as_flags_to_strings);my %_running_as_flags_VALUES;#Convert a flag value to a list of names for flags that are set.sub running_as_flags_to_strings { my ($flags) = @_; my @result = (); for my $k (keys %_running_as_flags_VALUES) { my $v = $_running_as_flags_VALUES{$k}; #is this a matching flag? if (($v == 0 && $flags == 0) || ($v != 0 && ($flags & $v) == $v)) { push @result, $k; } }#by default, just return the number as a 1-element list if (!@result) { return ($flags); } return @result;}push @EXPORT_OK, qw($RUNNING_AS_ROOT);push @{$EXPORT_TAGS{"running_as_flags"}}, qw($RUNNING_AS_ROOT);$_running_as_flags_VALUES{"RUNNING_AS_ROOT"} = $RUNNING_AS_ROOT;push @EXPORT_OK, qw($RUNNING_AS_DUMPUSER);push @{$EXPORT_TAGS{"running_as_flags"}}, qw($RUNNING_AS_DUMPUSER);$_running_as_flags_VALUES{"RUNNING_AS_DUMPUSER"} = $RUNNING_AS_DUMPUSER;push @EXPORT_OK, qw($RUNNING_AS_DUMPUSER_PREFERRED);push @{$EXPORT_TAGS{"running_as_flags"}}, qw($RUNNING_AS_DUMPUSER_PREFERRED);$_running_as_flags_VALUES{"RUNNING_AS_DUMPUSER_PREFERRED"} = $RUNNING_AS_DUMPUSER_PREFERRED;push @EXPORT_OK, qw($RUNNING_AS_CLIENT_LOGIN);push @{$EXPORT_TAGS{"running_as_flags"}}, qw($RUNNING_AS_CLIENT_LOGIN);$_running_as_flags_VALUES{"RUNNING_AS_CLIENT_LOGIN"} = $RUNNING_AS_CLIENT_LOGIN;push @EXPORT_OK, qw($RUNNING_AS_UID_ONLY);push @{$EXPORT_TAGS{"running_as_flags"}}, qw($RUNNING_AS_UID_ONLY);$_running_as_flags_VALUES{"RUNNING_AS_UID_ONLY"} = $RUNNING_AS_UID_ONLY;sub check_std_fds { fcntl(STDIN, F_GETFD, 0) or critical("Standard input is not open"); fcntl(STDOUT, F_GETFD, 0) or critical("Standard output is not open"); fcntl(STDERR, F_GETFD, 0) or critical("Standard error is not open");}1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -