Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to test the error handling in some software, in particular what happens when an error occurs reading from a file or pipe. Is there a simple way to send a certain amount of data to stdout and then generate an I/O error? (I.e., the process doing the reading would see read(2) return -1.) A simple shell recipe would be great, but I don't mind writing code if that's the only way.

share|improve this question

1 Answer

So you want to do fault injection on file accesses. Two techniques come to mind: using LD_PRELOAD to overload the read function in the library to return an error instead of doing its job in certain conditions; or accessing files on a FUSE that mirrors an existing filesystem, but artificially fails in certain conditions.

Looking for fault injection software, I found these two tools. I've never used either.

Libfiu (fault injection in userspace) is a tool to simulate failure of calls to the POSIX API. It works by preloading a library that overloads the POSIX API calls. You can write simple directives or arbitrary C code to override the normal behavior.

Petardfs is a FUSE filesystem that can report errors on demand. You can tell it to report errors for a given operation on a given file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.