[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Bugfix: Rule command requires 1 consequence
- To: herbstluftwm _minus_ devel _at_ lists _dot_ sourceforge _dot_ net
- Subject: [PATCH] Bugfix: Rule command requires 1 consequence
- From: Tyler Thomas Hart <htyler _at_ pdx _dot_ edu>
- Date: Fri, 14 Dec 2012 19:06:25 -0800
Hi,
Currently the rule command only checks the number of arguments. If these arguments are only flags and/or conditions, the rule will do nothing (afaik).
Empty rules waste memory, and when rule IDs and/or names are implemented, will slow down queue searching.
This patch returns HERBST_FORBIDDEN if no consequence is specified. It also fixes the command-format in the docs, which ORs the consequence with the conditions and flags.
Forgive me if this is the correct behavoir, and this is not a bug.
Tylo
>From 6fde8fcdaf555722891cbcb3361ab68976947590 Mon Sep 17 00:00:00 2001
From: Tyler Thomas Hart <htyler _at_ pdx _dot_ edu>
Date: Fri, 14 Dec 2012 18:58:33 -0800
Subject: [PATCH] Rule command checks for at least 1 consequence
---
NEWS | 1 +
doc/herbstluftwm.txt | 4 ++--
src/rules.c | 7 +++++++
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index 7a69e51..7e6a68e 100644
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,7 @@ Changes:
* add error messages for herbstclient
* new command: shift_edge
* new command: shift_to_monitor
+ * bug fix: rule command requires at least 1 consequence
Release: 0.4.1 on 2012-08-30
----------------------------
diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
index 54178f6..10ba753 100644
--- a/doc/herbstluftwm.txt
+++ b/doc/herbstluftwm.txt
@@ -619,7 +619,7 @@ floating [['TAG'] *on*|*off*|*toggle*|*status*]::
is given, floating mode is toggled. If status is given, then *on* or *off*
is printed, depending of the floating state on 'TAG'.
-rule [\[--]'FLAG'|\[--]'CONDITION'|\[--]'CONSEQUENCE' ...]::
+rule [\[--]'FLAG'|\[--]'CONDITION'] ... \[--]'CONSEQUENCE' ...::
Defines a rule which will be applied to all new clients. Its behaviour is
described in the <<RULES,*RULES section*>>.
@@ -836,7 +836,7 @@ appear. Each rule matches against a certain subset of all clients and defines a
set of properties for them (called 'CONSEQUENCE'##s##). A rule can be defined
with this command:
-+rule+ [\[--]'FLAG'|\[--]'CONDITION'|\[--]'CONSEQUENCE' ...]
++rule+ [\[--]'FLAG'|\[--]'CONDITION'] ... \[--]'CONSEQUENCE' ...
Each rule consists of a list of 'FLAG'##s##, 'CONDITION'##s## and
'CONSEQUENCE'##s## (each of them can be optionally prefixed with two dashes
diff --git a/src/rules.c b/src/rules.c
index 95a0ac5..1be5490 100644
--- a/src/rules.c
+++ b/src/rules.c
@@ -362,6 +362,13 @@ int rule_add_command(int argc, char** argv, GString* output) {
}
}
+ // Check if there is at least 1 consequence
+ if (rule->consequences == NULL) {
+ g_string_append_printf(output,
+ "rule: you must specify at least one consequence\n");
+ return HERBST_FORBIDDEN;
+ }
+
g_queue_push_tail(&g_rules, rule);
return 0;
}
--
1.8.0.2