Bug 8284 - "buffer size for readdir_r cannot be determined" error (using sun studio compiler)
Summary: "buffer size for readdir_r cannot be determined" error (using sun studio comp...
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: 1.4.x
Hardware: x86 (IA32) Solaris
: high major
Assignee: Simon McVittie
QA Contact: John (J5) Palmieri
URL: http://git.collabora.co.uk/?p=user/sm...
Whiteboard: 1.4
Keywords: patch
Depends on:
Reported: 2006-09-14 21:25 UTC by Anil Jangity
Modified: 2011-01-25 05:21 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:

Make _dbus_directory_get_next_file use readdir, not readdir_r (4.16 KB, patch)
2011-01-17 11:47 UTC, Simon McVittie
Details | Splinter Review

Description Anil Jangity 2006-09-14 21:25:21 UTC
gmake[1]: Entering directory `/data/Xfce-beta-src/dbus-0.93/dbus'
source='dbus-sysdeps-util-unix.c' object='dbus-sysdeps-util-unix.lo' libtool=yes \
DEPDIR=.deps depmode=none /bin/bash ../depcomp \
/bin/bash ../libtool --tag=CC --mode=compile /opt/SUNWspro/bin/cc
-DDBUS_API_SUBJECT_TO_CHANGE=1 -I/opt/Xfce-beta/include -I/usr/local/include
-I/usr/X11/include -I/usr/openwin/include -I/usr/sfw/include -I/usr/include 
-I/opt/Xfce-beta/include -I/usr/local/include -I/usr/X11/include
-I/usr/openwin/include -I/usr/sfw/include -I/usr/include -c -o
dbus-sysdeps-util-unix.lo dbus-sysdeps-util-unix.c
 /opt/SUNWspro/bin/cc -DHAVE_CONFIG_H -I. -I. -I.. -I.. -I.. -DDBUS_COMPILATION
-DDBUS_API_SUBJECT_TO_CHANGE=1 -I/opt/Xfce-beta/include -I/usr/local/include
-I/usr/X11/include -I/usr/openwin/include -I/usr/sfw/include -I/usr/include
-I/opt/Xfce-beta/include -I/usr/local/include -I/usr/X11/include
-I/usr/openwin/include -I/usr/sfw/include -I/usr/include -c
dbus-sysdeps-util-unix.c  -KPIC -DPIC -o .libs/dbus-sysdeps-util-unix.o
"dbus-sysdeps-util-unix.c", line 519: #error: "buffer size for readdir_r cannot
be determined"
cc: acomp failed for dbus-sysdeps-util-unix.c
gmake[1]: *** [dbus-sysdeps-util-unix.lo] Error 1
gmake[1]: Leaving directory `/data/Xfce-beta-src/dbus-0.93/dbus'
gmake: *** [all] Error 2
Comment 1 Havoc Pennington 2006-09-14 21:34:34 UTC
This means that neither NAME_MAX or fpathconf/dirfd/_PC_NAME_MAX are 
available, can you poke around the solaris man pages and see if they are in 
some header we just aren't including, or if there's no way to get these. Also, 
maybe check the readdir_r man page and see how they suggest choosing the size 
of the output parameter passed to it.
Comment 2 Havoc Pennington 2006-09-14 21:40:24 UTC
According to http://docs.sun.com/app/docs/doc/816-5168/6mbb3hrpf?a=view

"The caller must allocate storage pointed to by entry to be large enough for a 
dirent structure with an array of char d_name member containing at least 
NAME_MAX (that is, pathconf(directory, _PC_NAME_MAX)) plus one elements. 
(_PC_NAME_MAX is defined in <unistd.h>.)"

Is this for a newer version of solaris than you have maybe? Or maybe the 
configure checks did not succeed or fpathconf/dirfd are missing?

Comment 3 Havoc Pennington 2006-09-14 21:45:41 UTC
Can you try adding -D_POSIX_C_SOURCE=199506L to your cflags?
Comment 4 Anil Jangity 2006-09-14 21:57:04 UTC
I have fpathconf but no dirfd. This is pretty much the latest version of Solaris 10.

Here are separate compiles with the different flags you suggested:

build@sr1-sjc-01:~/Xfce-beta-src/dbus-0.93/dbus% /opt/SUNWspro/bin/cc
-I/opt/Xfce-beta/include -I/usr/local/include -I/usr/X11/include
-I/usr/openwin/include -I/usr/sfw/include -I/usr/include
-I/opt/Xfce-beta/include -I/usr/local/include -I/usr/X11/include
-I/usr/openwin/include -I/usr/sfw/include -I/usr/include -c
dbus-sysdeps-util-unix.c  -KPIC -DPIC -o .libs/dbus-sysdeps-util-unix.o
"dbus-sysdeps-util-unix.c", line 520: #error: "buffer size for readdir_r cannot
be determined"
cc: acomp failed for dbus-sysdeps-util-unix.c

build@sr1-sjc-01:~/Xfce-beta-src/dbus-0.93/dbus% /opt/SUNWspro/bin/cc
-DHAVE_CONFIG_H -I. -I. -I.. -I.. -I.. -D_POSIX_C_SOURCE=199506L
-I/usr/local/include -I/usr/X11/include -I/usr/openwin/include
-I/usr/sfw/include -I/usr/include -I/opt/Xfce-beta/include -I/usr/local/include
-I/usr/X11/include -I/usr/openwin/include -I/usr/sfw/include -I/usr/include -c
dbus-sysdeps-util-unix.c  -KPIC -DPIC -o .libs/dbus-sysdeps-util-unix.o
"/usr/include/sys/resource.h", line 146: incomplete struct/union/enum timeval:
"dbus-sysdeps-util-unix.c", line 261: warning: implicit function declaration:
"dbus-sysdeps-util-unix.c", line 520: #error: "buffer size for readdir_r cannot
be determined"
cc: acomp failed for dbus-sysdeps-util-unix.c

Comment 5 Havoc Pennington 2006-09-14 22:08:03 UTC
mentions that on solaris we might have to do open() and then fdopendir().
an "updated version" of that mail at 
has a little more detail.

I'm not sure honestly this is all worth it, since readdir() is only *allowed* 
by the spec to have thread problems, and on both Solaris and Linux I'm pretty 
sure it does not. So we don't know what systems it would have problems on - 
maybe only some crap old unix nobody cares about. Also, I don't think we 
(currently) use readdir in libdbus, only in the bus daemon, which is not 

but anyway... I guess we don't have to give up yet, as we could instead of 
having the buf_size function, we could have an open_dir_with_size() function 
that does the open/fdopendir trick if we don't have dirfd
Comment 6 John (J5) Palmieri 2006-10-11 10:35:11 UTC
I've seen this compile fine under Solaris at teh Boston Summit last weekend.  Is
this still an issue with CVS D-Bus?
Comment 7 Benjamin Close 2008-01-11 02:36:47 UTC
Bugzilla Upgrade Mass Bug Change

NEEDSINFO state was removed in Bugzilla 3.x, reopening any bugs previously listed as NEEDSINFO.

  - benjsc
    fd.o Wrangler
Comment 8 Simon McVittie 2011-01-07 08:45:57 UTC
(In reply to comment #5)
> Also, I don't think we 
> (currently) use readdir in libdbus, only in the bus daemon, which is not 
> threaded.

Well spotted: it's only in dbus-sysdeps-util-*, dbus-auth-util and dbus-message-util.

It wasn't at all obvious to me that the -util suffix means "not part of libdbus"; we could probably do with some restructuring there.

Anyway, changing _dbus_directory_get_next_file to use plain readdir(), and flagging it as explicitly not threadsafe, would make it much much easier to fix Bug #15922 as well as this one.
Comment 9 Simon McVittie 2011-01-17 11:45:53 UTC
Here's a patch to just use readdir().
Comment 10 Simon McVittie 2011-01-17 11:47:50 UTC
Created attachment 42126 [details] [review]
Make _dbus_directory_get_next_file use readdir, not readdir_r

This isn't thread-safe or reentrant, but it turns out we don't need
either of those properties, and readdir_r is a real pain to use correctly,
particularly in the presence of FUSE filesystems that might implement
statfs() wrong.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=8284
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=15922
Comment 11 Simon McVittie 2011-01-24 08:25:02 UTC
I think this is worth fixing for 1.4 because of Bug #15922.
Comment 12 Will Thompson 2011-01-24 09:24:01 UTC
Review of attachment 42126 [details] [review]:

This looks fine!
Comment 13 Simon McVittie 2011-01-25 05:21:37 UTC
Thanks, fixed in git for 1.4.4, 1.5.0.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.