It is unsafe to suspend devices if the hardware is controlled by X.  Add an
extra check to prevent this from happening.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  *
  */
 
+#include <linux/vt_kern.h>
 #include <linux/device.h>
 #include "../base.h"
 #include "power.h"
        return error;
 }
 
-
 /**
  *     device_suspend - Save state and stop all devices in system.
  *     @state:         Power state to put each device in.
 {
        int error = 0;
 
+       if (!is_console_suspend_safe())
+               return -EINVAL;
+
        down(&dpm_sem);
        down(&dpm_list_sem);
        while (!list_empty(&dpm_active) && error == 0) {
 
        }
 }
 
+int is_console_suspend_safe(void)
+{
+       /* It is unsafe to suspend devices while X has control of the
+        * hardware. Make sure we are running on a kernel-controlled console.
+        */
+       return vc_cons[fg_console].d->vc_mode == KD_TEXT;
+}
+
 /*
  *     Visible symbols for modules
  */
 
 int vt_waitactive(int vt);
 void change_console(struct vc_data *new_vc);
 void reset_vc(struct vc_data *vc);
+#ifdef CONFIG_VT
+int is_console_suspend_safe(void);
+#else
+static inline int is_console_suspend_safe(void) { return 1; }
+#endif
 
 /*
  * vc_screen.c shares this temporary buffer with the console write code so that