[maemo-commits] [maemo-commits] r13556 - in projects/haf/trunk/hildon-desktop: . src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Mon Sep 3 13:00:15 EEST 2007
Author: jobi
Date: 2007-09-03 13:00:09 +0300 (Mon, 03 Sep 2007)
New Revision: 13556

Modified:
   projects/haf/trunk/hildon-desktop/ChangeLog
   projects/haf/trunk/hildon-desktop/src/hd-applications-menu.c
   projects/haf/trunk/hildon-desktop/src/main.c
Log:

2007-09-03 Johan Bilien  <johan.bilien at nokia.com>

	* src/main.c: added fork wrapper to unprotect children
	from OOM-killing and reset their priority. Fixes: NB#49535
	* src/hd-application-menu.c: removed duplicate code



Modified: projects/haf/trunk/hildon-desktop/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-desktop/ChangeLog	2007-09-03 09:20:48 UTC (rev 13555)
+++ projects/haf/trunk/hildon-desktop/ChangeLog	2007-09-03 10:00:09 UTC (rev 13556)
@@ -1,3 +1,9 @@
+2007-09-03 Johan Bilien  <johan.bilien at nokia.com>
+
+	* src/main.c: added fork wrapper to unprotect children
+	from OOM-killing and reset their priority. Fixes: NB#49535
+	* src/hd-application-menu.c: removed duplicate code
+
 2007-08-31 Johan Bilien  <johan.bilien at nokia.com>
 
 	* configure.ac: 0.0.34

Modified: projects/haf/trunk/hildon-desktop/src/hd-applications-menu.c
===================================================================
--- projects/haf/trunk/hildon-desktop/src/hd-applications-menu.c	2007-09-03 09:20:48 UTC (rev 13555)
+++ projects/haf/trunk/hildon-desktop/src/hd-applications-menu.c	2007-09-03 10:00:09 UTC (rev 13556)
@@ -510,35 +510,6 @@
     
         g_clear_error (&error);
       }
-      else
-      {
-        int priority;
-        errno = 0;
-        gchar *oom_filename;
-        int fd;
-
-        /* If the child process inherited desktop's high priority,
-         * give child default priority */
-        priority = getpriority (PRIO_PROCESS, child_pid);
-    
-        if (!errno && priority < 0)
-        {
-          setpriority (PRIO_PROCESS, child_pid, 0);
-        }
-
-        /* Unprotect from OOM */
-        oom_filename = g_strdup_printf ("/proc/%i/oom_adj",
-                                        child_pid);
-        fd = open (oom_filename, O_WRONLY);
-        g_free (oom_filename);
-
-        if (fd >= 0)
-          {
-            write (fd, "0", sizeof (char));
-            close (fd);
-          }
-
-      }
     }
     else
     {

Modified: projects/haf/trunk/hildon-desktop/src/main.c
===================================================================
--- projects/haf/trunk/hildon-desktop/src/main.c	2007-09-03 09:20:48 UTC (rev 13555)
+++ projects/haf/trunk/hildon-desktop/src/main.c	2007-09-03 10:00:09 UTC (rev 13556)
@@ -29,14 +29,79 @@
 #include <locale.h>
 
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
 #include <gtk/gtk.h>
 #include <libgnomevfs/gnome-vfs.h>
 
+/* getpriority, setpriority */
+#include <sys/time.h>
+#include <sys/resource.h>
+
+/* dlsym */
+#define __USE_GNU
+#include <dlfcn.h>
+
+/* open */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <errno.h>
+
 #include "hd-desktop.h"
 
 #define OSSO_USER_DIR        ".osso"
 #define HILDON_DESKTOP_GTKRC "current-gtk-theme.maemo_af_desktop"
 
+/*
+ * hildon-desktop is typically running with higher priority and
+ * runs protected against out-of-memory killing from the kernel.
+ * Spawned children however should not be given these priviledges.
+ */
+pid_t
+fork (void)
+{
+  static pid_t (*fork_real) () = NULL;
+  pid_t         pid;
+
+  if (fork_real == NULL)
+    fork_real = dlsym (RTLD_NEXT, "fork");
+
+  pid = fork_real ();
+
+  if (pid == 0)
+  {
+    pid_t       child_pid;
+    int         priority;
+    int         fd;
+
+    errno = 0;
+
+    child_pid = getpid ();
+
+    /* If the child process inherited desktop's high priority,
+     * give child default priority */
+    priority = getpriority (PRIO_PROCESS, child_pid);
+
+    if (!errno && priority < 0)
+    {
+      setpriority (PRIO_PROCESS, child_pid, 0);
+    }
+
+    /* Unprotect from OOM */
+    fd = g_open ("/proc/self/oom_adj", O_WRONLY, 0);
+
+    if (fd >= 0)
+    {
+      write (fd, "0", sizeof (char));
+      close (fd);
+    }
+
+  }
+
+  return pid;
+}
+
 int main (int argc, char **argv)
 {
   GObject *desktop;


More information about the maemo-commits mailing list