relocate repo files so ND2 is the only code
This commit is contained in:
38
lib/App/Netdisco/Util/Daemon.pm
Normal file
38
lib/App/Netdisco/Util/Daemon.pm
Normal file
@@ -0,0 +1,38 @@
|
||||
package App::Netdisco::Util::Daemon;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use MCE::Util ();
|
||||
|
||||
# make sure this is already done elsewhere
|
||||
use if $^O eq 'linux', 'Sys::Proctitle';
|
||||
|
||||
use base 'Exporter';
|
||||
our @EXPORT = qw/prctl parse_max_workers/;
|
||||
|
||||
sub prctl {
|
||||
if ($^O eq 'linux') {
|
||||
Sys::Proctitle::setproctitle(shift);
|
||||
}
|
||||
else {
|
||||
$0 = shift;
|
||||
}
|
||||
}
|
||||
|
||||
sub parse_max_workers {
|
||||
my $max = shift;
|
||||
return 0 if !defined $max;
|
||||
|
||||
if ($max =~ /^auto(?:$|\s*([\-\+\/\*])\s*(.+)$)/i) {
|
||||
my $ncpu = MCE::Util::get_ncpu() || 0;
|
||||
|
||||
if ($1 and $2) {
|
||||
local $@; $max = eval "int($ncpu $1 $2 + 0.5)";
|
||||
}
|
||||
}
|
||||
|
||||
return $max || 0;
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user