I have made the following changes intended for :
  CE:MW:Shared / dsme

Please review and accept or decline.
BOSS has already run some checks on this request.
See the "Messages from BOSS" section below.

https://build.pub.meego.com//request/show/6907

Thank You,
Pekka Lundstrom

[This message was auto-generated]

---

Request # 6907:

Messages from BOSS:

State: review at 2012-10-04T13:44:38 by bossbot

Reviews:
       accepted by bossbot : Prechecks succeeded.
       new for CE-maintainers : Please replace this text with a review and 
approve/reject the review (not the SR). BOSS will take care of the rest

Changes:
  submit: home:plundstr:branches:CE:MW:Shared / dsme -> CE:MW:Shared / dsme
  
changes files:
--------------
--- dsme.changes
+++ dsme.changes
@@ -0,0 +1,4 @@
+* Thu Oct 04 2012 Pekka Lundstrom <[email protected]> - 0.62.5
+- Changed oom.c so that it supports oom value change both on new and old kernel
+  Fixes NEMO#475: dsme gives warning about deprecated use of oom_adj
+

old:
----
  dsme-0.62.4.tar.gz

new:
----
  dsme-0.62.5.tar.gz

spec files:
-----------
--- dsme.spec
+++ dsme.spec
@@ -9,7 +9,7 @@
 # << macros
 
 Summary:    Device State Management Entity
-Version:    0.62.4
+Version:    0.62.5
 Release:    0
 Group:      System/System Control
 License:    LGPLv2+

other changes:
--------------

++++++ dsme-0.62.4.tar.gz -> dsme-0.62.5.tar.gz
--- configure.ac
+++ configure.ac
@@ -1,5 +1,5 @@
 # Package name and version
-AC_INIT(dsme, 0.62.4)
+AC_INIT(dsme, 0.62.5)
 
 AM_INIT_AUTOMAKE
 
--- dsme/oom.c
+++ dsme/oom.c
@@ -27,43 +27,82 @@
 
 #include <stdio.h>
 #include <errno.h>
+#include <sys/stat.h>
+#include "dsme/logging.h"
 
-#define OOM_ADJ_PATH            "/proc/self/oom_adj"
-#define OOM_ADJ_PROTECT_VALUE   (-17)
-#define OOM_ADJ_UNPROTECT_VALUE 0
-
-static bool set_oom_adj_value(int i)
+/* Kernel 2.6.36 and newer are using /proc/<pid>/oom_score_adj
+ * and older kernels /proc/<pid>/oom_adj
+ * We support both and detect it on the fly
+ */
+
+#define OOM_ADJ_PATH_OLD        "/proc/self/oom_adj"
+#define OOM_ADJ_PATH_NEW        "/proc/self/oom_score_adj"
+#define OOM_PROTECT_VALUE_OLD   (-17)
+#define OOM_PROTECT_VALUE_NEW   (-1000)
+#define OOM_UNPROTECT_VALUE     0
+typedef enum {oom_protected, oom_unprotected} oom_mode;
+  
+static bool set_oom_protection_mode(oom_mode mode)
 {
   FILE* file = 0;
+  const char* new_path = OOM_ADJ_PATH_NEW;
+  const char* old_path = OOM_ADJ_PATH_OLD;
+  char* oom_path;
+  int  oom_value;
+  struct stat st;
+
+  if (stat(OOM_ADJ_PATH_NEW, &st) == 0) {
+    oom_path = (char*)new_path;
+  } else {
+    oom_path = (char*)old_path; 
+  }
+
+  if (mode == oom_protected) {
+      if (oom_path == new_path) {
+          oom_value = OOM_PROTECT_VALUE_NEW;
+      } else {
+          oom_value = OOM_PROTECT_VALUE_OLD;
+      }
+  } else {
+      oom_value = OOM_UNPROTECT_VALUE;
+  }
 
-  file = fopen(OOM_ADJ_PATH, "w");
+  file = fopen(oom_path, "w");
   if (!file) {
+      dsme_log(LOG_ERR, "set_oom_protection_mode() can't open %s", oom_path);
       return false;
   }
 
-  if (fprintf(file, "%i", i) < 0) {
+  if (fprintf(file, "%i", oom_value) < 0) {
       (void)fclose(file);
+      dsme_log(LOG_CRIT, "set_oom_protection_mode(%s,%i) failed", oom_path, 
oom_value);
       return false;
   }
 
   if (fclose(file) < 0) {
       return false;
   }
-
   return true;
 }
 
 bool protect_from_oom(void)
 {
-  return set_oom_adj_value(OOM_ADJ_PROTECT_VALUE);
+  return set_oom_protection_mode(oom_protected);
 }
 
 bool unprotect_from_oom(void)
 {
-  return set_oom_adj_value(OOM_ADJ_UNPROTECT_VALUE);
+  return set_oom_protection_mode(oom_unprotected);
 }
 
 bool adjust_oom(int oom_adj)
 {
-  return set_oom_adj_value(oom_adj);
+  /* This function is not used anywhere, but we keep it anyhow 
+   * Actual value can not be set anymore but only protected/unprotected
+   */
+  if (oom_adj < 0) {
+      return set_oom_protection_mode(oom_protected);
+  } else {
+      return set_oom_protection_mode(oom_unprotected);
+  }
 }

++++++ dsme.yaml
--- dsme.yaml
+++ dsme.yaml
@@ -1,6 +1,6 @@
 Name: dsme
 Summary: Device State Management Entity
-Version: 0.62.4
+Version: 0.62.5
 Release: 0
 Group: System/System Control
 License: LGPLv2+



Reply via email to