All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: Tom Zanussi <zanussi@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 1/4] libtracefs: Add tracefs_list_pop() to remove the last item
Date: Wed, 21 Jul 2021 23:39:14 -0400	[thread overview]
Message-ID: <20210722033917.367982-2-rostedt@goodmis.org> (raw)
In-Reply-To: <20210722033917.367982-1-rostedt@goodmis.org>

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Add a way to remove the last item of a string list. This will be needed to
revert changes made to the new tracefs_synth structure that will have more
than one tracefs_list char ** that must be the same size. If one is
successfully updated, but the next one fails, the first one needs to be
reverted.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 include/tracefs.h   |  1 +
 src/tracefs-utils.c | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/tracefs.h b/include/tracefs.h
index 2649417654b1..4dd77b9c4119 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -66,6 +66,7 @@ int tracefs_error_clear(struct tracefs_instance *instance);
 void tracefs_list_free(char **list);
 char **tracefs_list_add(char **list, const char *string);
 int tracefs_list_size(char **list);
+int tracefs_list_pop(char **list);
 
 /**
  * tracefs_trace_on_get_fd - Get a file descriptor of "tracing_on" in given instance
diff --git a/src/tracefs-utils.c b/src/tracefs-utils.c
index 600cdf2acefc..63bb413298fe 100644
--- a/src/tracefs-utils.c
+++ b/src/tracefs-utils.c
@@ -448,6 +448,32 @@ char **tracefs_list_add(char **list, const char *string)
 	return list;
 }
 
+/**
+ * tracefs_list_pop - Removes the last string added
+ * @list: The list to remove the last event from
+ *
+ * Returns 0 on success, -1 on error.
+ * Returns 1 if the list is empty or NULL.
+ */
+int tracefs_list_pop(char **list)
+{
+	unsigned long size;
+
+	if (!list || list[0])
+		return 1;
+
+	list--;
+	size = *(unsigned long *)list;
+	/* size must be greater than zero */
+	if (!size)
+		return -1;
+	size--;
+	*list = (char *)size;
+	list++;
+	list[size] = '\0';
+	return 0;
+}
+
 /**
  * tracefs_list_size - Return the number of strings in the list
  * @list: The list to determine the size.
-- 
2.30.2


  reply	other threads:[~2021-07-22  3:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22  3:39 [PATCH 0/4] libtracefs: Creating synthetic events Steven Rostedt
2021-07-22  3:39 ` Steven Rostedt [this message]
2021-07-22  3:39 ` [PATCH 2/4] libtracefs: Create a way to create a synthetic event Steven Rostedt
2021-07-22  3:39 ` [PATCH 3/4] libtracefs: Add TRACEFS_TIMESTAMP and TRACEFS_TIMESTAMP_USECS to synth Steven Rostedt
2021-07-22  3:39 ` [PATCH 4/4] libtracefs: Add man pages for creating synthetic events Steven Rostedt
2021-07-22  3:45 ` [PATCH 0/4] libtracefs: Creating " Steven Rostedt

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=20210722033917.367982-2-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=zanussi@kernel.org \
    /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.