linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Topi Miettinen <toiwoton@gmail.com>
To: linux-modules@vger.kernel.org
Subject: [PATCH] libkmod-module: convert return value from system() to errno
Date: Mon, 23 Dec 2019 19:06:31 +0200	[thread overview]
Message-ID: <f8c64aed-b4a1-e43f-ed4b-f99236932477@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1069 bytes --]

Don't use exit status of a command directly as errno code, callers
will be confused.

Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
---
  libkmod/libkmod-module.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 8044a8f..6031d80 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -983,11 +983,13 @@ static int command_do(struct kmod_module *mod, 
const char *type,
         if (err == -1 || WEXITSTATUS(err)) {
                 ERR(mod->ctx, "Error running %s command for %s\n",
                                                                 type, 
modname);
-               if (err != -1)
-                       err = -WEXITSTATUS(err);
+               if (err != -1) /* nonzero exit status: something bad 
happened */
+                       return -EINVAL;
+               else /* child process could not be created */
+                       return -errno;
         }

-       return err;
+       return 0;
  }

  struct probe_insert_cb {
-- 
2.24.0

[-- Attachment #2: 0001-libkmod-module-convert-return-value-from-system-to-e.patch --]
[-- Type: text/x-diff, Size: 1099 bytes --]

From f560864a4a8fd61c2881cfefb970db27c2418690 Mon Sep 17 00:00:00 2001
From: Topi Miettinen <toiwoton@gmail.com>
Date: Mon, 23 Dec 2019 18:58:13 +0200
Subject: [PATCH] libkmod-module: convert return value from system() to errno

Don't use exit status of a command directly as errno code, callers
will be confused.

Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
---
 libkmod/libkmod-module.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 8044a8f..6031d80 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -983,11 +983,13 @@ static int command_do(struct kmod_module *mod, const char *type,
 	if (err == -1 || WEXITSTATUS(err)) {
 		ERR(mod->ctx, "Error running %s command for %s\n",
 								type, modname);
-		if (err != -1)
-			err = -WEXITSTATUS(err);
+		if (err != -1) /* nonzero exit status: something bad happened */
+			return -EINVAL;
+		else /* child process could not be created */
+			return -errno;
 	}
 
-	return err;
+	return 0;
 }
 
 struct probe_insert_cb {
-- 
2.24.0


             reply	other threads:[~2019-12-23 17:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-23 17:06 Topi Miettinen [this message]
2019-12-24  2:54 ` [PATCH] libkmod-module: convert return value from system() to errno Lucas De Marchi
2019-12-24  9:54   ` Topi Miettinen
2019-12-28 22:59     ` Lucas De Marchi
2019-12-29 11:04       ` Topi Miettinen

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=f8c64aed-b4a1-e43f-ed4b-f99236932477@gmail.com \
    --to=toiwoton@gmail.com \
    --cc=linux-modules@vger.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 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).