]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
rmmod: prefer ERR over plain fprintf
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Mon, 5 Nov 2012 19:51:32 +0000 (17:51 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Mon, 5 Nov 2012 20:31:19 +0000 (18:31 -0200)
tools/rmmod.c

index 843c4f54df17b3290760ae94e73045c3a0a1a251..d57e8bdbf4e548278148ac94f7d7b6a621c7c331 100644 (file)
@@ -28,6 +28,8 @@
 #include <syslog.h>
 #include "libkmod.h"
 
+#define LOGPREFIX "rmmod: "
+#define ERR(...) fprintf(stderr, LOGPREFIX "ERROR: " __VA_ARGS__)
 
 static const char cmdopts_s[] = "fsvVwh";
 static const struct option cmdopts[] = {
@@ -102,7 +104,7 @@ static int check_module_inuse(struct kmod_module *mod) {
        struct kmod_list *holders;
 
        if (kmod_module_get_initstate(mod) == -ENOENT) {
-               fprintf(stderr, "Error: Module %s is not currently loaded\n",
+               ERR("Module %s is not currently loaded\n",
                                kmod_module_get_name(mod));
                return -ENOENT;
        }
@@ -111,8 +113,7 @@ static int check_module_inuse(struct kmod_module *mod) {
        if (holders != NULL) {
                struct kmod_list *itr;
 
-               fprintf(stderr, "Error: Module %s is in use by:",
-                               kmod_module_get_name(mod));
+               ERR("Module %s is in use by:", kmod_module_get_name(mod));
 
                kmod_list_foreach(itr, holders) {
                        struct kmod_module *hm = kmod_module_get_module(itr);
@@ -126,8 +127,7 @@ static int check_module_inuse(struct kmod_module *mod) {
        }
 
        if (kmod_module_get_refcnt(mod) != 0) {
-               fprintf(stderr, "Error: Module %s is in use\n",
-                               kmod_module_get_name(mod));
+               ERR("Module %s is in use\n", kmod_module_get_name(mod));
                return -EBUSY;
        }
 
@@ -159,7 +159,7 @@ static int do_rmmod(int argc, char *argv[])
                        verbose++;
                        break;
                case 'w':
-                       fprintf(stderr, "'Wait' behavior is targeted for removal from kernel.\nWe will now sleep for 10s, and then continue.\n");
+                       ERR("'Wait' behavior is targeted for removal from kernel.\nWe will now sleep for 10s, and then continue.\n");
                        sleep(10);
                        flags &= ~KMOD_REMOVE_NOWAIT;
                        break;
@@ -172,21 +172,19 @@ static int do_rmmod(int argc, char *argv[])
                case '?':
                        return EXIT_FAILURE;
                default:
-                       fprintf(stderr,
-                               "Error: unexpected getopt_long() value '%c'.\n",
-                               c);
+                       ERR("unexpected getopt_long() value '%c'.\n", c);
                        return EXIT_FAILURE;
                }
        }
 
        if (optind >= argc) {
-               fprintf(stderr, "Error: missing module name.\n");
+               ERR("missing module name.\n");
                return EXIT_FAILURE;
        }
 
        ctx = kmod_new(NULL, &null_config);
        if (!ctx) {
-               fputs("Error: kmod_new() failed!\n", stderr);
+               ERR("kmod_new() failed!\n");
                return EXIT_FAILURE;
        }
 
@@ -206,8 +204,8 @@ static int do_rmmod(int argc, char *argv[])
                        err = kmod_module_new_from_name(ctx, arg, &mod);
 
                if (err < 0) {
-                       fprintf(stderr, "Error: could not use module %s: %s\n",
-                               arg, strerror(-err));
+                       ERR("could not use module %s: %s\n", arg,
+                           strerror(-err));
                        break;
                }
 
@@ -219,9 +217,8 @@ static int do_rmmod(int argc, char *argv[])
 
                err = kmod_module_remove_module(mod, flags);
                if (err < 0) {
-                       fprintf(stderr,
-                               "Error: could not remove module %s: %s\n",
-                               arg, strerror(-err));
+                       ERR("could not remove module %s: %s\n", arg,
+                           strerror(-err));
                        r++;
                }
 next: