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 668210 - Add g_application_command_line_get_stdin()
Add g_application_command_line_get_stdin()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gapplication
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-01-18 19:39 UTC by Allison Karlitskaya (desrt)
Modified: 2012-12-27 16:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add g_application_command_line_get_stdin() (8.99 KB, patch)
2012-01-18 19:39 UTC, Allison Karlitskaya (desrt)
reviewed Details | Review
rebased patch (8.63 KB, patch)
2012-11-28 19:33 UTC, Paolo Borelli
committed Details | Review

Description Allison Karlitskaya (desrt) 2012-01-18 19:39:00 UTC
gedit wants this, and it's not nearly insane as the general-purpose fd
passing case (plus, it may be possible to do it in a portable way).
Comment 1 Allison Karlitskaya (desrt) 2012-01-18 19:39:02 UTC
Created attachment 205577 [details] [review]
Add g_application_command_line_get_stdin()

This returns a GInputStream corresponding to the stdin on the
commandline that caused this invocation.
Comment 2 Matthias Clasen 2012-01-19 04:14:30 UTC
Review of attachment 205577 [details] [review]:

Where is the test ?

When we commit this, it should probably be mentioned here: https://live.gnome.org/GTK+/GApplication-dbus-apis

::: gio/gapplicationcommandline.c
@@ +540,3 @@
+ * @cmdline: a #GApplicationCommandLine
+ *
+ * Gets the stdin of the invoking process.

It would be really good to mention why this might be useful.

::: gio/gapplicationimpl-dbus.c
@@ +556,3 @@
+    GError *error = NULL;
+
+    /* send along the stdin incase

'in case', two words, no ?
Comment 3 Sebastian Dröge (slomo) 2012-04-16 10:08:23 UTC
Calling it stdin is very Unix specific I guess, maybe another name? Also see bug #621187
Comment 4 Ignacio Casal Quinteiro (nacho) 2012-07-31 15:20:46 UTC
Seems to work here for gedit.
Comment 5 Ignacio Casal Quinteiro (nacho) 2012-07-31 16:00:25 UTC
Actually it does not properly work. We need the input stream to not be null if it has some data or we need a way to know that it has some data.

something like:
if (!isatty (STDIN_FILENO))
      {
        struct stat sbuffer;

        if (fstat (STDIN_FILENO, &sbuffer) == 0 &&
            (S_ISREG (sbuffer.st_mode) || S_ISFIFO (sbuffer.st_mode) || S_ISLNK (sbuffer.st_mode)))
          {
            fd_list = g_unix_fd_list_new ();
            g_unix_fd_list_append (fd_list, 0, &error);
          }
      }
Comment 6 Allison Karlitskaya (desrt) 2012-08-01 08:11:42 UTC
This feature is insane....

echo foo | gedit

I would have expected that I need at least to do

echo foo | gedit -

I can imagine cases where gedit has stdin that is not a terminal and that it should not expect to read from it....
Comment 7 Paolo Borelli 2012-08-01 21:10:30 UTC
If "gedit -" makes thinks easier, I am all for it (as a matter of fact, that's how I would have liked it to be in the first place)... the current syntax is what we inherited since gedit 0.X days

That in turns means that we will need to move some the insanity in special casing the a file named "-", but I guess we can survive :-)
Comment 8 Sébastien Wilmet 2012-08-03 20:56:43 UTC
What about a more general solution to handle any file descriptors, not only stdin?
It could be useful for a process to pass its stdout/stderr or any other file descriptor for more complex uses.

Also, I think it's better to not associate file descriptors with GApplicationCommandLine. The fact that stdin, stdout and stderr can be _redirected_ from the command line should not be seen as _being part_ of the command line. And what about other file descriptors that are created by the process?

So an idea would be to implement another GAction, named for example GUnixFDAction.

As a side note, I thought G_VARIANT_TYPE_HANDLE could be used in a GSimpleAction to automagically pass file descriptors over D-Bus. But it's not the case, G_VARIANT_TYPE_HANDLE represents an index of an fd, not the fd itself.
Comment 9 Sébastien Wilmet 2012-08-04 02:01:26 UTC
Hum, forget my previous post :) I was a bit lost with all the interactions of the interfaces and classes involved with GApplication.
Comment 10 Paolo Borelli 2012-11-28 19:33:03 UTC
Created attachment 230117 [details] [review]
rebased patch

I rebased desrt's patch since it didn't apply anymore and also addressed the two comments by Matthias (not the unit test though).

However testing this with gedit does not seem to work: it works for the first instance but not the following ones
Comment 11 Paolo Borelli 2012-11-28 19:49:00 UTC
FYI the testing code in gedit is available on the wip/gtkapp branch

http://git.gnome.org/browse/gedit/commit/?h=wip/gtkapp&id=068560016d0370c5136d9ca2898aaf547d3d5a34

(you need to uncomment the actual line calling this function obviously)
Comment 12 Paolo Borelli 2012-12-08 16:17:40 UTC
Actually after talking with desrt on irc and tested again and it works great. I guess I was doing something silly like running the second instance out of the jhbuild shell...