[PATCH] Wait for external "convert" in pango-view



Hi,

I tried "pango-view" in a script to render text to a file, and I found 
that upon exit, the file doesn't exist for some fraction of a second, 
which causes problems for the script when it tries to do something 
with the output.

To illustrate,

  $ rm -f text.ppm; pango-view --backend=ft2 -q -o text.ppm -t 'Hi there!'; \
      ls -l text.ppm; sleep 1; ls -l text.ppm
  ls: cannot access text.ppm: No such file or directory
  -rw-r--r-- 1 guinan guinan 18242 Apr 23 13:19 text.ppm

See attached patch for a fix.  I added a waitpid() call similar to the 
one later in the same file.

-Jamie
--- pango-1.21.0/pango-view/viewer-main.c.ori	2007-07-05 17:30:28.000000000 -0400
+++ pango-1.21.0/pango-view/viewer-main.c	2008-04-23 13:01:58.000000000 -0400
@@ -69,6 +69,7 @@
       else
 	{
 	  FILE *stream;
+	  GPid pid = 0;
 
 	  if (view->write_suffix && g_str_has_suffix (opt_output, view->write_suffix))
 	    {
@@ -86,15 +87,22 @@
 	      convert_argv[2] = opt_output;
 
 	      if (!g_spawn_async_with_pipes (NULL, (gchar **)convert_argv, NULL,
+					     G_SPAWN_DO_NOT_REAP_CHILD |
 					     G_SPAWN_SEARCH_PATH |
 					     G_SPAWN_STDOUT_TO_DEV_NULL |
 					     G_SPAWN_STDERR_TO_DEV_NULL,
-					     NULL, NULL, NULL, &fd, NULL, NULL, &error))
+					     NULL, NULL, &pid, &fd, NULL, NULL, &error))
 		fail ("When running ImageMagick 'convert' command: %s\n", error->message);
 	      stream = fdopen (fd, "wb");
 	    }
 	  view->write (instance, surface, stream, width, height);
 	  fclose (stream);
+#ifdef G_OS_UNIX
+	  if (pid)
+	    {
+	      waitpid (pid, NULL, 0);
+	    }
+#endif
 	}
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]