Skip to content

Commit

Permalink
Reduce noise in check_random.inc
Browse files Browse the repository at this point in the history
  • Loading branch information
david-dick committed Jan 4, 2025
1 parent 6b98ad8 commit d22d1f6
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions check_random.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use Config;

my $test_file_name = 'test.c';
my $binary_name = 'a.out';
my $output = q[];
open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!";
print FOO <<'_OUT_';
#include <sys/random.h>
Expand All @@ -16,12 +17,14 @@ int main(void)
}
_OUT_
close FOO or die "Failed to close $test_file_name:$!";
my $result = system { $Config{cc} } $Config{cc}, '-o', $binary_name, $test_file_name;
$output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`;
unlink $test_file_name or die "Failed to unlink $test_file_name:$!";
if ($result == 0) {
if ($? == 0) {
warn "getrandom from sys/random is AVAILABLE\n";
unlink $binary_name or die "Failed to unlink $binary_name:$!";
$optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_NATIVE_GETRANDOM';
} else {
warn "getrandom from sys/random is unavailable\n";
open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!";
print FOO <<'_OUT_';
#include <sys/syscall.h>
Expand All @@ -36,11 +39,13 @@ int main(void)
}
_OUT_
close FOO or die "Failed to close $test_file_name:$!";
my $result = system { $Config{cc} } $Config{cc}, '-o', $binary_name, $test_file_name;
if ($result == 0) {
$output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`;
if ($? == 0) {
warn "SYS_getrandom from sys/syscall is AVAILABLE\n";
unlink $binary_name or die "Failed to unlink $binary_name:$!";
$optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_SYSCALL_GETRANDOM';
} else {
warn "SYS_getrandom from sys/syscall is unavailable\n";
open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!";
print FOO <<'_OUT_';
#include <sys/random.h>
Expand All @@ -54,11 +59,13 @@ int main(void)
}
_OUT_
close FOO or die "Failed to close $test_file_name:$!";
$result = system { $Config{cc} } $Config{cc}, '-o', $binary_name, $test_file_name;
if ($result == 0) {
$output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`;
if ($? == 0) {
warn "getentropy from sys/random is AVAILABLE\n";
unlink $binary_name or die "Failed to unlink $binary_name:$!";
$optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_NATIVE_GETENTROPY';
} else {
warn "getentropy from sys/random is unavailable\n";
open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!";
print FOO <<'_OUT_';
#include <unistd.h>
Expand All @@ -72,11 +79,13 @@ int main(void)
}
_OUT_
close FOO or die "Failed to close $test_file_name:$!";
$result = system { $Config{cc} } $Config{cc}, '-o', $binary_name, $test_file_name;
if ($result == 0) {
$output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`;
if ($? == 0) {
warn "getentropy from unistd is AVAILABLE\n";
unlink $binary_name or die "Failed to unlink $binary_name:$!";
$optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_UNISTD_GETENTROPY';
} else {
warn "getentropy from unistd is unavailable\n";
open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!";
print FOO <<'_OUT_';
int main(void)
Expand All @@ -85,11 +94,14 @@ int main(void)
}
_OUT_
close FOO or die "Failed to close $test_file_name:$!";
$result = system { $Config{cc} } $Config{cc}, '-o', $binary_name, $test_file_name;
if ($result == 0) {
$output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`;
if ($? == 0) {
warn "C compiler is AVAILABLE\n";
warn $output;
unlink $binary_name or die "Failed to unlink $binary_name:$!";
$optional{DEFINE} = '-DUNKNOWN_ENVIRONMENT';
} else {
warn "C compiler is unavailable\n";
$optional{DEFINE} = '-DNO_COMPILER_FOUND';
}
}
Expand Down

0 comments on commit d22d1f6

Please sign in to comment.