]> git.sur5r.net Git - i3/i3/commitdiff
Merge branch 'master' into next
authorMichael Stapelberg <michael@stapelberg.de>
Fri, 27 Jun 2014 07:05:32 +0000 (09:05 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Fri, 27 Jun 2014 07:05:32 +0000 (09:05 +0200)
include/ipc.h
src/commands.c
src/ipc.c
src/util.c
testcases/t/229-cleanup-tmpdir.t

index b6ee9839587f159988c283cfe72cbe22d88f566a..e9358ee58b78d2e8e6d21c6bb8f268d950900fa1 100644 (file)
@@ -50,6 +50,12 @@ typedef void (*handler_t)(int, uint8_t *, int, uint32_t, uint32_t);
                               int size, uint32_t message_size, \
                               uint32_t message_type)
 
+/**
+ * Emulates mkdir -p (creates any missing folders)
+ *
+ */
+bool mkdirp(const char *path);
+
 /**
  * Handler for activity on the listening socket, meaning that a new client
  * has just connected and we should accept() him. Sets up the event handler
index bf9942e2d46caa67f64eab9b75f9e7162e007beb..7803c984c209b55794721f8048d18853ea8ca50c 100644 (file)
@@ -1731,13 +1731,10 @@ void cmd_reload(I3_CMD) {
 void cmd_restart(I3_CMD) {
     LOG("restarting i3\n");
     ipc_shutdown();
+    unlink(config.ipc_socket_path);
     /* We need to call this manually since atexit handlers don’t get called
      * when exec()ing */
     purge_zerobyte_logfile();
-    /* The unlink call is intentionally after the purge_zerobyte_logfile() so
-     * that the latter does not remove the directory yet. We need to store the
-     * restart layout state in there. */
-    unlink(config.ipc_socket_path);
     i3_restart(false);
 
     // XXX: default reply for now, make this a better reply
index 4c8e61a906c74f7b378cb713e93541be44b2f1f8..8413d0a6b6412edf6a84c92a5d55ff754bcae1fc 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -41,7 +41,7 @@ static void set_nonblock(int sockfd) {
  * Emulates mkdir -p (creates any missing folders)
  *
  */
-static bool mkdirp(const char *path) {
+bool mkdirp(const char *path) {
     if (mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0)
         return true;
     if (errno != ENOENT) {
index c40f6581b866b9862ae681b6b625087017a2205a..b382a586e09f2d8b545e663bcaa26b5b4eaf61cc 100644 (file)
@@ -249,6 +249,15 @@ char *store_restart_layout(void) {
         filename = resolve_tilde(config.restart_state_path);
     }
 
+    /* create the directory, it could have been cleaned up before restarting or
+     * may not exist at all in case it was user-specified. */
+    char *filenamecopy = sstrdup(filename);
+    char *base = dirname(filenamecopy);
+    DLOG("Creating \"%s\" for storing the restart layout\n", base);
+    if (!mkdirp(base))
+        ELOG("Could not create \"%s\" for storing the restart layout, layout will be lost.\n", base);
+    free(filenamecopy);
+
     int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
     if (fd == -1) {
         perror("open()");
index eff39b08d3bbaab3de96884b29be0f9ef2e4aba3..cec9bc4df0aea1b55f1f76c0a50ac76d292d22d8 100644 (file)
@@ -19,6 +19,8 @@
 # Bug still in: 4.7.2-186-g617afc6
 use i3test i3_autostart => 0;
 use File::Basename;
+use File::Temp qw(tempfile tempdir);
+use X11::XCB qw(:all);
 
 my $config = <<EOT;
 # i3 config file (v4)
@@ -99,5 +101,79 @@ if (-d $new_tmpdir) {
     diag('contents = ' . Dumper(<$new_tmpdir/*>));
 }
 
+################################################################################
+# Regression: with a socket path outside of tmpdir, i3 would delete the tmpdir
+# prematurely and could not use it for storing the restart layout.
+################################################################################
+
+# Set XDG_RUNTIME_DIR to a temp directory so that i3 will create its directory
+# in there and we’ll be able to find it. Necessary because we cannot deduce the
+# temp directory from the socket path (which we explicitly set).
+$ENV{XDG_RUNTIME_DIR} = tempdir(CLEANUP => 1);
+
+my ($outfh, $outname) = tempfile('/tmp/i3-socket.XXXXXX', UNLINK => 1);
+$config = <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+
+ipc-socket $outname
+EOT
+
+$pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
+$socketpath = get_socket_path(0);
+
+sub get_config_path {
+    my $atom = $x->atom(name => 'I3_CONFIG_PATH');
+    my $cookie = $x->get_property(0, $x->get_root_window(), $atom->id, GET_PROPERTY_TYPE_ANY, 0, 256);
+    my $reply = $x->get_property_reply($cookie->{sequence});
+    return $reply->{value};
+}
+
+my ($outfh2, $outname2) = tempfile('/tmp/i3-socket.XXXXXX', UNLINK => 1);
+my $config_path = get_config_path();
+open(my $configfh, '>', $config_path);
+say $configfh <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+ipc-socket $outname2
+EOT
+close($configfh);
+$tmpdir = $ENV{XDG_RUNTIME_DIR} . '/i3';
+
+ok(-d $tmpdir, "tmpdir $tmpdir exists");
+
+# Clear the error logfile. The testsuite runs in an environment where RandR is
+# not supported, so there always is a message about xinerama in the error
+# logfile.
+@errorlogfiles = <$tmpdir/errorlog.*>;
+for my $fn (@errorlogfiles) {
+    open(my $fh, '>', $fn);
+    close($fh);
+}
+
+my $tmp = fresh_workspace;
+my $win = open_window;
+cmd 'border none';
+my ($nodes, $focus) = get_ws_content($tmp);
+is($nodes->[0]->{border}, 'none', 'border is none');
+
+cmd 'restart';
+
+# The socket path will be different, and we use that for checking whether i3 has restarted yet.
+while (get_socket_path(0) eq $socketpath) {
+    sleep 0.1;
+}
+
+$new_tmpdir = $ENV{XDG_RUNTIME_DIR} . '/i3';
+
+does_i3_live;
+
+($nodes, $focus) = get_ws_content($tmp);
+is($nodes->[0]->{border}, 'none', 'border still none after restart');
+
+exit_gracefully($pid);
+
+close($outfh);
+close($outfh2);
 
 done_testing;