Fix segfault when calling "i3 -C".
Commit 287a0b4
introduced a segfault when validating the i3 config
as the root_screen will not be set in this case, causing a null
pointer dereference.
fixes #2144
This commit is contained in:
@ -96,8 +96,13 @@ sub activate_i3 {
|
||||
# the interactive signalhandler to make it crash immediately instead.
|
||||
# Also disable logging to SHM since we redirect the logs anyways.
|
||||
# Force Xinerama because we use Xdmx for multi-monitor tests.
|
||||
my $i3cmd = abs_path("../i3") . q| -V -d all --disable-signalhandler| .
|
||||
q| --shmlog-size=0 --force-xinerama|;
|
||||
my $i3cmd = abs_path("../i3") . q| --shmlog-size=0 --disable-signalhandler --force-xinerama|;
|
||||
if (!$args{validate_config}) {
|
||||
# We only set logging if i3 is actually started, but not if we only
|
||||
# validate the config file. This is to keep logging to a minimum as
|
||||
# such a test will likely want to inspect the log file.
|
||||
$i3cmd .= q| -V -d all|;
|
||||
}
|
||||
|
||||
# For convenience:
|
||||
my $outdir = $args{outdir};
|
||||
@ -107,6 +112,10 @@ sub activate_i3 {
|
||||
$i3cmd .= ' -L ' . abs_path('restart-state.golden');
|
||||
}
|
||||
|
||||
if ($args{validate_config}) {
|
||||
$i3cmd .= ' -C';
|
||||
}
|
||||
|
||||
if ($args{valgrind}) {
|
||||
$i3cmd =
|
||||
qq|valgrind --log-file="$outdir/valgrind-for-$test.log" | .
|
||||
@ -149,6 +158,11 @@ sub activate_i3 {
|
||||
# descriptor on the listening socket.
|
||||
$socket->close;
|
||||
|
||||
if ($args{validate_config}) {
|
||||
$args{cv}->send(1);
|
||||
return $pid;
|
||||
}
|
||||
|
||||
# We now connect (will succeed immediately) and send a request afterwards.
|
||||
# As soon as the reply is there, i3 is considered ready.
|
||||
my $cl = IO::Socket::UNIX->new(Peer => $args{unix_socket_path});
|
||||
|
@ -5,6 +5,7 @@ use strict;
|
||||
use warnings;
|
||||
use Exporter 'import';
|
||||
use Time::HiRes qw(sleep);
|
||||
use i3test::Util qw(slurp);
|
||||
use v5.10;
|
||||
|
||||
our @EXPORT = qw(start_xserver);
|
||||
@ -12,13 +13,6 @@ our @EXPORT = qw(start_xserver);
|
||||
my @pids;
|
||||
my $x_socketpath = '/tmp/.X11-unix/X';
|
||||
|
||||
# reads in a whole file
|
||||
sub slurp {
|
||||
open(my $fh, '<', shift) or return '';
|
||||
local $/;
|
||||
<$fh>;
|
||||
}
|
||||
|
||||
# forks an X server process
|
||||
sub fork_xserver {
|
||||
my $keep_xserver_output = shift;
|
||||
@ -86,8 +80,11 @@ sub start_xserver {
|
||||
|
||||
# Yeah, I know it’s non-standard, but Perl’s POSIX module doesn’t have
|
||||
# _SC_NPROCESSORS_CONF.
|
||||
my $cpuinfo = slurp('/proc/cpuinfo');
|
||||
my $num_cores = scalar grep { /model name/ } split("\n", $cpuinfo);
|
||||
my $num_cores;
|
||||
if (-e '/proc/cpuinfo') {
|
||||
my $cpuinfo = slurp('/proc/cpuinfo');
|
||||
$num_cores = scalar grep { /model name/ } split("\n", $cpuinfo);
|
||||
}
|
||||
# If /proc/cpuinfo does not exist, we fall back to 2 cores.
|
||||
$num_cores ||= 2;
|
||||
|
||||
|
@ -13,6 +13,7 @@ use Time::HiRes qw(sleep);
|
||||
use Cwd qw(abs_path);
|
||||
use Scalar::Util qw(blessed);
|
||||
use SocketActivation;
|
||||
use i3test::Util qw(slurp);
|
||||
|
||||
use v5.10;
|
||||
|
||||
@ -39,6 +40,7 @@ our @EXPORT = qw(
|
||||
focused_ws
|
||||
get_socket_path
|
||||
launch_with_config
|
||||
get_i3_log
|
||||
wait_for_event
|
||||
wait_for_map
|
||||
wait_for_unmap
|
||||
@ -827,6 +829,7 @@ sub launch_with_config {
|
||||
$tmp_socket_path = "/tmp/nested-$ENV{DISPLAY}";
|
||||
|
||||
$args{dont_create_temp_dir} //= 0;
|
||||
$args{validate_config} //= 0;
|
||||
|
||||
my ($fh, $tmpfile) = tempfile("i3-cfg-for-$ENV{TESTNAME}-XXXXX", UNLINK => 1);
|
||||
|
||||
@ -857,8 +860,21 @@ sub launch_with_config {
|
||||
restart => $ENV{RESTART},
|
||||
cv => $cv,
|
||||
dont_create_temp_dir => $args{dont_create_temp_dir},
|
||||
validate_config => $args{validate_config},
|
||||
);
|
||||
|
||||
# If we called i3 with -C, we wait for it to exit and then return as
|
||||
# there's nothing else we need to do.
|
||||
if ($args{validate_config}) {
|
||||
$cv->recv;
|
||||
waitpid $i3_pid, 0;
|
||||
|
||||
# We need this since exit_gracefully will not be called in this case.
|
||||
undef $i3_pid;
|
||||
|
||||
return ${^CHILD_ERROR_NATIVE};
|
||||
}
|
||||
|
||||
# force update of the cached socket path in lib/i3test
|
||||
# as soon as i3 has started
|
||||
$cv->cb(sub { get_socket_path(0) });
|
||||
@ -871,6 +887,16 @@ sub launch_with_config {
|
||||
return $i3_pid;
|
||||
}
|
||||
|
||||
=head2 get_i3_log
|
||||
|
||||
Returns the content of the log file for the current test.
|
||||
|
||||
=cut
|
||||
sub get_i3_log {
|
||||
my $logfile = "$ENV{OUTDIR}/i3-log-for-$ENV{TESTNAME}";
|
||||
return slurp($logfile);
|
||||
}
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Michael Stapelberg <michael@i3wm.org>
|
||||
|
47
testcases/lib/i3test/Util.pm
Normal file
47
testcases/lib/i3test/Util.pm
Normal file
@ -0,0 +1,47 @@
|
||||
package i3test::Util;
|
||||
# vim:ts=4:sw=4:expandtab
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use v5.10;
|
||||
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw(
|
||||
slurp
|
||||
);
|
||||
|
||||
=encoding utf-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
i3test::Util - General utility functions
|
||||
|
||||
=cut
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
=cut
|
||||
|
||||
=head2 slurp($fn)
|
||||
|
||||
Reads the entire file specified in the arguments and returns the content.
|
||||
|
||||
=cut
|
||||
sub slurp {
|
||||
my ($file) = @_;
|
||||
my $content = do {
|
||||
local $/ = undef;
|
||||
open my $fh, "<", $file or die "could not open $file: $!";
|
||||
<$fh>;
|
||||
};
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Michael Stapelberg <michael@i3wm.org>
|
||||
|
||||
=cut
|
||||
|
||||
1
|
Reference in New Issue
Block a user