Bug 40235

Summary: Undefined CMSG_SPACE and CMSG_LEN on Solaris 9
Product: dbus Reporter: Dagobert Michelsen <dam>
Component: coreAssignee: Simon McVittie <smcv>
Status: RESOLVED FIXED QA Contact: John (J5) Palmieri <johnp>
Severity: normal    
Priority: medium CC: hp, smcv
Version: 1.4.xKeywords: patch
Hardware: SPARC   
OS: Solaris   
URL: http://cgit.freedesktop.org/~smcv/dbus/commit/?h=14-solaris-40235
Whiteboard: review+
i915 platform: i915 features:
Bug Depends on:    
Bug Blocks: 36074    
Attachments: On Solaris, define CMSG_ALIGN, CMSG_LEN, CMSG_SPACE if undefined

Description Dagobert Michelsen 2011-08-19 06:49:29 UTC
I am compiling dbus 1.5.6 on Solaris 9 Sparc with Sun Studio 12 and encountered a compilation error about missing CMSG_SPACE and CMSG_LEN:

Undefined                       first referenced
 symbol                             in file
CMSG_LEN                            .libs/libdbus_1_la-dbus-sysdeps-unix.o
CMSG_SPACE                          .libs/libdbus_1_la-dbus-sysdeps-unix.o

These tiny definitions in dbus/dbus-sysdeps-unix.c fix the issue:

#define CMSG_SPACE(l) ((size_t)_CMSG_HDR_ALIGN(sizeof (struct cmsghdr) + (l)))
#define CMSG_LEN(l) ((size_t)_CMSG_DATA_ALIGN(sizeof (struct cmsghdr)) + (l))

Best regards -- Dago
Comment 1 Dagobert Michelsen 2011-08-19 06:52:16 UTC
A slightly better fix is posted here: http://wiki.opencsw.org/porting-faq#toc10
Comment 2 Simon McVittie 2011-08-23 04:04:49 UTC
In the version you linked:

#ifndef CMSG_ALIGN
#   ifdef __sun__
#       define CMSG_ALIGN _CMSG_DATA_ALIGN
#   else
#       define CMSG_ALIGN(len) (((len)+sizeof(long)-1) & ~(sizeof(long)-1))
#   endif
#endif

the _CMSG_DATA_ALIGN macro is only assumed to be present if __sun__ is defined, which (according to that porting FAQ) is only the case under gcc, and not under Sun Studio. Should we be looking for __sun there, too?

I'd prefer to only enable this workaround on Solaris for the moment, unless/until someone reports that it affects some other OS. The generic code path (aligning to the next 'long' boundary) looks a bit suspicious to me - on LP64 platforms, a kernel could equally well be expecting 32-bit alignment - but I'd be OK with using it on Solaris.

I'll attach a patch in a moment.
Comment 3 Simon McVittie 2011-08-23 04:15:32 UTC
Created attachment 50480 [details] [review]
On Solaris, define CMSG_ALIGN, CMSG_LEN, CMSG_SPACE if undefined

This patch is against dbus-1.4 but should apply equally well to master.

Dago, does this look OK to you / work correctly on Solaris 9?

However, I note that according to Wikipedia, Solaris 10 is 6 years old (and is the first version to work on x86-64, which seems like a reasonable milestone for "still relevant"), and Solaris *11* (Express) is nearly a year old. I'm not entirely convinced we should be merging patches to work around deficiencies of a superseded, 8 year old libc... defining subtleties of the kernel/userland cmsg interface is surely the OS's job, not ours?
Comment 4 Dagobert Michelsen 2011-08-23 06:20:21 UTC
Yes, the patch applies cleanly and works. Thanks!

Solaris 9 is still fully supported with a basic support contract and Solaris 11 has not been released at all apart from the "express" developer beta. Blaming the os vendor may be essentially right, but it doesn't help when people try to build the software. Working around os problems is not that unusual in ensuring portability :-)
Comment 5 Simon McVittie 2011-09-21 03:41:29 UTC
Fixed in git for 1.4.16 and 1.5.8, thanks

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.