(This is cperl 5, version 24, subversion 4 (v5.24.4c) built for x86_64-linux) Ubuntu 18.04.
Below is a program that works. However, when I run this program from within Mojolicious::Lite (version 6.04), it hangs. Using top, I see that "tr" is the one eating all the CPU. I have tried using cat instead of tr and it still hangs. If I Control-C the Mojo code it prints the password then exits. It is like tr is accepting the urandom bytes but not moving on to the fold until I interrupt it. But, this works in the ordinary script, not the Mojo one...
Anyone any ideas as to why?
Warmly
John
The script that works:
#! /usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $pass_length = 3;
my $exec = qq{tr -cd "[:alnum:]" < /dev/urandom | fold -w$pass_length | head -n1};
print Dumper $exec;
my $pass = qx{$exec};
chomp $pass;
print Dumper $pass;
The Mojolicious Lite code that hangs:
use Mojolicious::Lite;
use strict;
use warnings;
use Data::Dumper;
post 'testit' => sub {
my $c = shift;
my $pass_length = 3;
# tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1
my $exec = qq{tr -cd '[:alnum:]' < /dev/urandom | fold -w$pass_length | head -n1};
warn Dumper $exec;
my $pass = qx{$exec};
chomp $pass;
warn Dumper $pass;
return $c->render( json => { foo => 'bar'} );
};
app->secrets('foobar');
app->start;
Benefits:
The following version wastes even less entropy, but requires a set of exactly 64 symbols: