Commit d93db68c authored by Francesc Guasch's avatar Francesc Guasch
Browse files

added a non forkable create domain

parent 71be8371
...@@ -435,13 +435,14 @@ This is run in the ravada backend. It processes the commands requested by the fr ...@@ -435,13 +435,14 @@ This is run in the ravada backend. It processes the commands requested by the fr
sub process_requests { sub process_requests {
my $self = shift; my $self = shift;
my $debug = shift; my $debug = shift;
my $dont_fork = shift;
my $sth = $CONNECTOR->dbh->prepare("SELECT id FROM requests WHERE status='requested'"); my $sth = $CONNECTOR->dbh->prepare("SELECT id FROM requests WHERE status='requested'");
$sth->execute; $sth->execute;
while (my ($id)= $sth->fetchrow) { while (my ($id)= $sth->fetchrow) {
my $req = Ravada::Request->open($id); my $req = Ravada::Request->open($id);
warn "executing request ".$req." ".Dumper($req) if $DEBUG || $debug; warn "executing request ".$req." ".Dumper($req) if $DEBUG || $debug;
eval { $self->_execute($req) }; eval { $self->_execute($req, $dont_fork) };
if ($@) { if ($@) {
$req->status('done'); $req->status('done');
$req->error($@); $req->error($@);
...@@ -451,6 +452,10 @@ sub process_requests { ...@@ -451,6 +452,10 @@ sub process_requests {
$sth->finish; $sth->finish;
} }
sub _process_requests_dont_fork {
my $self = shift;
return $self->process_requests(undef,1);
}
=head2 list_vm_types =head2 list_vm_types
...@@ -472,13 +477,14 @@ sub list_vm_types { ...@@ -472,13 +477,14 @@ sub list_vm_types {
sub _execute { sub _execute {
my $self = shift; my $self = shift;
my $request = shift; my $request = shift;
my $dont_fork = shift;
my $sub = $self->_req_method($request->command); my $sub = $self->_req_method($request->command);
die "Unknown command ".$request->command die "Unknown command ".$request->command
if !$sub; if !$sub;
return $sub->($self,$request); return $sub->($self,$request, $dont_fork);
} }
...@@ -499,7 +505,7 @@ sub _cmd_domdisplay { ...@@ -499,7 +505,7 @@ sub _cmd_domdisplay {
} }
sub _cmd_create_fork { sub _do_cmd_create{
my $self = shift; my $self = shift;
my $request = shift; my $request = shift;
...@@ -518,11 +524,12 @@ sub _wait_pids { ...@@ -518,11 +524,12 @@ sub _wait_pids {
my $request = shift; my $request = shift;
for my $pid ( keys %{$self->{pids}}) { for my $pid ( keys %{$self->{pids}}) {
$request->status("waiting for pid $pid"); $request->status("waiting for pid $pid") if $request;
warn "Checking for pid '$pid' created at ".localtime($self->{pids}->{$pid});
# warn "Checking for pid '$pid' created at ".localtime($self->{pids}->{$pid});
my $kid = waitpid($pid,0); my $kid = waitpid($pid,0);
warn "Found $kid"; # warn "Found $kid";
return if $kid == $pid; return if $kid == $pid;
} }
} }
...@@ -538,13 +545,16 @@ sub _cmd_create { ...@@ -538,13 +545,16 @@ sub _cmd_create {
my $self = shift; my $self = shift;
my $request = shift; my $request = shift;
my $dont_fork = shift;
return $self->_do_cmd_create($request)
if $dont_fork;
$request->status('waiting for other tasks'); $request->status('waiting for other tasks');
$self->_wait_pids($request); $self->_wait_pids($request);
$request->status('forking'); $request->status('forking');
my $pid = fork(); my $pid = fork();
if (!defined $pid) { if (!defined $pid) {
$request->status('done'); $request->status('done');
...@@ -552,7 +562,7 @@ sub _cmd_create { ...@@ -552,7 +562,7 @@ sub _cmd_create {
return; return;
} }
if ($pid == 0 ) { if ($pid == 0 ) {
$self->_cmd_create_fork($request); $self->_do_cmd_create($request);
exit; exit;
} }
$self->_add_pid($pid); $self->_add_pid($pid);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment