From: Peter Rajnoha <prajnoha@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH] Add escape sequence for ':' in command's PV list
Date: Wed, 15 Sep 2010 14:30:15 +0200 [thread overview]
Message-ID: <4C90BC57.30100@redhat.com> (raw)
This is reincarnation of simple, old and forgotten (and not so important) patch
I sent a long long time ago but it faded away somehow. But I'd like to have
this cleaned up finally (..to not make a mess on my desk :)).
At that time, I used doubling of characters to escape the ":". But since
we use "\" everywhere else, let's do it this way. (rhbz #491409)
(I remember there was a discussion about adding some form of generic
mechanism for escaping characters by means of adding a new command to
do that. Do we still want that? Is that really necessary?)
Peter
---
lib/misc/lvm-string.c | 20 ++++++++++++++++++--
lib/misc/lvm-string.h | 6 ++++++
tools/toollib.c | 15 +++++++--------
3 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/lib/misc/lvm-string.c b/lib/misc/lvm-string.c
index 7eed799..6c1c1a5 100644
--- a/lib/misc/lvm-string.c
+++ b/lib/misc/lvm-string.c
@@ -105,14 +105,19 @@ static void _quote_characters(char **out, const char *src,
* Also unquote quote_char.
*/
static void _unquote_characters(char *src, const int orig_char,
- const int quote_char)
+ const int quote_char,
+ char **substr_first_unquoted)
{
char *out = src;
+ *substr_first_unquoted = NULL;
+
while (*src) {
if (*src == quote_char &&
(*(src + 1) == orig_char || *(src + 1) == quote_char))
src++;
+ else if (*src == orig_char)
+ *substr_first_unquoted = out;
*out++ = *src++;
}
@@ -209,7 +214,18 @@ char *escape_double_quotes(char *out, const char *src)
*/
void unescape_double_quotes(char *src)
{
- _unquote_characters(src, '\"', '\\');
+ char *s;
+
+ _unquote_characters(src, '\"', '\\', &s);
+}
+
+/*
+ * Unescape colons in situ and save the substring starting
+ * at the position of the first unescaped colon.
+ */
+void unescape_colons(char *src, char **substr_first_unquoted)
+{
+ _unquote_characters(src, ':', '\\', substr_first_unquoted);
}
/*
diff --git a/lib/misc/lvm-string.h b/lib/misc/lvm-string.h
index 35d9245..f649fdc 100644
--- a/lib/misc/lvm-string.h
+++ b/lib/misc/lvm-string.h
@@ -60,4 +60,10 @@ char *escape_double_quotes(char *out, const char *src);
*/
void unescape_double_quotes(char *src);
+/*
+ * Unescape colons in situ and save the substring starting
+ * at the position of the first unescaped colon.
+ */
+void unescape_colons(char *src, char **substr_first_unquoted);
+
#endif
diff --git a/tools/toollib.c b/tools/toollib.c
index 5da30f4..104f33c 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1093,7 +1093,7 @@ struct dm_list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int
struct dm_list *r;
struct pv_list *pvl;
struct dm_list tags, arg_pvnames;
- const char *pvname = NULL;
+ char *pvname = NULL;
char *colon, *tagname;
int i;
@@ -1128,13 +1128,12 @@ struct dm_list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int
pvname = argv[i];
- if ((colon = strchr(pvname, ':'))) {
- if (!(pvname = dm_pool_strndup(mem, pvname,
- (unsigned) (colon -
- pvname)))) {
- log_error("Failed to clone PV name");
- return NULL;
- }
+ unescape_colons(pvname, &colon);
+
+ if (colon && !(pvname = dm_pool_strndup(mem, pvname,
+ (unsigned) (colon - pvname)))) {
+ log_error("Failed to clone PV name");
+ return NULL;
}
if (!(pvl = find_pv_in_vg(vg, pvname))) {
next reply other threads:[~2010-09-15 12:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-15 12:30 Peter Rajnoha [this message]
-- strict thread matches above, loose matches on Subject: below --
2009-05-13 11:09 [PATCH] Add escape sequence for ':' in command's PV list Peter Rajnoha
2009-05-13 19:43 ` Dave Wysochanski
2009-05-13 19:55 ` Milan Broz
2009-05-14 9:33 ` Peter Rajnoha
2009-05-14 19:25 ` Dave Wysochanski
2009-05-15 12:07 ` Dave Wysochanski
2009-05-15 12:27 ` Dave Wysochanski
2009-05-15 17:57 ` Peter Rajnoha
2009-05-15 18:13 ` Alasdair G Kergon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C90BC57.30100@redhat.com \
--to=prajnoha@redhat.com \
--cc=lvm-devel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.