3

I am currently developing inside an embedded Linux environment (kernel 3.10.0), and while goofing around in the procfs mount of the system I found that all processes present the following file in their /proc/[pid] folder:

-rw-r--r--   1 root    root      0 Feb   22 09:10 make-it-fail

Just for testing, I launched from the shell sleep 360 & and tried to read/write with cat and echo the make-if-fail file. These are the results:

# stat /proc/[sleep_pid]/make-it-fail
    File: /proc/[sleep_pid]/make-it-fail
    Size: 0    Blocks: 0    IO Block: 1024   regular empty file
    [...]
# cat /proc/[sleep_pid]/make-it-fail
0
# echo "1" > /proc/[sleep_pid]/make-it-fail
# cat /proc/[sleep_pid]/make-it-fail
1
# stat /proc/[sleep_pid]/make-it-fail
    File: /proc/[sleep_pid]/make-it-fail
    Size: 0    Blocks: 0    IO Block: 1024   regular empty file
    [...]

Odd things:

  1. Although stat claims that the file has size 0, I could read and write something there, and retrieve what I wrote.
  2. The process is alive and kicking, "surviving" the reads and writes of this file. I actually expected it to ... well, fail or exit.

I understand that procfs is a pseudo-filesystem (therefore stat results might be not "real"/misleading) and that it interfaces with kernel structures, but I feel I am missing something here right now.

So, what is the purpose and usage of this file? I cannot recall seeing it in other distros (e.g. it is not in the Ubuntu that I use for development)

3
  • 3
    I found this link. kernel.org/doc/Documentation/fault-injection/…; as for the file, it is there because the kernel has debug mode enabled. proc is a virtual interface for kernel vars, those file inconsistencies are taken for granted. – Rui F Ribeiro Feb 22 '16 at 8:52
  • @RuiFRibeiro thanks! That is it! If you'd elaborate it more in an answer I'd accept it. – dave_alcarin Feb 22 '16 at 10:10
  • I investigated a little more and posted an answer. – Rui F Ribeiro Feb 22 '16 at 12:31
4

I was investigating a little your questions, as I was becoming suspicious from reading this Injecting faults into the kernel that make-it-fail was a flag.

Actually it is confirmed reading Injecting faults into the kernel:

So there are a number of options which can be used to focus the faults on a particular part of the kernel.
These include: task-filter: if this variable is set to a positive value, faults will only be injected when a specially-marked processes are running. To enable this marking, each process has a new flag (make-it-fail) in its /proc directory; setting that value to one will cause faults to be injected into that process.

At the end of the day, make-it-fail is a boolean flag that marks whether a conditional injection operation to several processes will be done in the related PID. So just changing it's value to 1 as you have done will have no consequences.

As for the variables/filenames themselves, the article also point outs the kernel has to be compiled with fault injection capability turned on; hence you not seeing them in other Linux machines normally.

As for proc having the file system inconsistencies, proc is a virtual file system mapping file names to internal linux structures/variables; and it is natural a file having as size 0 bytes.

From the TLDP Linux Filesystem Hierarchy: /proc

The most distinctive thing about files in this directory is the fact that all of them have a file size of 0, with the exception of kcore, mtrr and self.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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