#define WARM_CODE
#include "warm.h"
+#define PFX "wARM: "
+
/* provided by glibc */
extern long init_module(void *, unsigned long, const char *);
extern long delete_module(const char *, unsigned int);
static int warm_fd = -1;
static int kernel_version;
+static int module_inserted;
static void sys_cacheflush(void *start, void *end)
{
read_len = fread(buff, 1, len, f);
if (read_len != len) {
- fprintf(stderr, "failed to read module\n");
+ fprintf(stderr, PFX "failed to read module\n");
goto fail1;
}
uname(&unm);
if (strlen(unm.release) < 3 || unm.release[1] != '.') {
- fprintf(stderr, "unexpected version string: %s\n", unm.release);
+ fprintf(stderr, PFX "unexpected version string: %s\n", unm.release);
goto fail;
}
kernel_version = ((unm.release[0] - '0') << 4) | (unm.release[2] - '0');
/* try to insmod */
ret = system(buff2);
if (ret != 0) {
- fprintf(stderr, "system/insmod failed: %d %d\n", ret, errno);
+ fprintf(stderr, PFX "system/insmod failed: %d %d\n", ret, errno);
if (kernel_version >= 0x26) {
ret = manual_insmod_26(buff1, "verbose=1");
if (ret != 0)
- fprintf(stderr, "manual insmod also failed: %d\n", ret);
+ fprintf(stderr, PFX "manual insmod also failed: %d\n", ret);
}
}
+ if (ret == 0)
+ module_inserted = 1;
warm_fd = open("/proc/warm", O_RDWR);
if (warm_fd >= 0)
return 0;
fail:
- fprintf(stderr, "wARM: can't init, acting as sys_cacheflush wrapper\n");
+ fprintf(stderr, PFX "can't init, acting as sys_cacheflush wrapper\n");
return -1;
}
close(warm_fd);
warm_fd = -1;
- if (kernel_version < 0x26) {
- struct utsname unm;
- memset(&unm, 0, sizeof(unm));
- uname(&unm);
- snprintf(name, sizeof(name), "warm_%s", unm.release);
- }
- else
- strcpy(name, "warm");
-
- snprintf(cmd, sizeof(cmd), "/sbin/rmmod %s", name);
- ret = system(cmd);
- if (ret != 0) {
- fprintf(stderr, "system/rmmod failed: %d %d\n", ret, errno);
- manual_rmmod(name);
+ if (module_inserted) {
+ if (kernel_version < 0x26) {
+ struct utsname unm;
+ memset(&unm, 0, sizeof(unm));
+ uname(&unm);
+ snprintf(name, sizeof(name), "warm_%s", unm.release);
+ }
+ else
+ strcpy(name, "warm");
+
+ snprintf(cmd, sizeof(cmd), "/sbin/rmmod %s", name);
+ ret = system(cmd);
+ if (ret != 0) {
+ fprintf(stderr, PFX "system/rmmod failed: %d %d\n", ret, errno);
+ manual_rmmod(name);
+ }
}
}