Skip to content

Commit 0652271

Browse files
committed
[UI] Do not leak fd into restarted services (Debian Bug#893152 by Stephen Rothwell <debbugs@rothwell.id.au>).
1 parent 1227613 commit 0652271

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ needrestart (3.2) unstable; urgency=medium
2020
(github issue #116 by Marc Dequènes (Duck) @duck-rh)
2121
- [L10n] Fix typo in Russian localization.
2222
(github pull request #118 by @bodqhrohro)
23+
- [UI] Do not leak fd into restarted services.
24+
(Debian Bug#893152 by Stephen Rothwell <debbugs@rothwell.id.au>)
2325

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

perl/lib/NeedRestart/UI/Debconf.pm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,20 @@ sub runcmd {
269269
close(STDOUT);
270270
}
271271

272+
# Workaround for Debian Bug#893152
273+
#
274+
# Using Debconf leaks a fd to this module's source file. Since Perl seems
275+
# not to set O_CLOEXEC the fd keeps open if the Debconf package uses fork
276+
# to restart needrestart piped to Debconf. The FD will leak into restarted
277+
# daemons if using Sys-V init.
278+
foreach my $fn (</proc/self/fd/*>) {
279+
my $dst = readlink($fn);
280+
281+
# check if the FD is the package source file
282+
if ($dst && ($dst eq __FILE__) && $fn =~ /\/(\d+)$/) {
283+
open(my $fh, "<&=", $1) || warn("$!\n");
284+
close($fh);
285+
}
286+
}
287+
272288
1;

0 commit comments

Comments
 (0)