Skip to content

Commit

Permalink
[UI] Do not leak fd into restarted services (Debian Bug#893152 by Ste…
Browse files Browse the repository at this point in the history
…phen Rothwell <debbugs@rothwell.id.au>).
  • Loading branch information
liske committed Jun 16, 2018
1 parent 1227613 commit 0652271
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ needrestart (3.2) unstable; urgency=medium
(github issue #116 by Marc Dequènes (Duck) @duck-rh)
- [L10n] Fix typo in Russian localization.
(github pull request #118 by @bodqhrohro)
- [UI] Do not leak fd into restarted services.
(Debian Bug#893152 by Stephen Rothwell <debbugs@rothwell.id.au>)

-- Thomas Liske <thomas@fiasko-nw.net>

Expand Down
16 changes: 16 additions & 0 deletions perl/lib/NeedRestart/UI/Debconf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,20 @@ sub runcmd {
close(STDOUT);
}

# Workaround for Debian Bug#893152
#
# Using Debconf leaks a fd to this module's source file. Since Perl seems
# not to set O_CLOEXEC the fd keeps open if the Debconf package uses fork
# to restart needrestart piped to Debconf. The FD will leak into restarted
# daemons if using Sys-V init.
foreach my $fn (</proc/self/fd/*>) {
my $dst = readlink($fn);

# check if the FD is the package source file
if ($dst && ($dst eq __FILE__) && $fn =~ /\/(\d+)$/) {
open(my $fh, "<&=", $1) || warn("$!\n");
close($fh);
}
}

1;

0 comments on commit 0652271

Please sign in to comment.