[Pkg-privacy-commits] [msva-perl] 344/356: Make msva's primary listening daemon a subprocess instead of the parent
Ximin Luo
infinity0 at moszumanska.debian.org
Mon Aug 24 07:42:12 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch debian
in repository msva-perl.
commit 7f8a57a1ebc8f5b4d63acbd8f7104c85f7dc0a19
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date: Wed Jul 25 01:33:29 2012 -0400
Make msva's primary listening daemon a subprocess instead of the parent
A crashing MSVA should not kill the X11 session any longer. This is
modelled after OpenSSH's ssh-agent's behavior (though in contrast with
ssh-agent's documentation).
---
Crypt/Monkeysphere/MSVA.pm | 53 ++++++++++++++++++++++++++--------------------
Net/Server/MSVA.pm | 6 ++++++
2 files changed, 36 insertions(+), 23 deletions(-)
diff --git a/Crypt/Monkeysphere/MSVA.pm b/Crypt/Monkeysphere/MSVA.pm
index c02de64..bbde2b3 100755
--- a/Crypt/Monkeysphere/MSVA.pm
+++ b/Crypt/Monkeysphere/MSVA.pm
@@ -295,7 +295,7 @@
# This is part of a spawned child process. We don't want the
# child process to destroy the update monitor when it terminates.
- $self->{updatemonitor}->forget();
+ $self->{updatemonitor}->forget() if exists $self->{updatemonitor} && defined $self->{updatemonitor};
my $clientinfo = get_client_info(select);
my $clientuid = $clientinfo->{uid};
@@ -702,17 +702,22 @@
my $self = shift;
my $server = shift;
- $self->spawn_master_subproc($server);
+ $self->spawn_as_child($server);
}
- sub master_subprocess_died {
+ sub pre_accept_hook {
my $self = shift;
my $server = shift;
- my $subproc_return = shift;
- my $exitstatus = POSIX::WEXITSTATUS($subproc_return);
- msvalog('verbose', "Subprocess %d terminated; exiting %d.\n", $self->{child_pid}, $exitstatus);
- $server->set_exit_status($exitstatus);
+ $self->parent_changed($server) if (getppid() != $self->{parent_pid});
+ }
+
+ sub parent_changed {
+ my $self = shift;
+ my $server = shift;
+
+ msvalog('verbose', "parent %d went away; exiting.\n", $self->{parent_pid});
+ $server->set_exit_status(0);
$server->server_close();
}
@@ -745,10 +750,6 @@
# instead, we'll just avoid trying to kill the next process with this PID:
$self->{updatemonitor}->forget();
}
- } elsif (exists $self->{child_pid} &&
- ($self->{child_pid} == 0 ||
- $self->{child_pid} == $pid)) {
- $self->master_subprocess_died($server, $?);
}
}
@@ -782,19 +783,18 @@
}
$self->port($port);
}
- $self->{updatemonitor} = Crypt::Monkeysphere::MSVA::Monitor::->new($logger);
}
- sub spawn_master_subproc {
+ sub spawn_as_child {
my $self = shift;
my $server = shift;
- if ((exists $ENV{MSVA_CHILD_PID}) && ($ENV{MSVA_CHILD_PID} ne '')) {
+ if ((exists $ENV{MSVA_PARENT_PID}) && ($ENV{MSVA_PARENT_PID} ne '')) {
# this is most likely a re-exec.
- msvalog('info', "This appears to be a re-exec, continuing with child pid %d\n", $ENV{MSVA_CHILD_PID});
- $self->{child_pid} = $ENV{MSVA_CHILD_PID} + 0;
- } elsif ($#ARGV >= 0) {
- $self->{child_pid} = 0; # indicate that we are planning to fork.
+ msvalog('info', "This appears to be a re-exec, continuing with parent pid %d\n", $ENV{MSVA_PARENT_PID});
+ $self->{parent_pid} = $ENV{MSVA_PARENT_PID} + 0;
+ } elsif ($#ARGV >= 0) {
+ $self->{parent_pid} = 0; # indicate that we are planning to fork.
# avoid ignoring SIGCHLD right before we fork.
$SIG{CHLD} = sub {
my $val;
@@ -802,20 +802,26 @@
$self->child_dies($val, $server);
}
};
+ my $pid = $$;
my $fork = fork();
if (! defined $fork) {
msvalog('error', "could not fork\n");
} else {
- if ($fork) {
- msvalog('debug', "Child process has PID %d\n", $fork);
- $self->{child_pid} = $fork;
- $ENV{MSVA_CHILD_PID} = $fork;
+ if (! $fork) {
+ msvalog('debug', "daemon has PID %d, parent has PID %d\n", $$, $pid);
+ $self->{parent_pid} = $pid;
+ # ppid is set in Net::Server::Fork's post_configure; we're
+ # past post_configure by here, and we're about to change
+ # process IDs before assuming the role of a forking server,
+ # so we should set it properly:
+ $server->{server}->{ppid} = $$;
+ $ENV{MSVA_PARENT_PID} = $pid;
} else {
msvalog('verbose', "PID %d executing: \n", $$);
for my $arg (@ARGV) {
msvalog('verbose', " %s\n", $arg);
}
- # untaint the environment for the subprocess
+ # untaint the environment for the parent process
# see: https://labs.riseup.net/code/issues/2461
foreach my $e (keys %ENV) {
$ENV{$e} = untaint($ENV{$e});
@@ -836,6 +842,7 @@
# ssh-agent. maybe avoid backgrounding by setting
# MSVA_NO_BACKGROUND.
};
+ $self->{updatemonitor} = Crypt::Monkeysphere::MSVA::Monitor::->new($logger);
}
sub extracerts {
diff --git a/Net/Server/MSVA.pm b/Net/Server/MSVA.pm
index 07e43ee..53b37ad 100644
--- a/Net/Server/MSVA.pm
+++ b/Net/Server/MSVA.pm
@@ -19,6 +19,7 @@
{ package Net::Server::MSVA;
use strict;
use base qw(Net::Server::Fork);
+ use Net::Server 2.000 ();
my $msva;
# guarantee initial failure -- this will be cleared after we bind
@@ -37,6 +38,11 @@
$msva->pre_loop_hook($self, @_);
}
+ sub pre_accept_hook {
+ my $self = shift;
+ $msva->pre_accept_hook($self, @_);
+ }
+
sub set_exit_status {
my $self = shift;
$exit_status = shift;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/msva-perl.git
More information about the Pkg-privacy-commits
mailing list