comparison lib/Test/Nginx.pm @ 49:b01ae969181b

Tests: create process group when running daemons. This allows to run daemons indirectly (e.g. via shell) and still be able to kill them without external pid file.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 18 Nov 2008 21:44:14 +0300
parents acfafb52d393
children b494fe5b12d1 c7e29639f915
comparison
equal deleted inserted replaced
48:acfafb52d393 49:b01ae969181b
112 sub stop() { 112 sub stop() {
113 my ($self) = @_; 113 my ($self) = @_;
114 114
115 while ($self->{_daemons} && scalar @{$self->{_daemons}}) { 115 while ($self->{_daemons} && scalar @{$self->{_daemons}}) {
116 my $p = shift @{$self->{_daemons}}; 116 my $p = shift @{$self->{_daemons}};
117 kill 'TERM', $p; 117 # SIGTERM to process group
118 kill -15, $p;
118 wait; 119 wait;
119 } 120 }
120 121
121 return $self unless $self->{_started}; 122 return $self unless $self->{_started};
122 123
152 153
153 my $pid = fork(); 154 my $pid = fork();
154 die "Can't fork daemon: $!\n" unless defined $pid; 155 die "Can't fork daemon: $!\n" unless defined $pid;
155 156
156 if ($pid == 0) { 157 if ($pid == 0) {
158 setpgrp(0, 0);
157 if (ref($code) eq 'CODE') { 159 if (ref($code) eq 'CODE') {
158 $code->(@args); 160 $code->(@args);
159 exit 0; 161 exit 0;
160 } else { 162 } else {
161 exec($code, @args); 163 exec($code, @args);