diff options
author | Jan Schmidt <thaytan@noraisin.net> | 2009-10-08 15:21:48 +0100 |
---|---|---|
committer | Jan Schmidt <thaytan@noraisin.net> | 2009-10-08 15:21:48 +0100 |
commit | 63934021ab096ba3978caa1169caf24216d292ee (patch) | |
tree | 98abec3e09bf322fdcbe6402f6434b3e80565e86 /gst/gstpluginloader.c | |
parent | aeb3f1f1ff2ff315ce073fa045d8f899495327ab (diff) |
pluginloader: Move stdin and stdout out of harm's way
In the plugin loader subprocess, move stdin and stdout to new fd's
so that plugins printing things during plugin init or (*gasp*)
possibly reading from stdin don't interfere with the data sent to
and from the parent.
Diffstat (limited to 'gst/gstpluginloader.c')
-rw-r--r-- | gst/gstpluginloader.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/gst/gstpluginloader.c b/gst/gstpluginloader.c index 56c55b452..842ea012e 100644 --- a/gst/gstpluginloader.c +++ b/gst/gstpluginloader.c @@ -426,15 +426,42 @@ gboolean _gst_plugin_loader_client_run () { GstPluginLoader *l; + int dup_fd; l = plugin_loader_new (NULL); if (l == NULL) return FALSE; - l->fd_w.fd = 1; /* STDOUT */ - gst_poll_add_fd (l->fdset, &l->fd_w); + /* On entry, the inward pipe is STDIN, and outward is STDOUT. + * Dup those somewhere better so that plugins printing things + * won't interfere with anything */ +#ifndef G_OS_WIN32 + dup_fd = dup (0); /* STDIN */ + if (dup_fd == -1) { + GST_ERROR ("Failed to start. Could no dup STDIN, errno %d", errno); + return FALSE; + } + l->fd_r.fd = dup_fd; + close (0); + dup_fd = dup (1); /* STDOUT */ + if (dup_fd == -1) { + GST_ERROR ("Failed to start. Could no dup STDOUT, errno %d", errno); + return FALSE; + } + l->fd_w.fd = dup_fd; + close (1); + + /* Dup stderr down to stdout so things that plugins print are visible, + * but don't care if it fails */ + dup2 (2, 1); +#else + /* FIXME: Use DuplicateHandle and friends on win32 */ + l->fd_w.fd = 1; /* STDOUT */ l->fd_r.fd = 0; /* STDIN */ +#endif + + gst_poll_add_fd (l->fdset, &l->fd_w); gst_poll_add_fd (l->fdset, &l->fd_r); gst_poll_fd_ctl_read (l->fdset, &l->fd_r, TRUE); |