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:
Ingo Bürk
2016-01-02 19:11:55 -05:00
parent 3853d1866b
commit b9b1a60b5d
8 changed files with 138 additions and 21 deletions

View File

@ -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>