#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[] = {
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;
}
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);
}
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;
}
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;
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;
}
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;
}
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: