Fails to read from stdin if the process producing data is slow to start

Bug #230649 reported by James Westby
6
Affects Status Importance Assigned to Milestone
pastebinit
Fix Released
Medium
Unassigned

Bug Description

Hi,

pastebinit doesn't work when trying to read from stdin and
the process producing the data is slow to start, e.g.

  (sleep 2; echo a) | pastebinit

tells you that you need to provide arguments.

This could be fixed by checking the arguments first. If there is
no filename provided then read from stdin, and so wait for it.

This would also allow you to just run pastebinit and type.

As it accepts filenames without -i now there should be no confusion
caused by it "hanging" when you expect it read a file as happens
with "patch patch_filename".

Thanks for the tool though, it is very useful.

Thanks,

James

Revision history for this message
Stéphane Graber (stgraber) wrote : Re: [Bug 230649] [NEW] Fails to read from stdin if the process producing data is slow to start

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

James Westby wrote:
> Public bug reported:
>
> Hi,
>
> pastebinit doesn't work when trying to read from stdin and
> the process producing the data is slow to start, e.g.
>
> (sleep 2; echo a) | pastebinit
>
> tells you that you need to provide arguments.
>
> This could be fixed by checking the arguments first. If there is
> no filename provided then read from stdin, and so wait for it.
>
> This would also allow you to just run pastebinit and type.
>
> As it accepts filenames without -i now there should be no confusion
> caused by it "hanging" when you expect it read a file as happens
> with "patch patch_filename".
>
> Thanks for the tool though, it is very useful.
>
> Thanks,
>
> James
>
> ** Affects: pastebinit
> Importance: Undecided
> Status: New
>
Hi,
Thanks for reporting this bug, I'm not really sure of why sending data
trough the pipe doesn't work in your case.

I gave it a quick try and successfully reproduced the bug although I
have no idea of what's going wrong ...

Stéphane

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFILDN1jxyfqkjBhuwRAgl3AJ4u8aL5YWy1a9Eyd8djcvGdtoB4HwCfURA8
gWPQ1MhM35xJ6wQHlYxXvTQ=
=Z6nQ
-----END PGP SIGNATURE-----

Revision history for this message
Chris Jones (cmsj) wrote : Re: [Bug 230649] [NEW] Fails to read from stdin if the process producing data is slow to start

Hi

Stéphane Graber wrote:
> I gave it a quick try and successfully reproduced the bug although I
> have no idea of what's going wrong ...

         l_r = select.select([sys.stdin],[],[],0)

AIUI, that specifies the timeout is 0 seconds (ie it's entirely
non-blocking), so if the input isn't ready at the point that call is
made, it fails.

I think James' suggestion about checking options first makes sense. If
there is no filename, assuming stdin is wanted and doing blocking IO on it.

Cheers,
--
Chris Jones
   <email address hidden>
    www.canonical.com

Revision history for this message
James Westby (james-w) wrote :

On Thu, 2008-05-15 at 12:58 +0000, Stéphane Graber wrote:
> Hi,
> Thanks for reporting this bug, I'm not really sure of why sending data
> trough the pipe doesn't work in your case.
>
> I gave it a quick try and successfully reproduced the bug although I
> have no idea of what's going wrong ...

Early on in the code there is

        #Check if some datas were passed by pipe, if yes directly assign
content
        l_r = select.select([sys.stdin],[],[],0)
        try:
                content=l_r[0][0].read()
                filename="-"
        except:
                filename=""

        # Check number of arguments
        if len(sys.argv) == 1 and filename == "":
                print _("Error no arguments specified!\n")
                Usage()
                sys.exit(1)

The select call has a timeout of 0, so if stdin is not immediately
ready to provide data it returns an empty lists. There is then a list
index out of range error, which is caught by the "except", and so
it is marked as not receiving data on stdin.

As I said, removing this check and just assuming that if there is no
filename given stdin should be used would fix it, and I think not
cause any problems for other uses, do you think that would be
appropriate?

Thanks,

James

Revision history for this message
Stéphane Graber (stgraber) wrote :

I have pushed rev 44 of pastebinit with the check removed and reading stdin when no filename is specified.
I will still need to do some minor changes (probably updating the manpage).

You can get it from our bzr branch on LP, testing is welcome.

Stéphane

Changed in pastebinit:
importance: Undecided → Medium
status: New → Fix Committed
Revision history for this message
Alexander Sack (asac) wrote :

not really sure if this is fixed.

I am running rev 46 from fta archive:

ii pastebinit 0.11~bzr46-1~fta1 command-line pastebin client

I am doing:

(Works)
$ pastebinit -i /tmp/out
http://paste.ubuntu.com/46408/

(Doenst Work)
asac@hector:/tmp$ cat /tmp/out | pastebinit
Error no arguments specified!

pastebinit v0.10
Required arguments:
 -i <filename> (or pipe the text)
Optional arguments:
 -b <pastebin url:default is 'http://paste.ubuntu.com'>
 -a <author:default is 'asac'>
 -f <format of paste:default is 'text'>
 -r <parent posts ID:defaults to none>
Optional arguments supported only by 1t2.us and paste.stgraber.org:
 -j <jabberid for notifications:default is 'nah'>
 -m <permatag for all versions of a post:default is blank>
 -t <title of paste:default is blank>
 -u <username> -p <password>

Revision history for this message
Stéphane Graber (stgraber) wrote :

Just try:
  cat /tmp/out | pastebinit -

That should work, the manpage and usages should be updated before we release a new version of pastebinit though.

Changed in pastebinit:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.