After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 108659 - Plug-ins should use g_spawn instead of popen
Plug-ins should use g_spawn instead of popen
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Plugins
git master
Other Linux
: Normal minor
: Future
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2003-03-18 08:57 UTC by Manish Singh
Modified: 2005-03-02 02:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to use g_spawn API in plug-in ps (12.10 KB, patch)
2004-01-24 21:13 UTC, Peter Kirchgessner
needs-work Details | Review
Patch to use GPtrArray. Patches patched version. (4.89 KB, patch)
2004-01-25 15:04 UTC, Peter Kirchgessner
none Details | Review
Patch against CVS for gspawn API, -dBATCH (12.47 KB, patch)
2004-01-25 20:18 UTC, Peter Kirchgessner
committed Details | Review

Description Manish Singh 2003-03-18 08:57:10 UTC
popen is quite idiosyncratic across platforms, plus (at least on Unix)
involves the shell, leading to subtle bugs. The ps, mail, and print
plug-ins should use gspawn so we don't need to worry about such things.
Comment 1 Tomas Mraz 2003-07-24 14:27:25 UTC
Changing milestone to 2.0 as this is really minor problem and could be
fixed in the 2.0 releases.

Comment 2 Sven Neumann 2004-01-12 07:40:31 UTC
With the removal of EMX support this should have become a good deal
simpler. Would be nice to see this happening still but it's not a blocker.
Comment 3 Peter Kirchgessner 2004-01-12 21:26:09 UTC
Removing popen() needs to add mknod() and something like tempnam() to
get a name for the named pipe. mkstemp() or g_mkstemp() can not be
used, because they open an ordinary file.
Is mknod() and tempnam() available on all systems where popen() is
already running ?
Comment 4 Manish Singh 2004-01-12 21:48:34 UTC
No, we shouldn't be using named pipes, but the GSpawn API, which wraps
the anonymous pipe creation for us in a portable fashion.


http://developer.gnome.org/doc/API/2.0/glib/glib-Spawning-Processes.html

The main problem with popen is that it uses /bin/sh, which means have
all the shell quoting problems to deal with.
Comment 5 Peter Kirchgessner 2004-01-24 21:13:38 UTC
Created attachment 23715 [details] [review]
patch to use g_spawn API in plug-in ps
Comment 6 Peter Kirchgessner 2004-01-24 21:19:04 UTC
The patch is against pre1-tarball. Tested on Linux. Needs to be tested
on Windows, specially with input files that contain blanks etc. Every
quoting of input files has been removed from the plug-in. This should
now be done by g_spawn...
Comment 7 Manish Singh 2004-01-25 00:05:29 UTC
Tor, can you test this?
Comment 8 Manish Singh 2004-01-25 00:28:53 UTC
In your patch Peter, could you consider using a GPtrArray? It's more
readable that way, imho.

Also, with GSpawn, can win32 can handle using a pipe and not a temp
file, right?

Comment 9 Tor Lillqvist 2004-01-25 01:14:05 UTC
The code has a comment "For instance, the Win32 port of ghostscript 
doesn't work correctly when using standard output as output file." I 
don't remember what the exact problems were, and don't know whether 
that still is true with current ghostscript versions. But it probably 
is safer to keep using the temp file on Win32, even if it of course 
would make the code cleaner if one could get rid of the 
USE_REAL_OUTPUTFILE ifdefs.

I'll check...
Comment 10 Manish Singh 2004-01-25 01:19:04 UTC
Doh, silly me, I just looked at the patch and not the source code
itself. In this case, I agree it's safer to keep using a temp file,
because I'm sure there are users with old ghostscript versions out
there, even if this issue is resolved in newer ones.
Comment 11 Peter Kirchgessner 2004-01-25 15:04:12 UTC
Created attachment 23730 [details] [review]
Patch to use GPtrArray. Patches patched version.
Comment 12 Sven Neumann 2004-01-25 15:27:17 UTC
A patch against the patched version makes it difficult to review and
to apply the change. Could you create a diff against CVS instead?
Comment 13 Peter Kirchgessner 2004-01-25 15:38:40 UTC
Hi,

I just uploaded the patch to use GPtrArray. About the problem with
ghostscript using pipes on Windows. I also don't remember why I added
this. I just did some tests and saw that when starting ghostscript, I
need to add the -dBATCH. Otherwise ghostscript does not finish on
Windows. I will add later another patch that includes this. Currently
I have to leave home so that I can't do it now.
Comment 14 Peter Kirchgessner 2004-01-25 15:41:17 UTC
OK, I will add a new patch that is based on the CVS-version. And it
also will include the -dBATCH. Takes some hours. I must leave now.
Comment 15 Peter Kirchgessner 2004-01-25 20:18:10 UTC
Created attachment 23737 [details] [review]
Patch against CVS for gspawn API, -dBATCH
Comment 16 Peter Kirchgessner 2004-01-25 20:19:23 UTC
Last patch is against pre1-tarball, uses g_spawn API, GPtrArray, -dBATCH.
Comment 17 Manish Singh 2004-01-25 20:47:52 UTC
Looks good, I'll clean it up and commit it.
Comment 18 Manish Singh 2004-01-25 23:47:08 UTC
2004-01-25  Manish Singh  <yosh@gimp.org>
                                                                     
          
        * plug-ins/common/postscript.c: use GSpawn instead of popen,
-dBATCH,
        fixes #108659 for this plugin. Thanks to Peter Kirchgessner
for the
        patch.

Btw, Peter, g_ptr_array_free doesn't free the pointed to memory, so I
used g_strfreev for that.
Comment 19 Sven Neumann 2004-01-25 23:57:20 UTC
So that's mail and print left, both probably quite simple to do. The
mail plug-in is quite useless and a port of the print plug-in to a
newer version of gimpprint is scheduled for 2.0.1 or 2.0.2. IMO this
bug isn't blocking the 2.0 release and could very well be moved to the
2.0.1 milestone already.
Comment 20 Manish Singh 2004-01-26 00:05:45 UTC
Agreed. We should look at the print plugin when we port to their new
API, and mail is pretty trivial and not that critical.
Comment 21 Sven Neumann 2004-03-25 13:40:05 UTC
Bumping to milestone 2.2. As long as it works, there's no good reason why this
should be changed in the stable branch.
Comment 22 Sven Neumann 2004-10-22 18:34:01 UTC
This shouldn't block the 2.2 release.
Comment 23 Manish Singh 2005-03-02 02:20:32 UTC
Fixed the mail plugin:

2005-03-01  Manish Singh  <yosh@gimp.org>

        * plug-ins/common/mail.c: use g_spawn_async_with_pipes instead of
        popen. Addresses bug #108659. Also some general cleanup.
Comment 24 Manish Singh 2005-03-02 02:34:36 UTC
I'm going to close this bug. Newer gimp-print wraps the functionality the print
code into it's ui library, so once we use the new library, this is no longer our
issue.