From ac4ac941819b25243ede6420c8fa8f56b9e3c399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Sun, 25 Oct 2015 14:25:55 +0100 Subject: [PATCH 1/2] Fixed logging statement. Assignments don't necessarily represent workspace assignments, but could also be used, e.g., for no_focus. Hence, there's no point in logging dest.workspace for all assignments. --- src/assignments.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assignments.c b/src/assignments.c index babe890e..9de50e12 100644 --- a/src/assignments.c +++ b/src/assignments.c @@ -76,7 +76,7 @@ Assignment *assignment_for(i3Window *window, int type) { if ((type != A_ANY && (assignment->type & type) == 0) || !match_matches_window(&(assignment->match), window)) continue; - DLOG("got a matching assignment (to %s)\n", assignment->dest.workspace); + DLOG("got a matching assignment\n"); return assignment; } From ad10a366d6c922ce172b7a72e46fa844f02bcfcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Sun, 25 Oct 2015 14:27:08 +0100 Subject: [PATCH 2/2] Mark assignment as run before executing it. We need to store the information that an assignment was run for a window before actually executing the command. Otherwise, if the command causes a change that causes assignments to be run again, the window might be matched again, causing an infinite loop and hence i3 to freeze or crash. --- src/assignments.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/assignments.c b/src/assignments.c index 9de50e12..6c563357 100644 --- a/src/assignments.c +++ b/src/assignments.c @@ -40,6 +40,13 @@ void run_assignments(i3Window *window) { if (skip) continue; + /* Store that we ran this assignment to not execute it again. We have + * to do this before running the actual command to prevent infinite + * loops. */ + window->nr_assignments++; + window->ran_assignments = srealloc(window->ran_assignments, sizeof(Assignment *) * window->nr_assignments); + window->ran_assignments[window->nr_assignments - 1] = current; + DLOG("matching assignment, would do:\n"); if (current->type == A_COMMAND) { DLOG("execute command %s\n", current->dest.command); @@ -53,11 +60,6 @@ void run_assignments(i3Window *window) { command_result_free(result); } - - /* Store that we ran this assignment to not execute it again */ - window->nr_assignments++; - window->ran_assignments = srealloc(window->ran_assignments, sizeof(Assignment *) * window->nr_assignments); - window->ran_assignments[window->nr_assignments - 1] = current; } /* If any of the commands required re-rendering, we will do that now. */