Linux – Meaning and usage of /proc/[pid]/make-if-fail

embeddedlinuxproc

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)

Best Answer

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.

Related Question