gnome-shell r130 - in trunk: js/ui src



Author: walters
Date: Thu Dec 18 20:57:37 2008
New Revision: 130
URL: http://svn.gnome.org/viewvc/gnome-shell?rev=130&view=rev

Log:
Add magic 'restart' command to run dialog which re-executes

This is immensely convenient for debugging.  The shell global reexec_self
only works on Linux, sue me.

http://bugzilla.gnome.org/show_bug.cgi?id=565037

Modified:
   trunk/js/ui/runDialog.js
   trunk/src/shell-global.c
   trunk/src/shell-global.h

Modified: trunk/js/ui/runDialog.js
==============================================================================
--- trunk/js/ui/runDialog.js	(original)
+++ trunk/js/ui/runDialog.js	Thu Dec 18 20:57:37 2008
@@ -78,7 +78,10 @@
     },
 
     _run : function(command) {
-        if (command) {
+        if (command == 'restart') {
+            let global = Shell.Global.get();
+            global.reexec_self();
+        } else if (command) {
             var p = new Shell.Process({'args' : [command]});
             try {
                 p.run();

Modified: trunk/src/shell-global.c
==============================================================================
--- trunk/src/shell-global.c	(original)
+++ trunk/src/shell-global.c	Thu Dec 18 20:57:37 2008
@@ -5,6 +5,9 @@
 
 #include "display.h"
 #include <clutter/x11/clutter-x11.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
 
 struct _ShellGlobal {
   GObject parent;
@@ -335,3 +338,38 @@
 
   global->keyboard_grabbed = FALSE;
 }
+
+/**
+ * shell_global_reexec_self:
+ * @global: A #ShellGlobal
+ * 
+ * Restart the current process.  Only intended for development purposes. 
+ */
+void 
+shell_global_reexec_self (ShellGlobal *global)
+{
+  GPtrArray *arr;
+  gsize len;
+  char *buf;
+  char *buf_p;
+  char *buf_end;
+  GError *error = NULL;
+  
+  /* Linux specific (I think, anyways). */
+  if (!g_file_get_contents ("/proc/self/cmdline", &buf, &len, &error))
+    {
+      g_warning ("failed to get /proc/self/cmdline: %s", error->message);
+      return;
+    }
+      
+  buf_end = buf+len;
+  arr = g_ptr_array_new ();
+  /* The cmdline file is NUL-separated */
+  for (buf_p = buf; buf_p < buf_end; buf_p = buf_p + strlen (buf_p) + 1)
+    g_ptr_array_add (arr, buf_p);
+  
+  g_ptr_array_add (arr, NULL); 
+  execvp (arr->pdata[0], (char**)arr->pdata);
+  g_warning ("failed to reexec: %s", g_strerror (errno));
+  g_ptr_array_free (arr, TRUE);
+}
\ No newline at end of file

Modified: trunk/src/shell-global.h
==============================================================================
--- trunk/src/shell-global.h	(original)
+++ trunk/src/shell-global.h	Thu Dec 18 20:57:37 2008
@@ -52,6 +52,8 @@
 gboolean shell_global_grab_keyboard   (ShellGlobal *global);
 void     shell_global_ungrab_keyboard (ShellGlobal *global);
 
+void shell_global_reexec_self (ShellGlobal *global);
+
 G_END_DECLS
 
 #endif /* __SHELL_GLOBAL_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]