Re: [SLUG] making fgets fail during testing

2013-09-22 Thread Amos Shapira
"use strace and friends"

I though I'd mention that "friends" should include the lesser known
"ltrace" (http://linux.die.net/man/1/ltrace), which should allow you to
find which user-space function is called, not just system calls.



On 21 September 2013 23:07, Glen Turner  wrote:

> The usual technique is to interpose your own library call above the usual
> call. See LD_PRELOAD and dlsym(). For an interpreted language like PHP use
> strace and friends to see which library calls the PHP fgets() uses (it need
> not be fgets(), it could be read()).
> --
> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
>



-- 
 [image: View my profile on LinkedIn]

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] making fgets fail during testing

2013-09-21 Thread Glen Turner
The usual technique is to interpose your own library call above the usual call. 
See LD_PRELOAD and dlsym(). For an interpreted language like PHP use strace and 
friends to see which library calls the PHP fgets() uses (it need not be 
fgets(), it could be read()).
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] making fgets fail during testing

2013-09-12 Thread Menno Schaaf
> - power off you hard drive in process to get real read failure (EIO), if
> you have nothing to loose on your hdd :)
>
>
Putting the file on an (old) flash drive and pull it midway might be a bit
easier (and safer). Could also try and read a file off a failed drive if
you still have one lying around, always some interesting results doing that.


Menno
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] making fgets fail during testing

2013-09-12 Thread Maxim Zakharov
Morning,

On Fri, Sep 13, 2013 at 8:33 AM, Ashley Maher <
ashley.ma...@didymodesigns.com.au> wrote:

>
> What can I put in a test text file to get fgets to fail?
>
> Can hand indicate the condition fail but would like to trigger a "real"
> read failure well into the file. A lot of references about testing for
> failure but nothing how to trigger fgets to fail.
>
>
What sort of failure do you expect?
You may
- seek the pointer at the end of file just before fgets to get eof error
- lock part of the file exclusively from another process to get EAGAIN, if
mandatory file locking is supported and file was opened with non-blocking
flag.
- open a pipe instead of regular file and kill other end in process.
- send a signal to the process while it's waiting for read (pipe of socket)
to get EINTR.
- power off you hard drive in process to get real read failure (EIO), if
you have nothing to loose on your hdd :)


http://www.dataparksearch.org/  Twitter: @Maxime2
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] making fgets fail during testing

2013-09-12 Thread Rick Welykochy

Hi Ashley,

One thing you could try is putting non-ASCII characters in the
file, i.e. above 0x7f.

I haven't played with PHP, but in python, if you are using
ASCII encoding for text strings and try to load a non-ASCII
character into a string, an exception is raised.

Better still, tell PHP you are using UTF-8 encoding for
Unicode characters and then stuff in some badly formed
UTF-8 characters. Some random bytes ought to do it, as UTF-8
is fairly strict.

Let us know how you go. Text encoding and decoding has always
been a PITA.

cheers
rickw



Ashley Maher wrote:

Morning,

Posting here as the coders list is now dead.

Using php in a web app.

Reading in a large text file.

Using fgets to read line by line for processing.

What can I put in a test text file to get fgets to fail?

Can hand indicate the condition fail but would like to trigger a "real" read 
failure well into the file. A lot of references about testing for failure but nothing how 
to trigger fgets to fail.

Thanks for any hints.

Regards,

Ashley




--

Rick Welykochy || Vitendo Consulting

The chief source of problems is solutions.
  -- Eric Sevareid

--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html