diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c
index 8b1d743..ac7eb3a 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -442,6 +442,51 @@ gsm_manager_quit (GsmManager *manager)
 }
 
 static void
+gsm_manager_run_shutdown_scripts_from_dir (const gchar *path)
+{
+        GDir       *dir;
+        const char *name;
+
+        g_debug ("GsmManager: *** Running shutdown scripts for %s", path);
+
+        dir = g_dir_open (path, 0, NULL);
+        if (dir == NULL) {
+                return;
+        }
+
+        while ((name = g_dir_read_name (dir))) {
+                gchar  *script;
+                gchar  *argv[2] = {NULL};
+                GError *error = NULL;
+
+                script = g_build_filename (path, name, NULL);
+                argv[0] = script;
+
+                if (!g_spawn_sync (path, argv, NULL, 0, NULL, NULL, NULL, NULL, NULL, &error)) {
+                        g_warning ("Could not run script '%s': %s\n", name, error->message);
+                        g_error_free (error);
+                }
+
+                g_free (script);
+        }
+
+        g_dir_close (dir);
+}
+
+static void
+gsm_manager_run_shutdown_scripts (void)
+{
+        gchar **shutdown_dirs = gsm_util_get_shutdown_dirs ();
+        int i;
+
+        for (i = 0; shutdown_dirs[i]; i++) {
+                gsm_manager_run_shutdown_scripts_from_dir (shutdown_dirs[i]);
+        }
+
+        g_strfreev (shutdown_dirs);
+}
+
+static void
 end_phase (GsmManager *manager)
 {
         g_debug ("GsmManager: ending phase %s\n",
@@ -481,6 +526,7 @@ end_phase (GsmManager *manager)
                 start_phase (manager);
                 break;
         case GSM_MANAGER_PHASE_EXIT:
+                gsm_manager_run_shutdown_scripts ();
                 gsm_manager_quit (manager);
                 break;
         default:
diff --git a/gnome-session/gsm-util.c b/gnome-session/gsm-util.c
index d139b95..8a7e974 100644
--- a/gnome-session/gsm-util.c
+++ b/gnome-session/gsm-util.c
@@ -241,6 +241,27 @@ gsm_util_get_autostart_dirs ()
 }
 
 char **
+gsm_util_get_shutdown_dirs ()
+{
+        GPtrArray          *dirs;
+        const char * const *system_data_dirs;
+        int                 i;
+
+        dirs = g_ptr_array_new ();
+
+        system_data_dirs = g_get_system_data_dirs ();
+        for (i = 0; system_data_dirs[i]; i++) {
+                g_ptr_array_add (dirs,
+                                 g_build_filename (system_data_dirs[i],
+                                                   "gnome", "shutdown", NULL));
+        }
+
+        g_ptr_array_add (dirs, NULL);
+
+        return (char **) g_ptr_array_free (dirs, FALSE);
+}
+
+char **
 gsm_util_get_app_dirs ()
 {
         GPtrArray          *dirs;
diff --git a/gnome-session/gsm-util.h b/gnome-session/gsm-util.h
index b67a4ab..0201d76 100644
--- a/gnome-session/gsm-util.h
+++ b/gnome-session/gsm-util.h
@@ -35,6 +35,8 @@ gchar**     gsm_util_get_app_dirs                   (void);
 
 gchar**     gsm_util_get_autostart_dirs             (void);
 
+gchar**     gsm_util_get_shutdown_dirs              (void);
+
 gchar **    gsm_util_get_desktop_dirs               (void);
 
 gboolean    gsm_util_text_is_blank                  (const char *str);
