summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGreg Banks <gnb@melbourne.sgi.com>2009-02-06 04:54:26 +0300
committerGreg Kroah-Hartman <gregkh@suse.de>2009-03-25 02:38:27 +0300
commit9898abb3d23311fa227a7f46bf4e40fd2954057f (patch)
treef32e6f1b0422e491bf3db276f6f62467e4a21928 /lib
parent86151fdf38b3795f292b39defbff39d2684b9c8c (diff)
downloadlinux-9898abb3d23311fa227a7f46bf4e40fd2954057f.tar.xz
Dynamic debug: allow simple quoting of words
Allow simple quoting of words in the dynamic debug control language. This allows more natural specification when using the control language to match against printk formats, e.g #echo -n 'format "Setting node for non-present cpu" +p' > /mnt/debugfs/dynamic_debug/control instead of #echo -n 'format Setting\040node\040for\040non-present\040cpu +p' > /mnt/debugfs/dynamic_debug/control Adjust the dynamic debug documention to describe that and provide a new example. Adjust the existing examples in the documentation to reflect the current whitespace escaping behaviour when reading the control file. Fix some minor documentation trailing whitespace. Signed-off-by: Greg Banks <gnb@melbourne.sgi.com> Acked-by: Jason Baron <jbaron@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/dynamic_debug.c53
1 files changed, 33 insertions, 20 deletions
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 9e123ae326bc..833139ce1e22 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -196,32 +196,45 @@ static void ddebug_change(const struct ddebug_query *query,
}
/*
- * Wrapper around strsep() to collapse the multiple empty tokens
- * that it returns when fed sequences of separator characters.
- * Now, if we had strtok_r()...
- */
-static inline char *nearly_strtok_r(char **p, const char *sep)
-{
- char *r;
-
- while ((r = strsep(p, sep)) != NULL && *r == '\0')
- ;
- return r;
-}
-
-/*
* Split the buffer `buf' into space-separated words.
- * Return the number of such words or <0 on error.
+ * Handles simple " and ' quoting, i.e. without nested,
+ * embedded or escaped \". Return the number of words
+ * or <0 on error.
*/
static int ddebug_tokenize(char *buf, char *words[], int maxwords)
{
int nwords = 0;
- while (nwords < maxwords &&
- (words[nwords] = nearly_strtok_r(&buf, " \t\r\n")) != NULL)
- nwords++;
- if (buf)
- return -EINVAL; /* ran out of words[] before bytes */
+ while (*buf) {
+ char *end;
+
+ /* Skip leading whitespace */
+ while (*buf && isspace(*buf))
+ buf++;
+ if (!*buf)
+ break; /* oh, it was trailing whitespace */
+
+ /* Run `end' over a word, either whitespace separated or quoted */
+ if (*buf == '"' || *buf == '\'') {
+ int quote = *buf++;
+ for (end = buf ; *end && *end != quote ; end++)
+ ;
+ if (!*end)
+ return -EINVAL; /* unclosed quote */
+ } else {
+ for (end = buf ; *end && !isspace(*end) ; end++)
+ ;
+ BUG_ON(end == buf);
+ }
+ /* Here `buf' is the start of the word, `end' is one past the end */
+
+ if (nwords == maxwords)
+ return -EINVAL; /* ran out of words[] before bytes */
+ if (*end)
+ *end++ = '\0'; /* terminate the word */
+ words[nwords++] = buf;
+ buf = end;
+ }
if (verbose) {
int i;