Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge branch 'linux-build'
Vsevolod Stakhov committed 11 years ago
commit dd762256ffb35398c5f69a97c0440609e244cc58
parent d3db9f7
26 files changed +317 -40
modified compat/Makefile.am
@@ -8,6 +8,8 @@ libbsd_compat_la_SOURCES= basename.c \
				file_at.c \
				gr_util.c \
				humanize_number.c \
-
				strtonum.c
+
				strtonum.c \
+
				strnstr.c \
+
				funopen.c

libbsd_compat_la_CFLAGS=	$(pkg_common_cflags) -shared
modified compat/bsd_compat.h
@@ -27,9 +27,37 @@
#ifndef _BSD_COMPAT_H
#define _BSD_COMPAT_H

-
#include <sys/stat.h>
-

#include "pkg_config.h"
+

+
#ifdef HAVE_BSD_SYS_CDEFS_H
+
#include <bsd/sys/cdefs.h>
+
#endif
+

+
#ifdef HAVE_BSD_STDLIB_H
+
#include <bsd/stdlib.h>
+
#endif
+

+
#ifdef HAVE_BSD_UNISTD_H
+
#include <bsd/unistd.h>
+
#endif
+

+
#ifdef HAVE_BSD_STRING_H
+
#include <bsd/string.h>
+
#endif
+

+
#ifdef HAVE_BSD_STDIO_H
+
#include <bsd/stdio.h>
+
#endif
+

+
#ifdef HAVE_BSD_ERR_H
+
#include <bsd/err.h>
+
#endif
+

+
#ifdef HAVE_BSD_LIBUTIL_H
+
#include <bsd/libutil.h>
+
#endif
+

+
#include <sys/stat.h>
#include "endian_util.h"

char *bsd_dirname(const char *);
@@ -80,7 +108,9 @@ ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t
#endif

#if !HAVE_UNLINKAT
-
#define AT_REMOVEDIR	0x800
+
# ifndef AT_REMOVEDIR
+
#  define AT_REMOVEDIR	0x800
+
# endif
int unlinkat(int fd, const char *path, int flag);
#endif

@@ -88,4 +118,49 @@ int unlinkat(int fd, const char *path, int flag);
long long strtonum(const char *, long long, long long, const char **);
#endif

+
#if !HAVE_STRNSTR
+
char * strnstr(const char *s, const char *find, size_t slen);
+
#endif
+

+
#ifndef _PATH_GROUP
+
#define _PATH_GROUP "/etc/group"
+
#endif
+

+
#ifndef __FBSDID
+
#define __FBSDID(x)
+
#endif
+

+
#ifndef EAUTH
+
#define EAUTH 80
+
#endif
+

+
#ifndef ENEEDAUTH
+
#define ENEEDAUTH 81
+
#endif
+

+
#ifndef MAXLOGNAME
+
#define MAXLOGNAME 33
+
#endif
+

+
#ifndef __DECONST
+
#define __DECONST(type, var)    ((type)(uintptr_t)(const void *)(var))
+
#endif
+

+
#ifndef __unused
+
#ifdef __GNUC__
+
# define __unused __attribute__((__unused__))
+
#else
+
# define __unused
+
#endif
+
#endif
+

+
#if !HAVE_FUNOPEN
+
#if !HAVE_FOPENCOOKIE
+
# error "Your system has neither funopen nor fopencookie, cannot continue"
+
#endif
+
FILE * funopen(const void *cookie, int (*readfn)(void *, char *, int),
+
         int (*writefn)(void *, const char *, int),
+
         off_t (*seekfn)(void *, off_t, int), int (*closefn)(void *));
+
#endif
+

#endif
modified compat/file_at.c
@@ -28,6 +28,7 @@
#include <fcntl.h>
#include <pthread.h>
#include <stdarg.h>
+
#define _GNU_SOURCE
#include <unistd.h>

