You are not logged in.

#1 2012-02-20 14:50:39

palintropos
Member
Registered: 2012-02-09
Posts: 9

[SOLVED] Did something break 'find'?

I don't use the find command a whole lot, so (a.) I could just be missing something, and (b.) I have no idea exactly when this started. However, the find command seems to be totally broken on my system even after a reboot. Even simple things like 'find' or 'find . -print' in my home or / directory produce no output. I keep my system pretty well exactly up to date (last -Syu was just last night), and I don't use testing. TIA.

EDIT: Thought it might be relevant what version I'm using. findutils 4.4.2-4

Last edited by palintropos (2012-02-20 17:18:37)

Offline

#2 2012-02-20 15:07:41

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Did something break 'find'?

strace will tell you what's happening. Even 'find' without args in an empty directory should read the $PWD and output a single '.'

Offline

#3 2012-02-20 15:49:06

palintropos
Member
Registered: 2012-02-09
Posts: 9

Re: [SOLVED] Did something break 'find'?

'strace find' produces a boatload of output, but I don't really understand any of it. What should I be looking for?

EDIT: I decided to come back and include some sample output in case anyone else curious and wanting to help decides to come along.

In the following examples, the commands indicated were performed on a small directory in my home folder housing 3 .iso files I've downloaded.

ls:

archlinux-2011.08.19-netinstall-i686.iso  systemrescuecd-x86-2.4.1.iso
pmagic_2011_12_30.iso

find: no output

strace find:

execve("/usr/bin/find", ["find"], [/* 45 vars */]) = 0
brk(0)                                  = 0x8a6b000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7774000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=95344, ...}) = 0
mmap2(NULL, 95344, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb775c000
close(3)                                = 0
open("/lib/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\320\30\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=30696, ...}) = 0
mmap2(NULL, 33356, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7753000
mmap2(0xb775a000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6) = 0xb775a000
close(3)                                = 0
open("/lib/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000D\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=173588, ...}) = 0
mmap2(NULL, 176256, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7727000
mmap2(0xb7751000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x29) = 0xb7751000
close(3)                                = 0
open("/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\340\225\1\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1949865, ...}) = 0
mmap2(NULL, 1706628, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7586000
mmap2(0xb7721000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19b) = 0xb7721000
mmap2(0xb7724000, 10884, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7724000
close(3)                                = 0
open("/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\320Z\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=130607, ...}) = 0
mmap2(NULL, 107004, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb756b000
mmap2(0xb7582000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16) = 0xb7582000
mmap2(0xb7584000, 4604, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7584000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb756a000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7569000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb75696c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
mprotect(0xb7721000, 8192, PROT_READ)   = 0
mprotect(0xb7582000, 4096, PROT_READ)   = 0
mprotect(0xb7751000, 4096, PROT_READ)   = 0
mprotect(0xb775a000, 4096, PROT_READ)   = 0
mprotect(0x806e000, 4096, PROT_READ)    = 0
mprotect(0xb7796000, 4096, PROT_READ)   = 0
munmap(0xb775c000, 95344)               = 0
set_tid_address(0xb7569728)             = 3900
set_robust_list(0xb7569730, 0xc)        = 0
rt_sigaction(SIGRTMIN, {0xb7570560, [], SA_SIGINFO}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0xb75705e0, [], SA_RESTART|SA_SIGINFO}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0
uname({sys="Linux", node="gozer", ...}) = 0
uname({sys="Linux", node="gozer", ...}) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
gettimeofday({1329756546, 612989}, NULL) = 0
brk(0)                                  = 0x8a6b000
brk(0x8a8c000)                          = 0x8a8c000
ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
open(".", O_RDONLY|O_LARGEFILE)         = 3
fchdir(3)                               = 0
fstatat64(AT_FDCWD, ".", {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0
open(".", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW) = 4
fchdir(4)                               = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7773000
write(1, ".\n", 2)                      = 2
openat(AT_FDCWD, ".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 5
fchdir(5)                               = 0
getdents64(5, /* 5 entries */, 32768)   = 208
getdents64(5, /* 0 entries */, 32768)   = 0
close(5)                                = 0
write(1, "./systemrescuecd-x86-2.4.1.iso\n", 31) = 31
write(1, "./pmagic_2011_12_30.iso\n", 24) = 24
write(1, "./archlinux-2011.08.19-netinstal"..., 43) = 43
fchdir(4)                               = 0
fchdir(4)                               = 0
close(4)                                = 0
close(1)                                = 0
munmap(0xb7773000, 4096)                = 0
close(2)                                = 0
exit_group(0)                           = ?

Last edited by palintropos (2012-02-20 16:51:54)

Offline

#4 2012-02-20 16:59:12

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Did something break 'find'?

write(1, ".\n", 2)                      = 2
openat(AT_FDCWD, ".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 5
fchdir(5)                               = 0
getdents64(5, /* 5 entries */, 32768)   = 208
getdents64(5, /* 0 entries */, 32768)   = 0
close(5)                                = 0
write(1, "./systemrescuecd-x86-2.4.1.iso\n", 31) = 31
write(1, "./pmagic_2011_12_30.iso\n", 24) = 24
write(1, "./archlinux-2011.08.19-netinstal"..., 43) = 43

Clearly, there is output. Those write syscalls are sending data to stdout.

What happens when you run /usr/bin/find? Alternatively, what's the output of 'type -a find'?

Offline

#5 2012-02-20 17:17:27

palintropos
Member
Registered: 2012-02-09
Posts: 9

Re: [SOLVED] Did something break 'find'?

Wow, weird. /usr/bin/find works as expected. The output of 'type -a find' is:

find is a function
find () 
{ 
    find $* 2> /dev/null
}
find is /usr/bin/find

This effectively solves my problem (as I can simply call /usr/bin/find instead of just 'find'), but do you have any idea what's causing it? '/usr/bin' is in my $PATH.

Offline

#6 2012-02-20 17:53:52

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Did something break 'find'?

You're never calling the binary -- you're calling the function. the function find calls find, which calls find, which calls find, which calls find....... you've created an infinite loop.

If you desperately want to wrap find to avoid all error output, use this:

find() {
  command find "$@" 2>/dev/null
}

This is force a path lookup from within the function and will properly preserve arguments passed to the command.

Offline

#7 2012-02-21 00:46:00

palintropos
Member
Registered: 2012-02-09
Posts: 9

Re: [SOLVED] Did something break 'find'?

Cool. Well-troubleshooted! (Troubleshot?) Do you have any idea where I might have defined that? I vaguely remember doing that a while ago (one of the very first times I used the find command and got irritated by the permission-denied output when searching in root's space, maybe when I was first putting together a .bashrc), but I have no idea where I might have picked up the tip or how it's implemented. Thanks again for all your great diagnostic help so far.

Offline

#8 2012-02-21 01:04:45

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Did something break 'find'?

.bashrc seems like a likely candidate...

Offline

Board footer

Powered by FluxBB