From 26460c091a7ee5a437c67f164a2af05565f193af Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 8 Jun 2014 22:13:43 +0200 Subject: [PATCH] delete ipc socket when exiting, cleanup tmpdir fixes #1253 --- src/commands.c | 2 ++ src/main.c | 1 - testcases/t/229-cleanup-tmpdir.t | 53 ++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 testcases/t/229-cleanup-tmpdir.t diff --git a/src/commands.c b/src/commands.c index 801c9306..81358274 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1649,6 +1649,8 @@ void cmd_layout_toggle(I3_CMD, char *toggle_mode) { */ void cmd_exit(I3_CMD) { LOG("Exiting due to user command.\n"); + ipc_shutdown(); + unlink(config.ipc_socket_path); xcb_disconnect(conn); exit(0); diff --git a/src/main.c b/src/main.c index 5ff9afe0..4081c234 100644 --- a/src/main.c +++ b/src/main.c @@ -722,7 +722,6 @@ int main(int argc, char *argv[]) { if (ipc_socket == -1) { ELOG("Could not create the IPC socket, IPC disabled\n"); } else { - free(config.ipc_socket_path); struct ev_io *ipc_io = scalloc(sizeof(struct ev_io)); ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ); ev_io_start(main_loop, ipc_io); diff --git a/testcases/t/229-cleanup-tmpdir.t b/testcases/t/229-cleanup-tmpdir.t new file mode 100644 index 00000000..6448da00 --- /dev/null +++ b/testcases/t/229-cleanup-tmpdir.t @@ -0,0 +1,53 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Please read the following documents before working on tests: +# • http://build.i3wm.org/docs/testsuite.html +# (or docs/testsuite) +# +# • http://build.i3wm.org/docs/lib-i3test.html +# (alternatively: perldoc ./testcases/lib/i3test.pm) +# +# • http://build.i3wm.org/docs/ipc.html +# (or docs/ipc) +# +# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf +# (unless you are already familiar with Perl) +# +# Makes sure i3 deletes its temporary directory when exiting. +# Ticket: #1253 +# Bug still in: 4.7.2-186-g617afc6 +use i3test i3_autostart => 0; +use File::Basename; + +my $config = < 1, dont_create_temp_dir => 1); +my $socketpath = get_socket_path(0); +my $tmpdir = dirname($socketpath); + +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. +my @errorlogfiles = <$tmpdir/errorlog.*>; +for my $fn (@errorlogfiles) { + open(my $fh, '>', $fn); + close($fh); +} + +exit_gracefully($pid); + +ok(! -d $tmpdir, "tmpdir $tmpdir was cleaned up"); +if (-d $tmpdir) { + diag('contents = ' . Dumper(<$tmpdir/*>)); +} + +done_testing; -- 2.39.5