Bug 3097

Summary: BB making easily-fixed non-portable assumptions
Product: Busybox Reporter: bugdal
Component: Standard ComplianceAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Host: Target:
Build:
Attachments: Patch
config file for which COMMON_BUFSIZE is too small.

Description bugdal 2011-01-15 23:19:29 UTC
Four issues, patch to fix them is attached:

1. Apparently BB is relying on header pollution to get the definitions of major() and minor() macros used by tar, cpio, etc. The "correct" header for them is sys/sysmacros.h. The attached patch includes sysmacros.h, but only if major was not already defined by another header (usually sys/types.h).

2. COMMON_BUFSIZE is insufficient for inetd unless libc BUFSIZ is >= ~2k. Patch fixes it, but some tweaking may be desired to find the minimal value that will work.

3. BB is using the nonstandard "fdprintf" name by default for a function that was standardized by POSIX 2008 as "dprintf". Attached patch checks _POSIX_VERSION and uses the standard name when POSIX 2008 is detected, but a better solution would be to always use dprintf except on a finite known-bad set of systems that lack it. Unfortunately I don't know which systems these are.

4. networking/interface.c tries to include a kernel header by default instead of using the userspace net/ethernet.h, unless it detects glibc or newlib. The correct behavior would be to use the correct userspace header except on a finite known set of systems that lack it, but I don't know what these systems are, so I used a dummy "WTF_SOME_WEIRD_LIBC" as the test instead. This should obviously be fixed before committing.
Comment 1 bugdal 2011-01-15 23:20:11 UTC
Created attachment 2851 [details]
Patch
Comment 2 Denys Vlasenko 2011-01-16 00:38:18 UTC
> 2. COMMON_BUFSIZE is insufficient for inetd unless libc BUFSIZ is >= ~2k. Patch
> fixes it, but some tweaking may be desired to find the minimal value that will
> work.

Please attach the .config where it happens.
Comment 3 bugdal 2011-01-16 02:05:02 UTC
I can if you like, but it happens whenever inetd is enabled (even with no internal services) and BUFSIZ==1024.
Comment 4 bugdal 2011-01-16 05:36:56 UTC
Created attachment 2857 [details]
config file for which COMMON_BUFSIZE is too small.
Comment 5 Denys Vlasenko 2011-01-16 16:32:12 UTC
(In reply to comment #4)
> Created attachment 2857 [details]
> config file for which COMMON_BUFSIZE is too small.

I added this test printouts to networking/inetd.c:

int inetd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int inetd_main(int argc UNUSED_PARAM, char **argv)
{
        struct sigaction sa, saved_pipe_handler;
        servtab_t *sep, *sep2;
        struct passwd *pwd;
        struct group *grp = grp; /* for compiler */
        int opt;
        pid_t pid;
        sigset_t omask;
        
        INIT_G();
        
bb_error_msg("sizeof(G):%ld", (long)sizeof(G));
bb_error_msg("COMMON_BUFSIZE:%ld", (long)COMMON_BUFSIZE);
exit(0);

With your .config, building against 64-bit glibc I see:

$ ./busybox inetd
inetd: sizeof(G):464
inetd: COMMON_BUFSIZE:8193

when I additionally enable all inetd options, I see:

inetd: sizeof(G):608
inetd: COMMON_BUFSIZE:8193

And finally, building this .config against 32-bit uclibc configured for BUFSIZ=1024, I see:

inetd: sizeof(G):584
inetd: COMMON_BUFSIZE:1025

I don't see the problem. Please explain where is it.
Comment 6 bugdal 2011-01-16 22:21:44 UTC
Indeed, after further investigation, the COMMON_BUFSIZE issue was coming from a bug in my build environment which was bloating the size of inetd's globals, and not from BB. The other issues in this bug report still stand.
Comment 7 Denys Vlasenko 2011-02-07 14:01:12 UTC
I incorporated sys/sysmacros.h and fdprintf fixes. Thanks!