]> git.sur5r.net Git - i3/i3/blobdiff - testcases/lib/SocketActivation.pm
Merge branch 'master' into next
[i3/i3] / testcases / lib / SocketActivation.pm
index f6872fb6161a2f4921aecbcb0cf0cfe09b840f04..d32f6051d9fa17f4af26e252892f22c71d937c1e 100644 (file)
@@ -7,6 +7,7 @@ use IO::Socket::UNIX; # core
 use Cwd qw(abs_path); # core
 use POSIX qw(:fcntl_h); # core
 use AnyEvent::Handle; # not core
+use AnyEvent::Util; # not core
 use Exporter 'import';
 use v5.10;
 
@@ -51,6 +52,15 @@ sub activate_i3 {
         $ENV{LISTEN_PID} = $$;
         $ENV{LISTEN_FDS} = 1;
         delete $ENV{DESKTOP_STARTUP_ID};
+        delete $ENV{I3SOCK};
+        # $SHELL could be set to fish, which will horribly break running shell
+        # commands via i3’s exec feature. This happened e.g. when having
+        # “set-option -g default-shell "/usr/bin/fish"” in ~/.tmux.conf
+        delete $ENV{SHELL};
+        unless ($args{dont_create_temp_dir}) {
+            $ENV{XDG_RUNTIME_DIR} = '/tmp/i3-testsuite/';
+            mkdir $ENV{XDG_RUNTIME_DIR};
+        }
         $ENV{DISPLAY} = $args{display};
         $ENV{PATH} = join(':',
             '../i3-nagbar',
@@ -63,8 +73,11 @@ sub activate_i3 {
 
         # We are about to exec, but we did not modify $^F to include $socket
         # when creating the socket (because the file descriptor could have a
-        # number != 3 which would lead to i3 leaking a file descriptor).
-        # Therefore, we explicitly have to clear the file descriptor flags now:
+        # number != 3 which would lead to i3 leaking a file descriptor). This
+        # caused Perl to set the FD_CLOEXEC flag, which would close $socket on
+        # exec(), effectively *NOT* passing $socket to the new process.
+        # Therefore, we explicitly clear FD_CLOEXEC (the only flag right now)
+        # by setting the flags to 0.
         POSIX::fcntl($socket, F_SETFD, 0) or die "Could not clear fd flags: $!";
 
         # If the socket does not use file descriptor 3 by chance already, we
@@ -72,19 +85,32 @@ sub activate_i3 {
         if (fileno($socket) != 3) {
             POSIX::close(3);
             POSIX::dup2(fileno($socket), 3);
+            POSIX::close(fileno($socket));
         }
 
+        # Make sure no file descriptors are open. Strangely, I got an open file
+        # descriptor pointing to AnyEvent/Impl/EV.pm when testing.
+        AnyEvent::Util::close_all_fds_except(0, 1, 2, 3);
+
         # Construct the command to launch i3. Use maximum debug level, disable
         # the interactive signalhandler to make it crash immediately instead.
-        my $i3cmd = abs_path("../i3") . " -V -d all --disable-signalhandler";
+        # 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|;
 
         # For convenience:
         my $outdir = $args{outdir};
         my $test = $args{testname};
 
+        if ($args{restart}) {
+            $i3cmd .= ' -L ' . abs_path('restart-state.golden');
+        }
+
         if ($args{valgrind}) {
             $i3cmd =
                 qq|valgrind -v --log-file="$outdir/valgrind-for-$test.log" | .
+                qq|--suppressions="./valgrind.supp" | .
                 qq|--leak-check=full --track-origins=yes --num-callers=20 | .
                 qq|--tool=memcheck -- $i3cmd|;
         }
@@ -104,6 +130,14 @@ sub activate_i3 {
                      'sh -c "export LISTEN_PID=\$\$; ' . $cmd . '"';
         }
 
+        if ($args{xtrace}) {
+            my $out = "$outdir/xtrace-for-$test.log";
+
+            # See comment in $args{strace} branch.
+            $cmd = qq|xtrace -n -o "$out" -- | .
+                     'sh -c "export LISTEN_PID=\$\$; ' . $cmd . '"';
+        }
+
         # We need to use the shell due to using output redirections.
         exec '/bin/sh', '-c', $cmd;