[PATCH] libkmod-module: convert return value from system() to errno

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Topi Miettinen <toiwoton@xxxxxxxxx>
---
 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
>From f560864a4a8fd61c2881cfefb970db27c2418690 Mon Sep 17 00:00:00 2001
From: Topi Miettinen <toiwoton@xxxxxxxxx>
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@xxxxxxxxx>
---
 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


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux