Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I'm writing again. why after doing commands, script crashes the system?
Error: Out of memory

use Frontier::Daemon::Forking; use Crypt::XXTEA; use Cfg::Config; use Unix::PasswdFile; use MIME::Base64; use constant DEMON_PASS => $Cfg::Config{demonpass}; use constant DEMON_PORT => $Cfg::Config{demonport}; $SIG{CHLD} = 'IGNORE'; print "Uruchamianie demona.\n"; my $demon = Frontier::Daemon::Forking->new( methods => { sprawdz => \&sprawdz, instaluj => \&instaluj, start => \&start, stop => \&stop, konsola => \&konsola, send => \&send, ftp => \&ftp, reinstall => \&reinstall, delete => \&delete, status => \&status, }, LocalPort => DEMON_PORT, LocalAddr => '0.0.0.0', ) or die "Nie mozna uruchomic demona, sprobuj za chwile.\nKod bledu: $ +!"; sub decrypt_params { my @params; foreach my $param (@_) { $param = decode_base64($param); $param = Crypt::XXTEA::decrypt($param,DEMON_PASS); $param = decode_base64($param); return $param; push(@params,$param); } return @params; } sub sprawdz { my ($spr) = @_; my $sprawdz = decrypt_params($spr); if($spr ne 'spr') { return 1; } return 0; } sub instaluj { my($katalogins, $loginftp, $hasloftp) = @_; decrypt_params($katalogins); decrypt_params($loginftp); decrypt_params($hasloftp); system("screen -A -m -d -S c".$loginftp." cp -r ".$katalogins." /home/ +srv".$loginftp."/"); system("useradd -d /home/srv".$loginftp."/ ".$loginftp.""); $pw = new Unix::PasswdFile "/etc/passwd"; $pw->passwd("".$loginftp."", $pw->encpass("".$hasloftp."")); $pw->commit(); undef $pw; } sub start { my($katalog, $komenda, $loginftp) = @_; decrypt_params($katalog); decrypt_params($loginftp); decrypt_params($komenda); system("cd ".$katalog.";screen -A -m -d -L -S srv".$loginftp." ".$kome +nda.""); } sub stop { my($loginftp) = @_; decrypt_params($loginftp); system("kill -3 `screen -list | grep srv".$loginftp." | cut -d . -f1` +>/dev/null 2>&1"); system("screen -wipe"); } sub konsola { my ($loginftp) = @_; decrypt_params($loginftp); system("cd /home/srv".$loginftp.";rm screenlog;tail -n 200 screenlog.0 + > screenlog;"); } sub send { my ($loginftp, $komenda) = @_; decrypt_params($loginftp); decrypt_params($komenda); system("screen -A -m -d -S tmp".$loginftp." screen -x srv".$loginftp." +"); sleep 1; system("screen -S srv".$loginftp." -X stuff '".$komenda." '"); system("kill -9 `screen -list | grep tmp".$loginftp." | cut -d . -f1` +>/dev/null 2>&1"); } sub ftp { my($loginftp, $hasloftp) = @_; decrypt_params($loginftp); decrypt_params($hasloftp); $pw = new Unix::PasswdFile "/etc/passwd"; $pw->passwd("".$loginftp."", $pw->encpass("".$hasloftp."")); $pw->commit(); undef $pw; } sub reinstall { my($loginftp, $katalogins) = @_; decrypt_params($katalogins); decrypt_params($loginftp); system("rm -r /home/srv".$loginftp."/ && cp -R ".$katalogins." /home/s +rv".$loginftp."/"); } sub delete { my($loginftp) = @_; decrypt_params($loginftp); system("rm -r /home/srv".$loginftp."/"); system("deluser ".$loginftp.""); } sub status { my($screen) = @_; decrypt_params($screen); my $stat = `screen -list | grep srv$screen`; if ( $stat =~ /^\s*$/ ) { return 0; } else { return 1; } }

Replies are listed 'Best First'.
Re: Out of memory - FRONTIER DAEMON
by pvaldes (Chaplain) on Nov 03, 2011 at 21:42 UTC

    mmmh... this command line for example seems malformed

    system("screen -A -m -d -S c".$loginftp." cp -r".$katalogins." /home/srv".$loginftp."/");

    That's better probably:

    system("screen -A -m -d -S c".$loginftp."; cp -r".$katalogins." /home/srv".$loginftp."/");

    And even better probably will be to use the equivalent perl commands to remove, delete user, add user, kill, copy, grep, tail, cd... so you could use warnings and check the errors

    what's the purpose of things like this?

    system("useradd -d /home/srv".$loginftp."/ ".$loginftp.""); $pw = new Unix::PasswdFile "/etc/passwd";
      adding user ftp and changing the password.
        .""); <---?

        Probably not needed


        We can't reproduce your problem...

        cpan install Cfg::Config; Warning: Cannot install Cfg::Config, don't know what it is.

        And three, this line seems also malformed. (what is the command "stuff"?)

        system("screen -S srv".$loginftp." -X stuff '".$komenda." '");
Re: Out of memory - FRONTIER DAEMON
by Eliya (Vicar) on Nov 03, 2011 at 21:05 UTC
    ...after doing commands...

    I suppose hardly anyone here is going to go to the trouble of setting up everything as you have it in order to try to reproduce the problem... so you might get more useful replies if you elaborate on the exact conditions under which the problem occurs.

    Such as: after doing what commands? Any of them? After how many requests does the "out of memory" occur? Do the number of processes increase with every request? Does the size of the daemon process increase with every request? Etc.

    Also, can you reproduce the problem, if you strip down your daemon to just a single dummy method, i.e. take out everything not strictly required to reproduce the problem? If not, put things back in again step by step and see at which point the issue starts to manifest itself...