add missing error handlers for fork() and open() calls

This commit is contained in:
Johannes 'josch' Schauer 2020-01-04 00:39:00 +01:00
parent ed0b5069ce
commit 05e796cd95
Signed by: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -522,7 +522,7 @@ sub havemknod($) {
# we fork so that we can read STDERR # we fork so that we can read STDERR
my $pid = open my $fh, '-|' // error "failed to fork(): $!"; my $pid = open my $fh, '-|' // error "failed to fork(): $!";
if ($pid == 0) { if ($pid == 0) {
open(STDERR, '>&', STDOUT); open(STDERR, '>&', STDOUT) or error "cannot open STDERR: $!";
# we use mknod(1) instead of the system call because creating the # we use mknod(1) instead of the system call because creating the
# right dev_t argument requires makedev(3) # right dev_t argument requires makedev(3)
exec 'mknod', "$root/test-dev-null", 'c', '1', '3'; exec 'mknod', "$root/test-dev-null", 'c', '1', '3';
@ -601,7 +601,7 @@ sub run_progress {
fcntl($wfh, F_SETFD, $flags & ~FD_CLOEXEC ) or error "fcntl F_SETFD: $!"; fcntl($wfh, F_SETFD, $flags & ~FD_CLOEXEC ) or error "fcntl F_SETFD: $!";
my $fd = fileno $wfh; my $fd = fileno $wfh;
# redirect stderr to stdout so that we can capture it # redirect stderr to stdout so that we can capture it
open(STDERR, '>&', STDOUT); open(STDERR, '>&', STDOUT) or error "cannot open STDOUT: $!";
my @execargs = $get_exec->($fd); my @execargs = $get_exec->($fd);
# before apt 1.5, "apt-get update" attempted to chdir() into the # before apt 1.5, "apt-get update" attempted to chdir() into the
# working directory. This will fail if the current working directory # working directory. This will fail if the current working directory
@ -1486,13 +1486,13 @@ sub setup {
pipe my $rfh, my $wfh; pipe my $rfh, my $wfh;
my $pid1 = fork() // error "fork() failed: $!"; my $pid1 = fork() // error "fork() failed: $!";
if ($pid1 == 0) { if ($pid1 == 0) {
open(STDOUT, '>&', $wfh); open(STDOUT, '>&', $wfh) or error "cannot open STDOUT: $!";
debug("running dpkg-deb --fsys-tarfile $options->{root}/$deb"); debug("running dpkg-deb --fsys-tarfile $options->{root}/$deb");
exec 'dpkg-deb', '--fsys-tarfile', "$options->{root}/$deb"; exec 'dpkg-deb', '--fsys-tarfile', "$options->{root}/$deb";
} }
my $pid2 = fork() // error "fork() failed: $!"; my $pid2 = fork() // error "fork() failed: $!";
if ($pid2 == 0) { if ($pid2 == 0) {
open(STDIN, '<&', $rfh); open(STDIN, '<&', $rfh) or error "cannot open STDIN: $!";
debug("running tar -C $options->{root} --keep-directory-symlink --extract --file -"); debug("running tar -C $options->{root} --keep-directory-symlink --extract --file -");
exec 'tar', '-C', $options->{root}, '--keep-directory-symlink', '--extract', '--file', '-'; exec 'tar', '-C', $options->{root}, '--keep-directory-symlink', '--extract', '--file', '-';
} }
@ -2696,7 +2696,7 @@ sub main() {
} }
# check if the compressor is installed # check if the compressor is installed
if (defined $tar_compressor) { if (defined $tar_compressor) {
my $pid = fork(); my $pid = fork() // error "fork() failed: $!";
if ($pid == 0) { if ($pid == 0) {
open(STDOUT, '>', '/dev/null') or error "cannot open /dev/null for writing: $!"; open(STDOUT, '>', '/dev/null') or error "cannot open /dev/null for writing: $!";
open(STDIN, '<', '/dev/null') or error "cannot open /dev/null for reading: $!"; open(STDIN, '<', '/dev/null') or error "cannot open /dev/null for reading: $!";
@ -2868,8 +2868,8 @@ sub main() {
POSIX::sigprocmask(SIG_UNBLOCK, $sigset) or error "Can't unblock signals: $!"; POSIX::sigprocmask(SIG_UNBLOCK, $sigset) or error "Can't unblock signals: $!";
close $rfh; close $rfh;
open(STDOUT, '>&', STDERR);
close $parentsock; close $parentsock;
open(STDOUT, '>&', STDERR) or error "cannot open STDOUT: $!";
setup($options); setup($options);
@ -2883,7 +2883,7 @@ sub main() {
# redirect tar output to the writing end of the pipe so that the # redirect tar output to the writing end of the pipe so that the
# parent process can capture the output # parent process can capture the output
open(STDOUT, '>&', $wfh); open(STDOUT, '>&', $wfh) or error "cannot open STDOUT: $!";
# Add ./dev as the first entries of the tar file. # Add ./dev as the first entries of the tar file.
# We cannot add them after calling tar, because there is no way to # We cannot add them after calling tar, because there is no way to
@ -2910,8 +2910,8 @@ sub main() {
POSIX::sigprocmask(SIG_UNBLOCK, $sigset) or error "Can't unblock signals: $!"; POSIX::sigprocmask(SIG_UNBLOCK, $sigset) or error "Can't unblock signals: $!";
close $rfh; close $rfh;
open(STDOUT, '>&', STDERR);
close $parentsock; close $parentsock;
open(STDOUT, '>&', STDERR) or error "cannot open STDOUT: $!";
setup($options); setup($options);
@ -2925,7 +2925,7 @@ sub main() {
# redirect tar output to the writing end of the pipe so that the # redirect tar output to the writing end of the pipe so that the
# parent process can capture the output # parent process can capture the output
open(STDOUT, '>&', $wfh); open(STDOUT, '>&', $wfh) or error "cannot open STDOUT: $!";
# Add ./dev as the first entries of the tar file. # Add ./dev as the first entries of the tar file.
# We cannot add them after calling tar, because there is no way to # We cannot add them after calling tar, because there is no way to
@ -3294,7 +3294,7 @@ sub main() {
} else { } else {
if (defined $tar_compressor) { if (defined $tar_compressor) {
POSIX::sigprocmask(SIG_BLOCK, $sigset) or error "Can't block signals: $!"; POSIX::sigprocmask(SIG_BLOCK, $sigset) or error "Can't block signals: $!";
my $cpid = fork(); my $cpid = fork() // error "fork() failed: $!";
if ($cpid == 0) { if ($cpid == 0) {
# child: default signal handlers # child: default signal handlers
$SIG{'INT'} = 'DEFAULT'; $SIG{'INT'} = 'DEFAULT';