diff --git a/js/ui/runDialog.js b/js/ui/runDialog.js index fdfd36a8c..fd6344711 100644 --- a/js/ui/runDialog.js +++ b/js/ui/runDialog.js @@ -78,7 +78,10 @@ RunDialog.prototype = { }, _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(); diff --git a/src/shell-global.c b/src/shell-global.c index 55b837859..5d57437f0 100644 --- a/src/shell-global.c +++ b/src/shell-global.c @@ -5,6 +5,9 @@ #include "display.h" #include +#include +#include +#include struct _ShellGlobal { GObject parent; @@ -335,3 +338,38 @@ shell_global_ungrab_keyboard (ShellGlobal *global) 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 diff --git a/src/shell-global.h b/src/shell-global.h index 1970b0ac4..8888cebec 100644 --- a/src/shell-global.h +++ b/src/shell-global.h @@ -52,6 +52,8 @@ MetaScreen * shell_global_get_screen (ShellGlobal *global); 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__ */