only remove module if we inserted it
authornotaz <notaz@pixelinis>
Sat, 31 Jul 2010 15:45:37 +0000 (18:45 +0300)
committernotaz <notaz@pixelinis>
Sat, 31 Jul 2010 15:45:37 +0000 (18:45 +0300)
something may need to keep it loaded, like it is in ginge project.

warm.c

diff --git a/warm.c b/warm.c
index 5dad50d..c79c63e 100644 (file)
--- a/warm.c
+++ b/warm.c
@@ -50,6 +50,7 @@ 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)
 {
@@ -145,6 +146,8 @@ int warm_init(void)
                                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)
@@ -166,20 +169,22 @@ void warm_finish(void)
        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, PFX "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);
+               }
        }
 }