4

On a RHEL 6.5 Desktop, if I use:

sudo grep -r foo /*

my desktop reboots.

Q: Why?? How to debug this? It's the third time my Desktop reboots because of this :D

evachristine
  • 2,613

2 Answers2

7

There are things you're not supposed to blindly read from.

/dev/mem and /dev/kmem come to mind, but /dev/port sounds even more dangeous to read - it maps to I/O ports directly. Reading blindly from that sounds like a recipe for disaster (hard-locked my machine a few minutes ago... for science I guess). I don't think reading from that file will result in the same symptoms for all machines, but a reboot doesn't sound unreasonable.

At the very least, you should exclude /dev entirely from that, and /sys and /proc shouldn't be included either - it makes no sense to search those filesystems even if it was entirely safe.

Consider the performance as well. Do you really want to grep all of /dev/sda, then all of /dev/sda1, then whatever filesystem contents it has (assuming it's mounted)?

Mat
  • 52,586
  • 2
    Since version 2.12, GNU grep only searches in regular files (or special files passed on the command line) when invoked with -r. But RHEL6 has version 2.6.3 which indeed searches in all files including devices. – Gilles 'SO- stop being evil' Apr 24 '14 at 22:38
  • /proc/kcore would be another. And that one appears as a completely normal file. It even has a size on it. – phemmer Apr 25 '14 at 00:43
1

strace helped, the bad device was the /dev/cdrom

evachristine
  • 2,613
  • wow!! my machine is rebooting, and I need to find the source of that problem too!!! http://unix.stackexchange.com/questions/172396/how-does-auto-reboot-happens – Aquarius Power Dec 09 '14 at 21:16