These sound like good questions to ask on StackOverflow.

Rick

On Thu, Apr 12, 2018 at 2:37 AM, Erich Steinböck <erich.steinbo...@gmail.com
> wrote:

> checking the code in as it is is also an option...it gets more eyeballs on
>> the problem
>>
> I checked in the code for a Unix redirecting command handler.
> It's still work-in-progress, not only because of some minor issues (e. g.
> Ctrl+C handling), but because some severe restrictions, that I know no
> solutions for.
>
> 1) in a scenario, where we feed redirected input to a command that really
> doesn't consume it (e. g. echo), the command may finish before we can
> pipe all stdin input.  The spawned child exits, closing its stdin pipe read
> end.  On my test system, Ubuntu 16.04, the following write() operation
> then, instead of failing with an errno indication, will exit the program.
> No message, no segmentation fault, no indication at all.
> I'm trying circumventing this issue by not closing the parent stdin pipe
> read end (which normally isn't used at all and is suggested to be closed in
> most sample code).  This fixes the "exit" issue, but now, when the child
> finishes, further writes to the pipe don't give an error indication (as it
> is still valid because the parent read end is open) which leads to an
> endless loop.  This might be fixed if the handler checked whether the
> commandchild was still alive upon each loop (adding another complication
> that I wouldn't expect to be necessary)
>
> 2) when piping more than 64K (the default pipe size on Linux) to cat by
> redirecting stdin and stdout cat typically issues an error an output will
> miss lines.  I've left debug trace statements in the handler to show the
> issue.
>
> Feeding 660 lines with 100 characters each (plus a newline)
> the handler sees the correct 66660 total bytes, writes them in 4K blocks
> (the size of PIP_BUF which ensures we have atomic writes)
> at 64K the pipe is full, tha handler sees an EAGAIN error, tries to read
> from stdout (nothing there yet), waits a little and loops.
> loops #2 and #3 see the full stdin pipe, and an empty stdout pipe, but now
> cat complains: "cat: -: Resource temporarily unavailable"
> in loop #4 the handler is able to write the remaining bytes to stdin, and
> also stdout can be read now, but not all expected output lines are there
>
> With less than 64K input to stdin, things seem to work fine.
>
> ~~~
> $ ./rexx -e "a = .Array~new; address io 'cat' with input using
> (.Array~new(arg(1))~fill('-'~copies(100))) output stem o.; say o.0 o.1"
> 660
> io args /bin/sh -c cat
> io redirection requested
> io input redirection requested
> io output redirection requested
> io spawned command
> io input feed total buffer 66660 bytes
> io loop #1, input:1 output:1 error:0
> io input feed write offset 0, length 4096, written 4096 bytes
> io input feed write offset 4096, length 4096, written 4096 bytes
> io input feed write offset 8192, length 4096, written 4096 bytes
> io input feed write offset 12288, length 4096, written 4096 bytes
> io input feed write offset 16384, length 4096, written 4096 bytes
> io input feed write offset 20480, length 4096, written 4096 bytes
> io input feed write offset 24576, length 4096, written 4096 bytes
> io input feed write offset 28672, length 4096, written 4096 bytes
> io input feed write offset 32768, length 4096, written 4096 bytes
> io input feed write offset 36864, length 4096, written 4096 bytes
> io input feed write offset 40960, length 4096, written 4096 bytes
> io input feed write offset 45056, length 4096, written 4096 bytes
> io input feed write offset 49152, length 4096, written 4096 bytes
> io input feed write offset 53248, length 4096, written 4096 bytes
> io input feed write offset 57344, length 4096, written 4096 bytes
> io input feed write offset 61440, length 4096, written 4096 bytes
> io input feed write offset 65536, length 1124, written -1 bytes
> io input feed write failure Resource temporarily unavailable
> io output buffer -1 bytes read
> io output retry: Resource temporarily unavailable
> io loop wait 250 usec done
> io loop #2, input:1 output:1 error:0
> io input feed write offset 65536, length 1124, written -1 bytes
> io input feed write failure Resource temporarily unavailable
> io output buffer -1 bytes read
> io output retry: Resource temporarily unavailable
> io loop wait 250 usec done
> io loop #3, input:1 output:1 error:0
> io input feed write offset 65536, length 1124, written -1 bytes
> io input feed write failure Resource temporarily unavailable
> io output buffer -1 bytes read
> io output retry: Resource temporarily unavailable
> cat: -: Resource temporarily unavailable
> io loop wait 250 usec done
> io loop #4, input:1 output:1 error:0
> io input feed write offset 65536, length 1124, written 1124 bytes
> io input feed closed
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 4096 bytes read
> io output buffer 0 bytes read
> io output feed closed
> io waitpid(12788) = 12788
> io child ended with rc 1
> io returning
> 649 ------------------------------------------------------------
> ----------------------------------------
> ~~~
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Oorexx-devel mailing list
> Oorexx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to