On Friday 26 June 2009 14:17, Luigi Rizzo wrote:
> Hi,
> I am maintaining the busybox port on FreeBSD, and there are
> several patches that I have to apply from time to time to
> let the code build (attached is the current version for 1.13.4).
> Some of them are also required when building openwrt on FreeBSD,
> because parts of the code are built to run on the host.
>
> It would be great if you could push at least some of them
> upstream to the main distribution -- I think they apply to
> most of the *BSD and derived systems around, including __APPLE__
> (in fact i do see you have some conditional code for __APPLE__
> that may apply to FreeBSD as well).
>
> The patch i am attaching is targeted to the FreeBSD port -- if you
> are interested i can try to clean it up a bit so that it has the
> right #ifdefs to avoid interference when building on linux
Yes, I wouldn't send patches which contain gems like this:
+#if !defined __FreeBSD__
+#endif
I applied some parts of the patch, the rest is in attached z.patch.
--- ./libbb/lineedit.c 2008-11-29 07:48:56.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/lineedit.c 2009-06-25
23:05:54.000000000 +0200
@@ -78,6 +78,7 @@
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
static const char null_str[] ALIGN1 = "";
#endif
+typedef void (*sighandler_t)(int signum);
/* We try to minimize both static and stack usage. */
struct lineedit_statics {
Instead of this, perhaps remove the single occurence
of sighandler_t in that file.
--- ./libbb/login.c 2008-11-09 18:28:09.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/login.c 2009-06-25
23:05:54.000000000 +0200
@@ -62,10 +62,12 @@
case 'm':
outbuf = uts.machine;
break;
+#if 0
case 'D':
case 'o':
outbuf = uts.domainname;
break;
+#endif
Yeah right, now *Linux* users will come complaining... not acceptable.
Make it so that both camps are satisfied. (Many such places)
--- ./libbb/makedev.c 2008-11-09 18:28:09.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/makedev.c 2009-06-25
23:05:54.000000000 +0200
@@ -5,7 +5,7 @@
*
* Licensed under GPL version 2, see file LICENSE in this tarball for details.
*/
-
+#if !defined __FreeBSD__
/* We do not include libbb.h - #define makedev() is there! */
#include "platform.h"
#include <features.h>
@@ -22,3 +22,4 @@
return makedev(major, minor);
}
#endif
+#endif /* !__FreeBSD__ */
Maybe it's needed, but it's not obvious. Can you add a comment why
do you exclude this code on FreeBSD?
If you will be sending further patches, please diff them
against current git.
--
vda
diff -ubwr ./libbb/getpty.c ../../work.patched/busybox-1.13.4/libbb/getpty.c
--- ./libbb/getpty.c 2008-11-09 18:28:09.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/getpty.c 2009-06-25 23:09:02.000000000 +0200
@@ -19,7 +19,7 @@
if (p > 0) {
grantpt(p); /* chmod+chown corresponding slave pty */
unlockpt(p); /* (what does this do?) */
-#if 0 /* if ptsname_r is not available... */
+#if 1 /* if ptsname_r is not available... */
const char *name;
name = ptsname(p); /* find out the name of slave pty */
if (!name) {
diff -ubwr ./libbb/lineedit.c ../../work.patched/busybox-1.13.4/libbb/lineedit.c
--- ./libbb/lineedit.c 2008-11-29 07:48:56.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/lineedit.c 2009-06-25 23:05:54.000000000 +0200
@@ -78,6 +78,7 @@
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
static const char null_str[] ALIGN1 = "";
#endif
+typedef void (*sighandler_t)(int signum);
/* We try to minimize both static and stack usage. */
struct lineedit_statics {
diff -ubwr ./libbb/login.c ../../work.patched/busybox-1.13.4/libbb/login.c
--- ./libbb/login.c 2008-11-09 18:28:09.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/login.c 2009-06-25 23:05:54.000000000 +0200
@@ -62,10 +62,12 @@
case 'm':
outbuf = uts.machine;
break;
+#if 0
case 'D':
case 'o':
outbuf = uts.domainname;
break;
+#endif
case 'd':
strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
break;
diff -ubwr ./libbb/makedev.c ../../work.patched/busybox-1.13.4/libbb/makedev.c
--- ./libbb/makedev.c 2008-11-09 18:28:09.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/makedev.c 2009-06-25 23:05:54.000000000 +0200
@@ -5,7 +5,7 @@
*
* Licensed under GPL version 2, see file LICENSE in this tarball for details.
*/
-
+#if !defined __FreeBSD__
/* We do not include libbb.h - #define makedev() is there! */
#include "platform.h"
#include <features.h>
@@ -22,3 +22,4 @@
return makedev(major, minor);
}
#endif
+#endif /* !__FreeBSD__ */
diff -ubwr ./libbb/match_fstype.c ../../work.patched/busybox-1.13.4/libbb/match_fstype.c
--- ./libbb/match_fstype.c 2008-11-09 18:28:09.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/match_fstype.c 2009-06-25 23:05:54.000000000 +0200
@@ -10,6 +10,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
+#if !defined __FreeBSD__
#include "libbb.h"
int FAST_FUNC match_fstype(const struct mntent *mt, const char *fstype)
@@ -42,3 +43,4 @@
return -(no + 1);
}
+#endif /* !__FreeBSD__ */
diff -ubwr ./libbb/safe_gethostname.c ../../work.patched/busybox-1.13.4/libbb/safe_gethostname.c
--- ./libbb/safe_gethostname.c 2008-11-09 18:28:09.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/safe_gethostname.c 2009-06-25 23:05:54.000000000 +0200
@@ -62,5 +62,5 @@
struct utsname uts;
uname(&uts);
- return xstrndup(!uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname));
+ return xstrndup("?", 2); // !uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname));
}
diff -ubwr ./libbb/xconnect.c ../../work.patched/busybox-1.13.4/libbb/xconnect.c
--- ./libbb/xconnect.c 2008-12-31 04:06:45.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/xconnect.c 2009-06-25 23:05:54.000000000 +0200
@@ -7,6 +7,7 @@
*/
#include <netinet/in.h>
+#include <sys/socket.h> // struct sockaddr
#include <net/if.h>
#include "libbb.h"
@@ -26,7 +27,7 @@
/* Actually, ifr_name is at offset 0, and in practice
* just giving char[IFNAMSIZ] instead of struct ifreq works too.
* But just in case it's not true on some obscure arch... */
- r = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr));
+ r = -1; //setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr));
if (r)
bb_perror_msg("can't bind to interface %s", iface);
return r;
diff -ubwr ./libbb/xfuncs.c ../../work.patched/busybox-1.13.4/libbb/xfuncs.c
--- ./libbb/xfuncs.c 2008-11-09 18:28:09.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/xfuncs.c 2009-06-25 23:05:54.000000000 +0200
@@ -226,8 +226,9 @@
long size;
// If the ioctl works for this, return it.
-
+#if !defined __FreeBSD__
if (ioctl(fd, BLKGETSIZE, &size) >= 0) return size*512;
+#endif
// FIXME: explain why lseek(SEEK_END) is not used here!
diff -ubwr ./libbb/xfuncs_printf.c ../../work.patched/busybox-1.13.4/libbb/xfuncs_printf.c
--- ./libbb/xfuncs_printf.c 2008-11-09 18:28:09.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libbb/xfuncs_printf.c 2009-06-25 23:05:54.000000000 +0200
@@ -294,8 +294,8 @@
return string_ptr;
}
-#if 0 /* If we will ever meet a libc which hasn't [f]dprintf... */
-int FAST_FUNC fdprintf(int fd, const char *format, ...)
+#if 1 /* If we will ever meet a libc which hasn't [f]dprintf... */
+int FAST_FUNC dprintf(int fd, const char *format, ...)
{
va_list p;
int r;
@@ -326,6 +326,32 @@
return r;
}
#endif
+char *strchrnul(const char *s, int c)
+{
+ char *r = strchr(s, c);
+ if (r == NULL)
+ r = (char *)s + strlen(s);
+ return r;
+}
+#if 0
+void *memrchr(const void *s, int c, size_t n)
+{
+ const char *p = s;
+ for (p += n - 1; p != s; p--)
+ if (*p == c) break;
+ return (*p == c ? p : NULL);
+}
+#endif
+
+size_t strnlen(const char *s, size_t maxlen)
+{
+ size_t i;
+ for (i = 0; i < maxlen; i++) {
+ if (s[i] == '\0')
+ break;
+ }
+ return i;
+}
void FAST_FUNC xsetenv(const char *key, const char *value)
{
diff -ubwr ./libpwdgrp/pwd_grp.c ../../work.patched/busybox-1.13.4/libpwdgrp/pwd_grp.c
--- ./libpwdgrp/pwd_grp.c 2008-11-09 18:28:19.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/libpwdgrp/pwd_grp.c 2009-06-25 23:05:54.000000000 +0200
@@ -19,7 +19,9 @@
*/
#include "libbb.h"
+#if !defined __FreeBSD__
#include <features.h>
+#endif
#include <assert.h>
#ifndef _PATH_SHADOW
diff -ubwr ./networking/nslookup.c ../../work.patched/busybox-1.13.4/networking/nslookup.c
--- ./networking/nslookup.c 2008-11-09 18:27:59.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/networking/nslookup.c 2009-06-25 23:05:54.000000000 +0200
@@ -11,6 +11,8 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
+#include <netinet/in.h>
+#include <sys/socket.h>
#include <resolv.h>
#include "libbb.h"
diff -ubwr ./networking/telnetd.c ../../work.patched/busybox-1.13.4/networking/telnetd.c
--- ./networking/telnetd.c 2008-11-09 18:27:59.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/networking/telnetd.c 2009-06-25 23:05:54.000000000 +0200
@@ -254,7 +254,7 @@
* cooked mode, and with XTABS CRMOD enabled (see tty(4)). */
tcgetattr(0, &termbuf);
termbuf.c_lflag |= ECHO; /* if we use readline we dont want this */
- termbuf.c_oflag |= ONLCR | XTABS;
+ termbuf.c_oflag |= ONLCR | OXTABS;
termbuf.c_iflag |= ICRNL;
termbuf.c_iflag &= ~IXOFF;
/*termbuf.c_lflag &= ~ICANON;*/
diff -ubwr ./networking/traceroute.c ../../work.patched/busybox-1.13.4/networking/traceroute.c
--- ./networking/traceroute.c 2008-11-09 18:27:59.000000000 +0100
+++ ../../work.patched/busybox-1.13.4/networking/traceroute.c 2009-06-25 23:05:54.000000000 +0200
@@ -205,9 +205,10 @@
//#define CONFIG_FEATURE_TRACEROUTE_USE_ICMP
-#include <net/if.h>
#include <arpa/inet.h>
#include <netinet/in.h>
+#include <sys/socket.h>
+#include <net/if.h>
#include <netinet/udp.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
@@ -638,7 +639,7 @@
outicmp->icmp_seq = htons(seq);
else
#endif
- outudp->dest = htons(port + seq);
+ outudp->uh_dport = htons(port + seq);
#if ENABLE_FEATURE_TRACEROUTE_USE_ICMP
if (useicmp) {
@@ -660,11 +661,11 @@
ui->ui_src = oui->ui_src;
ui->ui_dst = oui->ui_dst;
ui->ui_pr = oui->ui_pr;
- ui->ui_len = outudp->len;
- outudp->check = 0;
- outudp->check = in_cksum((uint16_t *)ui, packlen);
- if (outudp->check == 0)
- outudp->check = 0xffff;
+ ui->ui_len = outudp->uh_ulen;
+ outudp->uh_sum = 0;
+ outudp->uh_sum = in_cksum((uint16_t *)ui, packlen);
+ if (outudp->uh_sum == 0)
+ outudp->uh_sum = 0xffff;
*outip = tip;
}
@@ -792,8 +793,8 @@
/* XXX 8 is a magic number */
if (hlen + 12 <= cc &&
hip->ip_p == IPPROTO_UDP &&
- up->source == htons(ident) &&
- up->dest == htons(port + seq))
+ up->uh_sport == htons(ident) &&
+ up->uh_dport == htons(port + seq))
return (type == ICMP_TIMXCEED ? -1 : code + 1);
}
}
@@ -1148,8 +1149,8 @@
{
outip->ip_p = IPPROTO_UDP;
outudp = (struct udphdr *)outp;
- outudp->source = htons(ident);
- outudp->len = htons((uint16_t)(packlen - (sizeof(*outip) + optlen)));
+ outudp->uh_sport = htons(ident);
+ outudp->uh_ulen = htons((uint16_t)(packlen - (sizeof(*outip) + optlen)));
outdata = (outdata_t *)(outudp + 1);
}
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox