linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: <linux-trace-devel@vger.kernel.org>
Cc: Sameeruddin shaik <sameeross1994@gmail.com>,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 2/4] libtracefs: Fix the errno values of tracefs_tracer_set()
Date: Fri, 25 Jun 2021 18:17:37 -0400	[thread overview]
Message-ID: <20210625221739.1215557-3-rostedt@goodmis.org> (raw)
In-Reply-To: <20210625221739.1215557-1-rostedt@goodmis.org>

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

Be consistent with the errno values on error for tracefs_tracer_set(). If
a bad enum is passed in, then EINVAL should be set, not ENODEV. But if the
tracer does not exist, then ENODEV should be set (even though the write
will return EINVAL).

Also fix the setting of errno to negative values. That's done in the
kernel, not user space.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 src/tracefs-tools.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c
index fb243d8..6d5ddae 100644
--- a/src/tracefs-tools.c
+++ b/src/tracefs-tools.c
@@ -979,12 +979,12 @@ int tracefs_tracer_set(struct tracefs_instance *instance,
 
 	fd = open(tracer_path, O_WRONLY);
 	if (fd < 0) {
-		errno = -ENOENT;
+		errno = ENOENT;
 		goto out;
 	}
 
 	if (tracer < 0 || tracer > ARRAY_SIZE(tracers)) {
-		errno = -ENODEV;
+		errno = EINVAL;
 		goto out;
 	}
 
@@ -1005,10 +1005,16 @@ int tracefs_tracer_set(struct tracefs_instance *instance,
 		}
 	}
 	if (!t) {
-		errno = -EINVAL;
+		errno = EINVAL;
 		goto out;
 	}
 	ret = write_tracer(fd, t);
+	/*
+	 * If the tracer does not exist, EINVAL is returned,
+	 * but let the user know this as ENODEV.
+	 */
+	if (ret < 0 && errno == EINVAL)
+		errno = ENODEV;
  out:
 	tracefs_put_tracing_file(tracer_path);
 	close(fd);
-- 
2.30.2


  parent reply	other threads:[~2021-06-25 22:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-25 22:17 [PATCH 0/4] libtracefs: Updates to tracefs_tracer_set() Steven Rostedt
2021-06-25 22:17 ` [PATCH 1/4] libtracefs: Add custom tracer " Steven Rostedt
2021-06-25 22:17 ` Steven Rostedt [this message]
2021-06-25 22:17 ` [PATCH 3/4] libtracefs: Check tracer parameter first in tracefs_tracer_set() Steven Rostedt
2021-06-25 22:17 ` [PATCH 4/4] libtracefs: Add documentation for tracefs_tracer_set/clear() 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=20210625221739.1215557-3-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=sameeross1994@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).