aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2024-03-19 07:01:22 +0100
committerPeter Eisentraut <peter@eisentraut.org>2024-03-19 07:09:31 +0100
commitd56cb42b54381d414f1f30929ca267e4768313c8 (patch)
treeaf3376a5ecf97ed9c2a0bc5a1c6716e6ecae5635 /src/test
parentbb5604ba9e53e3a0fb9967f960e36cff4d36b0ab (diff)
downloadpostgresql-d56cb42b54381d414f1f30929ca267e4768313c8.tar.gz
postgresql-d56cb42b54381d414f1f30929ca267e4768313c8.zip
Activate perlcritic InputOutput::RequireCheckedSyscalls and fix resulting warnings
This checks that certain I/O-related Perl functions properly check their return value. Some parts of the PostgreSQL code had been a bit sloppy about that. The new perlcritic warnings are fixed here. I didn't design any beautiful error messages, mostly just used "or die $!", which mostly matches existing code, and also this is developer-level code, so having the system error plus source code reference should be ok. Initially, we only activate this check for a subset of what the perlcritic check would warn about. The effective list is chmod flock open read rename seek symlink system The initial set of functions is picked because most existing code already checked the return value of those, so any omissions are probably unintended, or because it seems important for test correctness. The actual perlcritic configuration is written as an exclude list. That seems better so that we are clear on what we are currently not checking. Maybe future patches want to investigate checking some of the other functions. (In principle, we might eventually want to check all of them, but since this is test and build support code, not production code, there are probably some reasonable compromises to be made.) Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Discussion: https://www.postgresql.org/message-id/flat/88b7d4f2-46d9-4cc7-b1f7-613c90f9a76a%40eisentraut.org
Diffstat (limited to 'src/test')
-rw-r--r--src/test/kerberos/t/001_auth.pl2
-rw-r--r--src/test/modules/ssl_passphrase_callback/t/001_testfunc.pl2
-rw-r--r--src/test/perl/PostgreSQL/Test/Cluster.pm12
-rw-r--r--src/test/perl/PostgreSQL/Test/Utils.pm16
-rw-r--r--src/test/ssl/t/SSL/Server.pm10
5 files changed, 21 insertions, 21 deletions
diff --git a/src/test/kerberos/t/001_auth.pl b/src/test/kerberos/t/001_auth.pl
index 2a81ce8834b..e51e87d0a2e 100644
--- a/src/test/kerberos/t/001_auth.pl
+++ b/src/test/kerberos/t/001_auth.pl
@@ -111,7 +111,7 @@ $krb5_version = $1;
# Construct a pgpass file to make sure we don't use it
append_to_file($pgpass, '*:*:*:*:abc123');
-chmod 0600, $pgpass;
+chmod 0600, $pgpass or die $!;
# Build the krb5.conf to use.
#
diff --git a/src/test/modules/ssl_passphrase_callback/t/001_testfunc.pl b/src/test/modules/ssl_passphrase_callback/t/001_testfunc.pl
index 9aa4bdc3704..a2bfb645760 100644
--- a/src/test/modules/ssl_passphrase_callback/t/001_testfunc.pl
+++ b/src/test/modules/ssl_passphrase_callback/t/001_testfunc.pl
@@ -33,7 +33,7 @@ my $ddir = $node->data_dir;
# install certificate and protected key
copy("server.crt", $ddir);
copy("server.key", $ddir);
-chmod 0600, "$ddir/server.key";
+chmod 0600, "$ddir/server.key" or die $!;
$node->start;
diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm
index 4ea10d063c4..b08296605c4 100644
--- a/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -467,7 +467,7 @@ sub set_replication_conf
$self->host eq $test_pghost
or croak "set_replication_conf only works with the default host";
- open my $hba, '>>', "$pgdata/pg_hba.conf";
+ open my $hba, '>>', "$pgdata/pg_hba.conf" or die $!;
print $hba
"\n# Allow replication (set up by PostgreSQL::Test::Cluster.pm)\n";
if ($PostgreSQL::Test::Utils::windows_os
@@ -580,7 +580,7 @@ sub init
PostgreSQL::Test::Utils::system_or_bail($ENV{PG_REGRESS},
'--config-auth', $pgdata, @{ $params{auth_extra} });
- open my $conf, '>>', "$pgdata/postgresql.conf";
+ open my $conf, '>>', "$pgdata/postgresql.conf" or die $!;
print $conf "\n# Added by PostgreSQL::Test::Cluster.pm\n";
print $conf "fsync = off\n";
print $conf "restart_after_crash = off\n";
@@ -862,7 +862,7 @@ sub init_from_backup
rmdir($data_path);
PostgreSQL::Test::RecursiveCopy::copypath($backup_path, $data_path);
}
- chmod(0700, $data_path);
+ chmod(0700, $data_path) or die $!;
# Base configuration for this node
$self->append_conf(
@@ -1688,16 +1688,16 @@ sub _reserve_port
if (kill 0, $pid)
{
# process exists and is owned by us, so we can't reserve this port
- flock($portfile, LOCK_UN);
+ flock($portfile, LOCK_UN) || die $!;
close($portfile);
return 0;
}
}
# All good, go ahead and reserve the port
- seek($portfile, 0, SEEK_SET);
+ seek($portfile, 0, SEEK_SET) || die $!;
# print the pid with a fixed width so we don't leave any trailing junk
print $portfile sprintf("%10d\n", $$);
- flock($portfile, LOCK_UN);
+ flock($portfile, LOCK_UN) || die $!;
close($portfile);
push(@port_reservation_files, $filename);
return 1;
diff --git a/src/test/perl/PostgreSQL/Test/Utils.pm b/src/test/perl/PostgreSQL/Test/Utils.pm
index 2185a079def..42d5a50dc88 100644
--- a/src/test/perl/PostgreSQL/Test/Utils.pm
+++ b/src/test/perl/PostgreSQL/Test/Utils.pm
@@ -211,10 +211,10 @@ INIT
or die "could not open STDOUT to logfile \"$test_logfile\": $!";
# Hijack STDOUT and STDERR to the log file
- open(my $orig_stdout, '>&', \*STDOUT);
- open(my $orig_stderr, '>&', \*STDERR);
- open(STDOUT, '>&', $testlog);
- open(STDERR, '>&', $testlog);
+ open(my $orig_stdout, '>&', \*STDOUT) or die $!;
+ open(my $orig_stderr, '>&', \*STDERR) or die $!;
+ open(STDOUT, '>&', $testlog) or die $!;
+ open(STDERR, '>&', $testlog) or die $!;
# The test output (ok ...) needs to be printed to the original STDOUT so
# that the 'prove' program can parse it, and display it to the user in
@@ -564,7 +564,7 @@ Find and replace string of a given file.
sub string_replace_file
{
my ($filename, $find, $replace) = @_;
- open(my $in, '<', $filename);
+ open(my $in, '<', $filename) or croak $!;
my $content = '';
while (<$in>)
{
@@ -572,7 +572,7 @@ sub string_replace_file
$content = $content . $_;
}
close $in;
- open(my $out, '>', $filename);
+ open(my $out, '>', $filename) or croak $!;
print $out $content;
close($out);
@@ -789,11 +789,11 @@ sub dir_symlink
# need some indirection on msys
$cmd = qq{echo '$cmd' | \$COMSPEC /Q};
}
- system($cmd);
+ system($cmd) == 0 or die;
}
else
{
- symlink $oldname, $newname;
+ symlink $oldname, $newname or die $!;
}
die "No $newname" unless -e $newname;
}
diff --git a/src/test/ssl/t/SSL/Server.pm b/src/test/ssl/t/SSL/Server.pm
index 149a9385119..ca4c7b567b3 100644
--- a/src/test/ssl/t/SSL/Server.pm
+++ b/src/test/ssl/t/SSL/Server.pm
@@ -191,7 +191,7 @@ sub configure_test_server_for_ssl
}
# enable logging etc.
- open my $conf, '>>', "$pgdata/postgresql.conf";
+ open my $conf, '>>', "$pgdata/postgresql.conf" or die $!;
print $conf "fsync=off\n";
print $conf "log_connections=on\n";
print $conf "log_hostname=on\n";
@@ -204,7 +204,7 @@ sub configure_test_server_for_ssl
close $conf;
# SSL configuration will be placed here
- open my $sslconf, '>', "$pgdata/sslconfig.conf";
+ open my $sslconf, '>', "$pgdata/sslconfig.conf" or die $!;
close $sslconf;
# Perform backend specific configuration
@@ -290,7 +290,7 @@ sub switch_server_cert
my %params = @_;
my $pgdata = $node->data_dir;
- open my $sslconf, '>', "$pgdata/sslconfig.conf";
+ open my $sslconf, '>', "$pgdata/sslconfig.conf" or die $!;
print $sslconf "ssl=on\n";
print $sslconf $backend->set_server_cert(\%params);
print $sslconf "ssl_passphrase_command='"
@@ -315,7 +315,7 @@ sub _configure_hba_for_ssl
# but seems best to keep it as narrow as possible for security reasons.
#
# When connecting to certdb, also check the client certificate.
- open my $hba, '>', "$pgdata/pg_hba.conf";
+ open my $hba, '>', "$pgdata/pg_hba.conf" or die $!;
print $hba
"# TYPE DATABASE USER ADDRESS METHOD OPTIONS\n";
print $hba
@@ -337,7 +337,7 @@ sub _configure_hba_for_ssl
close $hba;
# Also set the ident maps. Note: fields with commas must be quoted
- open my $map, ">", "$pgdata/pg_ident.conf";
+ open my $map, ">", "$pgdata/pg_ident.conf" or die $!;
print $map
"# MAPNAME SYSTEM-USERNAME PG-USERNAME\n",
"dn \"CN=ssltestuser-dn,OU=Testing,OU=Engineering,O=PGDG\" ssltestuser\n",