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

svn path=/trunk/; revision=130
This commit is contained in:
Colin Walters 2008-12-18 20:57:37 +00:00
parent f059492a20
commit 6a1e408c44
3 changed files with 44 additions and 1 deletions

View File

@ -78,7 +78,10 @@ RunDialog.prototype = {
}, },
_run : function(command) { _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]}); var p = new Shell.Process({'args' : [command]});
try { try {
p.run(); p.run();

View File

@ -5,6 +5,9 @@
#include "display.h" #include "display.h"
#include <clutter/x11/clutter-x11.h> #include <clutter/x11/clutter-x11.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
struct _ShellGlobal { struct _ShellGlobal {
GObject parent; GObject parent;
@ -335,3 +338,38 @@ shell_global_ungrab_keyboard (ShellGlobal *global)
global->keyboard_grabbed = FALSE; 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);
}

View File

@ -52,6 +52,8 @@ MetaScreen * shell_global_get_screen (ShellGlobal *global);
gboolean shell_global_grab_keyboard (ShellGlobal *global); gboolean shell_global_grab_keyboard (ShellGlobal *global);
void shell_global_ungrab_keyboard (ShellGlobal *global); void shell_global_ungrab_keyboard (ShellGlobal *global);
void shell_global_reexec_self (ShellGlobal *global);
G_END_DECLS G_END_DECLS
#endif /* __SHELL_GLOBAL_H__ */ #endif /* __SHELL_GLOBAL_H__ */