ftp://ftp.krokus.ru/pub/OpenBSD/distfiles/xscreensaver-4.06.tar.gz
[xscreensaver] / utils / grabclient.c
index 0a1d2ac72630aafbf4971baece2d4819a484ec4e..0acb2853985a962091fe3955e354c83d4d52ab19 100644 (file)
@@ -101,6 +101,26 @@ checkerboard (Screen *screen, Window window)
       }
 }
 
+static void
+hack_subproc_environment (Display *dpy)
+{
+  /* Store $DISPLAY into the environment, so that the $DISPLAY variable that
+     the spawned processes inherit is what we are actually using.
+   */
+  const char *odpy = DisplayString (dpy);
+  char *ndpy = (char *) malloc(strlen(odpy) + 20);
+  strcpy (ndpy, "DISPLAY=");
+  strcat (ndpy, odpy);
+
+  /* Allegedly, BSD 4.3 didn't have putenv(), but nobody runs such systems
+     any more, right?  It's not Posix, but everyone seems to have it. */
+#ifdef HAVE_PUTENV
+  if (putenv (ndpy))
+    abort ();
+#endif /* HAVE_PUTENV */
+}
+
+
 void
 grab_screen_image (Screen *screen, Window window)
 {
@@ -117,7 +137,7 @@ grab_screen_image (Screen *screen, Window window)
       exit (1);
     }
 
-  sprintf (id, "0x%x", (unsigned long) window);
+  sprintf (id, "0x%lx", (unsigned long) window);
   cmd = (char *) malloc (strlen(grabber) + strlen(id) + 1);
 
   /* Needn't worry about buffer overflows here, because the buffer is
@@ -134,6 +154,7 @@ grab_screen_image (Screen *screen, Window window)
   checkerboard (screen, window);
 
   XSync (dpy, True);
+  hack_subproc_environment (dpy);
   system (cmd);
   free (cmd);
   XSync (dpy, True);