[PATCH] usdt; perform __ to - conversion for usdt and prov notes

Kris Van Hees <[email protected]>
Newsgroups dev.linux.lists.dtrace
Message-ID <SJ0PR10MB5672738898FBCFFE5C13ADEAC2ECA@SJ0PR10MB5672.namprd10.prod.outlook.com>
The __ to - conversion was only done for usdt notes.  It needs to be
done for both usdt and prov notes because they both contain probe
names that may need converting.

Reported-by: Ruud van der Pas <[email protected]>
Signed-off-by: Kris Van Hees <[email protected]>
---
 libcommon/usdt_parser_notes.c | 40 +++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/libcommon/usdt_parser_notes.c b/libcommon/usdt_parser_notes.c
index c98c9fb0..a8b46e65 100644
--- a/libcommon/usdt_parser_notes.c
+++ b/libcommon/usdt_parser_notes.c
@@ -293,6 +293,27 @@ strarray_size(uint8_t cnt, const char *str, const char *end, size_t skip)
 	return p - str;
 }
 
+/*
+ * If the probe name has encoded hyphens, perform in-place changing from "__"
+ * into "-".
+ */
+static void
+fix_probe_name(const char *prb, const char *end)
+{
+	if (strstr(prb, "__") != NULL) {
+		char		*q;
+		const char	*s = prb;
+
+		for (q = (char *)s; s < end; s++, q++) {
+			if (s[0] == '_' && s[1] == '_') {
+				*q = '-';
+				s++;
+			} else if (s > q)
+				*q = *s;
+		}
+	}
+}
+
 static int
 parse_prov_note(int out, dof_helper_t *dhp, usdt_data_t *data,
 		usdt_note_t *note)
@@ -353,6 +374,8 @@ parse_prov_note(int out, dof_helper_t *dhp, usdt_data_t *data,
 			return -1;
 		}
 
+		fix_probe_name(prbt.prb, p);
+
 		if ((prp = dt_htab_lookup(pvp->pmap, &prbt)) == NULL) {
 			if ((prp = malloc(sizeof(dt_probe_t))) == NULL) {
 				usdt_error(out, ENOMEM, "Failed to allocate probe");
@@ -471,22 +494,7 @@ parse_usdt_note(int out, dof_helper_t *dhp, usdt_data_t *data,
 	}
 	prbt.off = off;
 
-	/*
-	 * If the probe name has encoded hyphens, perform in-place changing
-	 * from "__" into "-".
-	 */
-	if (strstr(prbt.prb, "__") != NULL) {
-		char		*q;
-		const char	*s = prbt.prb, *e = p;
-
-		for (q = (char *)s; s < e; s++, q++) {
-			if (s[0] == '_' && s[1] == '_') {
-				*q = '-';
-				s++;
-			} else if (s > q)
-				*q = *s;
-		}
-	}
+	fix_probe_name(prbt.prb, p);
 
 	if ((prp = dt_htab_lookup(prbmap, &prbt)) == NULL) {
 		if ((prp = malloc(sizeof(dt_probe_t))) == NULL) {
-- 
2.43.5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.