1

If I was to debug a service on a machine and I determined that a write was failing, how could I check why the write failed?

I know the system call in C will return -1 and then we can check what constant int errno contains (EINVAL,etc.). However, if I'm not able to check this how would I go about checking the cause of the error? Would dmesg show an error at the block device level for me in this case?

1

1 Answer 1

1

If the write failure was related to a disk I/O error, and so to a failing disk, then you would very likely find error messages from the kernel in the dmesg output.

But if there are no such symptoms, you should exclude the simplest explanations first:

  • Is the process authorized to perform the write operation it's attempting? In other words, does it have write permission to the thing it's attempting to write? If SELinux is in use, also check the audit log in the /var/log/audit/ directory.
  • Is the filesystem full?
  • Is the filesystem out of free inodes (applicable only to filesystems with no dynamic inode creation, such as the ext2/ext3/ext4 family)?
3
  • That's perfect, thanks very much - one extra question - how could you check a process's read write permissions? I know a process has a file mode creation mask that can be set with umask, but in the case of an existing file would I just locate the file being written to, look at its permissions and then look at the processes euid or gid and compare them? Commented Nov 20, 2017 at 20:53
  • Exactly like that. Commented Nov 20, 2017 at 20:57
  • Its depends if file is local mounted or remote mount. for remote check it is mounted , permission is right etc> local filesystem check ``` 1.disk full df-h 2.inode df -i 3.permissin error 4.any filesytem error 5.mount option if its only readonly. 6.wrong fd 7.wrong permission ``` Commented Dec 7, 2020 at 10:34

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.