http://ftp.x.org/contrib/applications/xscreensaver-3.10.tar.gz
[xscreensaver] / driver / xscreensaver.c
index 7b16c898aaab4d95f22aa643084ed3842b2cd772..4460c19df6125b9c358df07e4a3a179bb06f98e4 100644 (file)
@@ -419,12 +419,29 @@ set_version_string (saver_info *si, int *argc, char **argv)
 static void
 privileged_initialization (saver_info *si, int *argc, char **argv)
 {
+#ifndef NO_LOCKING
+  /* before hack_uid() for proper permissions */
+  lock_priv_init (*argc, argv, si->prefs.verbose_p);
+#endif /* NO_LOCKING */
+
+#ifndef NO_SETUID
+  hack_uid (si);
+#endif /* NO_SETUID */
+}
+
+
+/* Figure out what locking mechanisms are supported.
+ */
+static void
+lock_initialization (saver_info *si, int *argc, char **argv)
+{
 #ifdef NO_LOCKING
   si->locking_disabled_p = True;
   si->nolock_reason = "not compiled with locking support";
 #else /* !NO_LOCKING */
   si->locking_disabled_p = False;
-  /* before hack_uid() for proper permissions */
+
+  /* Finish initializing locking, now that we're out of privileged code. */
   if (! lock_init (*argc, argv, si->prefs.verbose_p))
     {
       si->locking_disabled_p = True;
@@ -879,7 +896,25 @@ main_loop (saver_info *si)
 
       maybe_reload_init_file (si);
 
-      blank_screen (si);
+      if (! blank_screen (si))
+        {
+          /* We were unable to grab either the keyboard or mouse.
+             This means we did not (and must not) blank the screen.
+             If we were to blank the screen while some other program
+             is holding both the mouse and keyboard grabbed, then
+             we would never be able to un-blank it!  We would never
+             see any events, and the display would be wedged.
+
+             So, just go around the loop again and wait for the
+             next bout of idleness.
+          */
+
+          fprintf (stderr,
+                  "%s: unable to grab keyboard or mouse!  Blanking aborted.\n",
+                   blurb());
+          continue;
+        }
+
       kill_screenhack (si);
       spawn_screenhack (si, True);
 
@@ -997,6 +1032,7 @@ main (int argc, char **argv)
       exit (1);
 
   load_init_file (p);
+  lock_initialization (si, &argc, argv);
 
   if (p->xsync_p) XSynchronize (si->dpy, True);
   blurb_timestamp_p = p->timestamp_p;  /* kludge */