#include <bsd_compat.h>
modified compat/gr_util.c
@@ -596,7 +596,7 @@ __gr_scan(char *line, struct group *gr)
	gr->gr_mem = NULL;
	ndx = 0;
	do {
-
		gr->gr_mem = reallocf(gr->gr_mem, sizeof(*gr->gr_mem) *
+
		gr->gr_mem = realloc(gr->gr_mem, sizeof(*gr->gr_mem) *
		    (ndx + 1));
		if (gr->gr_mem == NULL)
			return (false);
added compat/strnstr.c
@@ -0,0 +1,62 @@
+
/*-
+
 * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
+
 * Copyright (c) 1990, 1993
+
 *      The Regents of the University of California.  All rights reserved.
+
 *
+
 * This code is derived from software contributed to Berkeley by
+
 * Chris Torek.
+
 *
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions
+
 * are met:
+
 * 1. Redistributions of source code must retain the above copyright
+
 *    notice, this list of conditions and the following disclaimer.
+
 * 2. Redistributions in binary form must reproduce the above copyright
+
 *    notice, this list of conditions and the following disclaimer in the
+
 *    documentation and/or other materials provided with the distribution.
+
 * 3. Neither the name of the University nor the names of its contributors
+
 *    may be used to endorse or promote products derived from this software
+
 *    without specific prior written permission.
+
 *
+
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+
 * SUCH DAMAGE.
+
 */
+

+
#include <sys/cdefs.h>
+
#include <string.h>
+

+
#if !HAVE_STRNSTR
+
/*
+
 * Find the first occurrence of find in s, where the search is limited to the
+
 * first slen characters of s.
+
 */
+
char *
+
strnstr(const char *s, const char *find, size_t slen)
+
{
+
        char c, sc;
+
        size_t len;
+

+
        if ((c = *find++) != '\0') {
+
                len = strlen(find);
+
                do {
+
                        do {
+
                                if (slen-- < 1 || (sc = *s++) == '\0')
+
                                        return (NULL);
+
                        } while (sc != c);
+
                        if (len > slen)
+
                                return (NULL);
+
                } while (strncmp(s, find, len) != 0);
+
                s--;
+
        }
+
        return ((char *)s);
+
}
+
#endif
modified configure.ac
@@ -25,6 +25,7 @@ LIBPKG_AGE=0
LIBPKG_SO_VERSION="$LIBPKG_CURRENT:$LIBPKG_REVISION:$LIBPKG_AGE"
AC_SUBST(LIBPKG_SO_VERSION)

+
AC_GNU_SOURCE
AC_PROG_CC_C99
LT_INIT()
AC_CONFIG_MACRO_DIR([m4])
@@ -69,6 +70,24 @@ AC_LINK_IFELSE([

gl_LD_VERSION_SCRIPT

+
AC_CANONICAL_HOST
+
case $host_os in
+
  linux*)
+
        OS_CFLAGS="-pthread"
+
        OS_LDFLAGS="-pthread"
+
        OS_LIBS="-ldl -lrt -llzo2 -llzma"
+
        ;;
+
    *)
+
        OS_CFLAGS=
+
        OS_LDFLAGS=
+
        OS_LIBS=
+
        ;;
+
esac
+

+
AC_SUBST(OS_CFLAGS)
+
AC_SUBST(OS_LDFLAGS)
+
AC_SUBST(OS_LIBS)
+

AC_CHECK_HEADERS_ONCE([machine/endian.h])
AC_CHECK_HEADERS_ONCE([endian.h])
AC_CHECK_HEADERS_ONCE([sys/endian.h])
@@ -106,7 +125,21 @@ AC_CHECK_HEADERS_ONCE([stdio.h])
AC_CHECK_HEADERS_ONCE([float.h])
AC_CHECK_HEADERS_ONCE([math.h])
AC_CHECK_HEADERS_ONCE([osreldate.h])
+
AC_CHECK_HEADERS_ONCE([sys/socket.h])
+
AC_CHECK_HEADERS_ONCE([netinet/in.h])
+
AC_CHECK_HEADERS_ONCE([netinet/in6.h])
+
AC_CHECK_HEADERS_ONCE([sys/statfs.h])
AC_CHECK_HEADERS_ONCE([dirent.h], [sys/ndir.h], [sys/dir.h], [ndir.h])
+
AC_CHECK_HEADERS_ONCE([sys/capability.h])
+
AC_CHECK_HEADERS_ONCE([sys/capsicum.h])
+
AC_CHECK_HEADERS_ONCE([bsd/stdlib.h])
+
AC_CHECK_HEADERS_ONCE([bsd/string.h]) 
+
AC_CHECK_HEADERS_ONCE([bsd/stdio.h]) 
+
AC_CHECK_HEADERS_ONCE([bsd/readpassphrase.h])
+
AC_CHECK_HEADERS_ONCE([bsd/libutil.h]) 
+
AC_CHECK_HEADERS_ONCE([bsd/err.h])
+
AC_CHECK_HEADERS_ONCE([bsd/unistd.h])  
+
AC_CHECK_HEADERS_ONCE([bsd/sys/cdefs.h])

AC_CHECK_HEADER([regex.h], [
	AC_DEFINE(HAVE_REGEX_H, 1, [Define to 1 if you have the <regex.h> header file.])
@@ -120,7 +153,18 @@ AC_CHECK_FUNCS_ONCE([localtime_r])
AC_CHECK_FUNCS_ONCE([gmtime_r])
AC_CHECK_FUNCS_ONCE([strerror_r])
AC_CHECK_FUNCS_ONCE([strtonum])
-
AC_CHECK_FUNCS_ONCE([fstatat], [openat], [unlinkat], [readlinkat], [faccessat])
+
AC_CHECK_FUNCS_ONCE([strnstr])
+
AC_CHECK_FUNCS_ONCE([funopen])
+
AC_CHECK_FUNCS_ONCE([fopencookie])
+
AC_CHECK_FUNCS_ONCE([sysctlbyname])
+
AC_CHECK_DECLS(
+
	[[fstatat], [openat], [unlinkat], [readlinkat], [faccessat]],
+
	[], [], [
+
		#include <sys/types.h>
+
		#include <fcntl.h>
+
		#include <sys/stat.h>
+
		#include <unistd.h>
+
	])
AC_CHECK_DECLS(
	[[be16dec], [be32dec], [be64dec], [le16dec], [le32dec], [le64dec],
	 [be16enc], [be32enc], [be64enc], [le16enc], [le32enc], [le64enc]],
@@ -132,6 +176,25 @@ AC_CHECK_FUNCS_ONCE([closefrom])
AC_CHECK_FUNCS_ONCE([dirfd])
AC_CHECK_FUNCS_ONCE([sysconf])

+
AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, 
+
	struct in6_addr.s6_addr16, 
+
	struct sockaddr_in.sin_len, 
+
	struct sockaddr_in6.sin6_len, 
+
	struct sockaddr_storage.ss_len,
+
	struct sockaddr_storage.ss_family,
+
	struct sockaddr_storage.__ss_family], [], [],
+
[#include <sys/types.h>
+
#ifdef HAVE_NETINET_IN_H
+
#include <netinet/in.h>
+
#endif
+
#ifdef HAVE_NETINET_IN6_H
+
#include <netinet/in6.h>
+
#endif
+
#ifdef HAVE_SYS_SOCKET_H
+
#include <sys/socket.h>
+
#endif
+
])
+

PKG_PROG_PKG_CONFIG

AC_DEFUN([AC_PROG_GIT], [AC_CHECK_PROG(GITBIN,git,yes)])
@@ -190,6 +253,11 @@ AC_SEARCH_LIBS([jail_getid], [jail], [
	AC_DEFINE(HAVE_LIBJAIL, 1, [Define to 1 if you have the 'jail' library (-ljail).])
	LIBJAIL_LIB="-ljail"
	], [])
+
	
+
AC_SEARCH_LIBS([getprogname], [bsd], [
+
	AC_DEFINE(HAVE_LIBBSD, 1, [Define to 1 if you have the 'bsd' library (-lbsd).])
+
	LIBBSD_LIB="-lbsd"
+
	], [])

AC_CHECK_HEADERS([gelf.h libelf.h], [
	AC_CHECK_TYPES([Elf_Note], [
@@ -217,24 +285,28 @@ AC_CHECK_HEADER([execinfo.h], [
AC_ARG_WITH([ldns], AS_HELP_STRING([--with-ldns], [Build with ldns for name resolving]))

AS_IF([test "x$with_ldns" = "xyes"], [
-
   PKG_CHECK_MODULES([LDNS], [libldns], [AC_DEFINE([HAVE_LDNS], [1], [Use ldns])],
+
   PKG_CHECK_MODULES([LDNS], [libldns], [
+
   	AC_DEFINE([HAVE_LDNS], [1], [Use ldns])
+
   	AC_SUBST([HAVE_LDNS], [1], [Use ldns])
+
   ],
   [
   	AC_CHECK_HEADER([ldns/ldns.h], [
   		AC_CHECK_LIB(ldns, ldns_resolver_new_frm_file, [
   			AC_DEFINE([HAVE_LDNS], [1], [Use ldns])
-
   			AC_DEFINE([LDNS_LIBS], [-lldns], [LDNS library])
+
   			AC_SUBST([HAVE_LDNS], [1], [Use ldns])
+
   			AC_SUBST([LDNS_LIBS], [-lldns], [LDNS library])
   		])
   	])
   ])
+
   AS_IF([test "x$HAVE_LDNS" != "x1"],
+
	[AC_MSG_ERROR([Unable to find the libdns])])
])

-
AC_CHECK_HEADER([sys/capability.h], [
-
        AC_CHECK_LIB(c, cap_sandboxed, [
-
                AC_DEFINE(HAVE_CAPSICUM, 1, [Define 1 if you have 'capsicum'.])
-
        ])
-

+
AC_CHECK_LIB(c, cap_sandboxed, [
+
   AC_DEFINE(HAVE_CAPSICUM, 1, [Define 1 if you have 'capsicum'.])
])

+

AC_CACHE_CHECK(for arc4random_uniform,
               ac_cv_func_arc4random_uniform,
               [AC_TRY_COMPILE([#include <stdlib.h>],
@@ -313,6 +385,7 @@ AM_CONDITIONAL(LIBELF_BUNDLED, test "$ac_cv_binary_abi" = "elf" -a "$libelf_bund

AC_SUBST([LIBJAIL_LIB])
AC_SUBST([LIBEXECINFO_LIB])
+
AC_SUBST([LIBBSD_LIB])
AC_SUBST([TESTS])
AC_SUBST([LDNS_LIBS])
AC_SUBST([LDNS_CFLAGS])
modified external/Makefile.am
@@ -243,7 +243,7 @@ libsqlite_static_la_SOURCES= $(libsqlite_la_SOURCES)
libsqlite_static_la_CFLAGS=	$(sqlite_common_cflags) -static
libsqlite_static_la_LDFLAGS=	-all-static

-
libfetch_common_cflags=	-DWITH_SSL -Wno-pointer-sign
+
libfetch_common_cflags=	-I$(top_srcdir)/compat -DWITH_SSL -Wno-pointer-sign
libfetch_la_CFLAGS=	$(libfetch_common_cflags) -shared
libfetch_la_SOURCES=	libfetch/common.c \
			libfetch/fetch.c \
modified external/libfetch/common.c
@@ -28,6 +28,8 @@
 */

#include <sys/cdefs.h>
+
#include "bsd_compat.h"
+

__FBSDID("$FreeBSD: head/lib/libfetch/common.c 273124 2014-10-15 07:35:50Z des $");

#include <sys/param.h>
@@ -224,7 +226,9 @@ fetch_reopen(int sd)
	if ((conn = calloc(1, sizeof(*conn))) == NULL)
		return (NULL);
	fcntl(sd, F_SETFD, FD_CLOEXEC);
+
#ifdef SO_NOSIGPIPE
	setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof opt);
+
#endif
	conn->sd = sd;
	++conn->ref;
	return (conn);
modified external/libfetch/fetch.c
@@ -27,6 +27,7 @@
 */

#include <sys/cdefs.h>
+
#include "bsd_compat.h"
__FBSDID("$FreeBSD: head/lib/libfetch/fetch.c 252375 2013-06-29 15:51:27Z kientzle $");

#include <sys/param.h>
modified external/libfetch/file.c
@@ -27,6 +27,7 @@
 */

#include <sys/cdefs.h>
+
#include "bsd_compat.h"
__FBSDID("$FreeBSD: head/lib/libfetch/file.c 240495 2012-09-14 12:15:13Z eadler $");

#include <sys/param.h>
modified external/libfetch/ftp.c
@@ -27,6 +27,7 @@
 */

#include <sys/cdefs.h>
+
#include "bsd_compat.h"
__FBSDID("$FreeBSD: head/lib/libfetch/ftp.c 226537 2011-10-19 11:43:51Z des $");

/*
@@ -133,7 +134,9 @@ unmappedaddr(struct sockaddr_in6 *sin6)
	sin4->sin_addr.s_addr = addr;
	sin4->sin_port = port;
	sin4->sin_family = AF_INET;
+
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
	sin4->sin_len = sizeof(struct sockaddr_in);
+
#endif
}

/*
@@ -486,7 +489,7 @@ struct ftpio {

static int	 ftp_readfn(void *, char *, int);
static int	 ftp_writefn(void *, const char *, int);
-
static fpos_t	 ftp_seekfn(void *, fpos_t, int);
+
static off_t	 ftp_seekfn(void *, off_t, int);
static int	 ftp_closefn(void *);

static int
@@ -549,18 +552,18 @@ ftp_writefn(void *v, const char *buf, int len)
	return (-1);
}

-
static fpos_t
-
ftp_seekfn(void *v, fpos_t pos __unused, int whence __unused)
+
static off_t
+
ftp_seekfn(void *v, off_t pos __unused, int whence __unused)
{
	struct ftpio *io;

	io = (struct ftpio *)v;
	if (io == NULL) {
		errno = EBADF;
-
		return (-1);
+
		return ((off_t)-1);
	}
	errno = ESPIPE;
-
	return (-1);
+
	return ((off_t)-1);
}

static int
@@ -770,7 +773,8 @@ ftp_transfer(conn_t *conn, const char *oper, const char *file,
		if (bindaddr != NULL && *bindaddr != '\0' &&
		    fetch_bind(sd, sa.ss_family, bindaddr) != 0)
			goto sysouch;
-
		if (connect(sd, (struct sockaddr *)&sa, sa.ss_len) == -1)
+

+
		if (connect(sd, (struct sockaddr *)&sa, l) == -1)
			goto sysouch;

		/* make the server initiate the transfer */
@@ -784,12 +788,14 @@ ftp_transfer(conn_t *conn, const char *oper, const char *file,
		u_int32_t a;
		u_short p;
		int arg, d;
+
		socklen_t sslen;
		char *ap;
		char hname[INET6_ADDRSTRLEN];

		switch (sa.ss_family) {
		case AF_INET6:
			((struct sockaddr_in6 *)&sa)->sin6_port = 0;
+
			sslen = sizeof(struct sockaddr_in6);
#ifdef IPV6_PORTRANGE
			arg = low ? IPV6_PORTRANGE_DEFAULT : IPV6_PORTRANGE_HIGH;
			if (setsockopt(sd, IPPROTO_IPV6, IPV6_PORTRANGE,
@@ -799,15 +805,18 @@ ftp_transfer(conn_t *conn, const char *oper, const char *file,
			break;
		case AF_INET:
			((struct sockaddr_in *)&sa)->sin_port = 0;
+
			sslen = sizeof(struct sockaddr_in);
+
#ifdef IP_PORTRANGE
			arg = low ? IP_PORTRANGE_DEFAULT : IP_PORTRANGE_HIGH;
			if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE,
				(char *)&arg, sizeof(arg)) == -1)
				goto sysouch;
+
#endif
			break;
		}
		if (verbose)
			fetch_info("binding data socket");
-
		if (bind(sd, (struct sockaddr *)&sa, sa.ss_len) == -1)
+
		if (bind(sd, (struct sockaddr *)&sa, sslen) == -1)
			goto sysouch;
		if (listen(sd, 1) == -1)
			goto sysouch;
@@ -830,7 +839,7 @@ ftp_transfer(conn_t *conn, const char *oper, const char *file,
			e = -1;
			sin6 = (struct sockaddr_in6 *)&sa;
			sin6->sin6_scope_id = 0;
-
			if (getnameinfo((struct sockaddr *)&sa, sa.ss_len,
+
			if (getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in6),
				hname, sizeof(hname),
				NULL, 0, NI_NUMERICHOST) == 0) {
				e = ftp_cmd(conn, "EPRT |%d|%s|%d|", 2, hname,
modified external/libfetch/http.c
@@ -27,6 +27,7 @@
 */

#include <sys/cdefs.h>
+
#include "bsd_compat.h"
__FBSDID("$FreeBSD: head/lib/libfetch/http.c 267133 2014-06-05 22:16:26Z bapt $");

/*
@@ -60,7 +61,7 @@ __FBSDID("$FreeBSD: head/lib/libfetch/http.c 267133 2014-06-05 22:16:26Z bapt $"
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
-

+
#define _XOPEN_SOURCE
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/time.h>
@@ -1421,9 +1422,10 @@ http_connect(struct url *URL, struct url *purl, const char *flags)
		fetch_syserr();
		return (NULL);
	}
-

+
#ifdef TCP_NOPUSH
	val = 1;
	setsockopt(conn->sd, IPPROTO_TCP, TCP_NOPUSH, &val, sizeof(val));
+
#endif

	return (conn);
}
@@ -1725,9 +1727,11 @@ http_request_body(struct url *URL, const char *op, struct url_stat *us,
		 * be compatible with such configurations, fiddle with socket
		 * options to force the pending data to be written.
		 */
+
#ifdef TCP_NOPUSH
		val = 0;
		setsockopt(conn->sd, IPPROTO_TCP, TCP_NOPUSH, &val,
			   sizeof(val));
+
#endif
		val = 1;
		setsockopt(conn->sd, IPPROTO_TCP, TCP_NODELAY, &val,
			   sizeof(val));
modified libpkg/Makefile.am
@@ -70,7 +70,7 @@ libpkg_la_SOURCES+= pkg_macho.c
pkg_common_cflags+=	-I$(top_srcdir)/external/libmachista
endif

-
libpkg_la_CFLAGS=	$(pkg_common_cflags) -shared
+
libpkg_la_CFLAGS=	@OS_CFLAGS@ $(pkg_common_cflags) -shared
libpkg_la_LIBADD=	$(top_builddir)/compat/libbsd_compat.la \
			$(top_builddir)/external/libucl.la \
			$(top_builddir)/external/libsqlite.la \
modified libpkg/pkg_audit.c
@@ -40,6 +40,10 @@

#include <expat.h>

+
#ifdef HAVE_SYS_CAPSICUM_H
+
#include <sys/capsicum.h>
+
#endif
+

#include "pkg.h"
#include "private/pkg.h"
#include "private/event.h"
modified libpkg/pkg_elf.c
@@ -48,7 +48,7 @@
#include <fcntl.h>
#include <gelf.h>
#include <libgen.h>
-
#if defined(HAVE_LINK_H) && !defined(__DragonFly__)
+
#if defined(HAVE_LINK_H) && !defined(__DragonFly__) && defined(HAVE_LIBELF)
#include <link.h>
#endif
#include <paths.h>
modified libpkg/pkg_jobs.c
@@ -32,6 +32,8 @@
#include "pkg_config.h"
#endif

+
#include <bsd_compat.h>
+

#include <sys/param.h>
#include <sys/mount.h>
#include <sys/types.h>
@@ -49,7 +51,9 @@
#include <sys/wait.h>
#include <ctype.h>

-
#include <bsd_compat.h>
+
#ifdef HAVE_SYS_STATFS_H
+
#include <sys/statfs.h>
+
#endif

#include "utarray.h"

modified libpkg/pkg_printf.c
@@ -24,6 +24,7 @@
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

+
#include "bsd_compat.h"
#include <sys/types.h>
#include <sys/sbuf.h>
#include <sys/stat.h>
modified libpkg/pkg_repo_create.c
@@ -28,6 +28,7 @@
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
+
#include "pkg_config.h"

#include <sys/types.h>
#include <sys/stat.h>
@@ -57,7 +58,7 @@
#include "private/utils.h"
#include "private/pkg.h"
#include "private/pkgdb.h"
-
#include "pkg_config.h"
+


struct digest_list_entry {
	char *origin;
@@ -579,8 +580,12 @@ pkg_create_repo(char *path, const char *output_dir, bool filelist,
	num_workers = pkg_object_int(pkg_config_get("WORKERS_COUNT"));
	if (num_workers <= 0) {
		len = sizeof(num_workers);
+
#ifdef HAVE_SYSCTLBYNAME
		if (sysctlbyname("hw.ncpu", &num_workers, &len, NULL, 0) == -1)
			num_workers = 6;
+
#else
+
		num_workers = 6;
+
#endif
	}

	if ((fts = fts_open(repopath, FTS_PHYSICAL|FTS_NOCHDIR, NULL)) == NULL) {
modified libpkg/pkgdb.c
@@ -36,6 +36,8 @@
#include "pkg_config.h"
#endif

+
#include <bsd_compat.h>
+

#include <sys/param.h>
#include <sys/mount.h>

@@ -55,7 +57,9 @@

#include <sqlite3.h>

-
#include <bsd_compat.h>
+
#ifdef HAVE_SYS_STATFS_H
+
#include <sys/statfs.h>
+
#endif

#include "pkg.h"
#include "private/event.h"
@@ -950,6 +954,7 @@ pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)

		sqlite3_initialize();

+
#ifdef MNT_LOCAL
		/*
		 * Fall back on unix-dotfile locking strategy if on a network filesystem
		 */
@@ -957,7 +962,7 @@ pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)
			if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
				sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
		}
-

+
#endif
		if (sqlite3_open(localpath, &db->sqlite) != SQLITE_OK) {
			ERROR_SQLITE(db->sqlite, "sqlite open");
			pkgdb_close(db);
modified libpkg/private/pkg.h
@@ -30,6 +30,8 @@
#ifndef _PKG_PRIVATE_H
#define _PKG_PRIVATE_H

+
#include "bsd_compat.h"
+

#include <sys/param.h>
#include <sys/cdefs.h>
#include <sys/sbuf.h>
modified libpkg/repo/binary/init.c
@@ -39,6 +39,10 @@

#include <bsd_compat.h>

+
#ifdef HAVE_SYS_STATFS_H
+
#include <sys/statfs.h>
+
#endif
+

#include "pkg.h"
#include "private/event.h"
#include "private/pkg.h"
@@ -296,7 +300,6 @@ int
pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
{
	char filepath[MAXPATHLEN];
-
	struct statfs stfs;
	const char *dbdir = NULL;
	sqlite3 *sqlite = NULL;
	int flags;
@@ -307,6 +310,8 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
	sqlite3_initialize();
	dbdir = pkg_object_string(pkg_config_get("PKG_DBDIR"));

+
#ifdef MNT_LOCAL
+
	struct statfs stfs;
	/*
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
	 */
@@ -314,6 +319,7 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
	}
+
#endif

	snprintf(filepath, sizeof(filepath), "%s/%s.meta",
		dbdir, pkg_repo_name(repo));
@@ -401,7 +407,6 @@ int
pkg_repo_binary_create(struct pkg_repo *repo)
{
	char filepath[MAXPATHLEN];
-
	struct statfs stfs;
	const char *dbdir = NULL;
	sqlite3 *sqlite = NULL;
	int retcode;
@@ -415,6 +420,8 @@ pkg_repo_binary_create(struct pkg_repo *repo)
	if (access(filepath, R_OK) == 0)
		return (EPKG_CONFLICT);

+
#ifdef MNT_LOCAL
+
	struct statfs stfs;
	/*
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
	 */
@@ -422,6 +429,7 @@ pkg_repo_binary_create(struct pkg_repo *repo)
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
	}
+
#endif

	/* Open for read/write/create */
	if (sqlite3_open(filepath, &sqlite) != SQLITE_OK)
modified src/Makefile.am
@@ -36,27 +36,30 @@ pkg_SOURCES= add.c \
			version.c \
			which.c
			
-
pkg_LDADD=	$(top_builddir)/libpkg/libpkg.la \
-
		$(top_builddir)/external/libsbuf.la \
+
pkg_LDADD=	@OS_LDFLAGS@ \
+
			$(top_builddir)/libpkg/libpkg.la \
+
			$(top_builddir)/external/libsbuf.la \
			@LIBJAIL_LIB@ \
			-lutil \
			-lcrypto
-
pkg_CFLAGS=		-I$(top_srcdir)/libpkg \
+
pkg_CFLAGS=	 @OS_CFLAGS@ \
+
			-I$(top_srcdir)/libpkg \
			-I$(top_builddir)/libpkg \
			-I$(top_srcdir)/compat \
			-I$(top_srcdir)/external/libsbuf \
			-I$(top_srcdir)/external/uthash \
			-I$(top_srcdir)/external/expat/lib \
-
			-DGITHASH=\"$(GIT_HEAD)\" \
-
			-Werror
+
			-DGITHASH=\"$(GIT_HEAD)\" 
pkg_static_SOURCES=
-
pkg_static_LDADD= $(top_builddir)/libpkg/libpkg_static.la \
+
pkg_static_LDADD= @OS_LDFLAGS@ \
+
			$(top_builddir)/libpkg/libpkg_static.la \
			$(top_builddir)/compat/libbsd_compat.la \
			$(top_builddir)/external/libsbuf_static.la \
			$(pkg_OBJECTS) \
			@LIBJAIL_LIB@ \
			@LIBEXECINFO_LIB@ \
			@LDNS_LIBS@ \
+
			@OS_LIBS@ \
			-larchive \
			-lz \
			-lutil \
modified src/audit.c
@@ -46,6 +46,10 @@
#include <sysexits.h>
#include <uthash.h>

+
#ifdef HAVE_SYS_CAPSICUM_H
+
#include <sys/capsicum.h>
+
#endif
+

#include <pkg.h>
#include "pkgcli.h"

modified src/pkgcli.h
@@ -28,6 +28,9 @@
#ifndef _PKGCLI_H
#define _PKGCLI_H

+
#include <stdint.h>
+
#include <bsd_compat.h>
+

#define pkg_warnx(fmt, ...) pkg_fprintf(stderr, "%s" fmt, getprogname(), __VA_ARGS__, -1)

extern bool quiet;
modified src/repo.c
@@ -24,16 +24,22 @@
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

+
#include <bsd_compat.h>
#include <getopt.h>
#include <signal.h>
#include <sysexits.h>
#include <stdio.h>
#include <string.h>
+

+
#ifdef HAVE_BSD_READPASSPHRASE_H
+
#include <bsd/readpassphrase.h>
+
#else
#include <readpassphrase.h>
+
#endif
+

#include <unistd.h>

#include <pkg.h>
-

#include "pkgcli.h"

void
modified src/utils.c
@@ -64,7 +64,7 @@ query_tty_yesno(bool r, const char *msg, ...)
	FILE	*tty;
	int	 tty_flags = O_RDWR;

-
#if !defined(__DragonFly__) && !defined(__APPLE__)
+
#ifdef O_TTY_INIT
	tty_flags |= O_TTY_INIT;
#endif
	tty_fd = open(_PATH_TTY, tty_flags);