From: Dietmar Maurer Date: Thu, 3 Sep 2015 16:58:27 +0000 (+0200) Subject: add run() method to CLIHandler X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=93ddd7bc6e8ec6d6b09896521ebc94fe19568829 add run() method to CLIHandler we can reuse that code for several binaries. --- diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm index 6ccfcd2..aee6bb2 100644 --- a/src/PVE/CLIHandler.pm +++ b/src/PVE/CLIHandler.pm @@ -4,6 +4,7 @@ use strict; use warnings; use Data::Dumper; +use PVE::SafeSyslog; use PVE::Exception qw(raise raise_param_exc); use PVE::RESTHandler; use PVE::PodParser; @@ -294,6 +295,35 @@ sub generate_pod_manpage { print_pod_manpage($podfn); } +sub run { + my ($class, $pwcallback, $preparefunc) = @_; + + $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin'; + + no strict 'refs'; + $cmddef = ${"${class}::cmddef"}; + + $exename = $class; + $exename =~ s/^.*:://; + + initlog($exename); + + die "please run as root\n" if $> != 0; + + PVE::INotify::inotify_init(); + + my $rpcenv = PVE::RPCEnvironment->init('cli'); + $rpcenv->init_request(); + $rpcenv->set_language($ENV{LANG}); + $rpcenv->set_user('root@pam'); + + my $cmd = shift @ARGV; + + handle_cmd($cmddef, $exename, $cmd, \@ARGV, $pwcallback, $0, $preparefunc); + + exit 0; +} + sub handle_cmd { my ($def, $cmdname, $cmd, $args, $pwcallback, $podfn, $preparefunc) = @_;