midipix / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone
Blob Blame History Raw
diff -Nru libbsd-0.9.1.orig/include/bsd/sys/cdefs.h libbsd-0.9.1/include/bsd/sys/cdefs.h
--- libbsd-0.9.1.orig/include/bsd/sys/cdefs.h	2018-05-22 15:56:14.000000000 +0200
+++ libbsd-0.9.1/include/bsd/sys/cdefs.h	2018-05-30 15:27:07.067975364 +0200
@@ -93,7 +93,7 @@
 #define LIBBSD_DEPRECATED(x)
 #endif
 
-#if LIBBSD_GCC_VERSION >= 0x0200
+#if 0
 #define LIBBSD_REDIRECT(name, proto, alias) name proto __asm__(LIBBSD_ASMNAME(#alias))
 #endif
 #define LIBBSD_ASMNAME(cname) LIBBSD_ASMNAME_PREFIX(__USER_LABEL_PREFIX__, cname)
diff -Nru libbsd-0.9.1.orig/include/bsd/vis.h libbsd-0.9.1/include/bsd/vis.h
--- libbsd-0.9.1.orig/include/bsd/vis.h	2018-05-22 16:07:42.000000000 +0200
+++ libbsd-0.9.1/include/bsd/vis.h	2018-05-30 15:37:23.466013504 +0200
@@ -113,14 +113,9 @@
 
 int	strvis(char *, const char *, int);
 int	stravis(char **, const char *, int);
-#ifdef LIBBSD_NETBSD_VIS
-/* NetBSD prototype. */
-int	LIBBSD_REDIRECT(strnvis, (char *, size_t, const char *, int),
-                        strnvis_netbsd);
-#else
-/* OpenBSD prototype (current default). */
-int	strnvis(char *, const char *, size_t, int);
-#endif
+
+/* NetBSD prototype */
+int	strnvis(char *, size_t, const char *, int);
 
 int	strsvis(char *, const char *, int, const char *);
 int	strsnvis(char *, size_t, const char *, int, const char *);
@@ -135,14 +130,9 @@
     int *);
 
 int	strunvis(char *, const char *);
-#ifdef LIBBSD_NETBSD_VIS
-/* NetBSD prototype. */
-int	LIBBSD_REDIRECT(strnunvis, (char *, size_t, const char *),
-                        strnunvis_netbsd);
-#else
-/* OpenBSD prototype (current default). */
-ssize_t	strnunvis(char *, const char *, size_t);
-#endif
+
+/* NetBSD prototype */
+int	strnunvis(char *, size_t, const char *);
 
 int	strunvisx(char *, const char *, int);
 int	strnunvisx(char *, size_t, const char *, int);
diff -Nru libbsd-0.9.1.orig/src/flopen.c libbsd-0.9.1/src/flopen.c
--- libbsd-0.9.1.orig/src/flopen.c	2018-05-21 04:33:33.000000000 +0200
+++ libbsd-0.9.1/src/flopen.c	2018-05-30 15:09:48.789934331 +0200
@@ -32,6 +32,7 @@
 #include <sys/stat.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdarg.h>
 #include <unistd.h>
 
diff -Nru libbsd-0.9.1.orig/src/getentropy.c libbsd-0.9.1/src/getentropy.c
--- libbsd-0.9.1.orig/src/getentropy.c	2018-05-21 04:48:37.000000000 +0200
+++ libbsd-0.9.1/src/getentropy.c	2018-05-30 15:44:15.596626881 +0200
@@ -26,6 +26,8 @@
 
 #if defined(__linux__)
 #include "getentropy_linux.c"
+#elif defined(__midipix__)
+#include "getentropy_midipix.c"
 #elif defined(__GNU__)
 #include "getentropy_hurd.c"
 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
diff -Nru libbsd-0.9.1.orig/src/getentropy_midipix.c libbsd-0.9.1/src/getentropy_midipix.c
--- libbsd-0.9.1.orig/src/getentropy_midipix.c	1970-01-01 01:00:00.000000000 +0100
+++ libbsd-0.9.1/src/getentropy_midipix.c	2018-05-30 15:43:30.744779217 +0200
@@ -0,0 +1,153 @@
+/*	$OpenBSD: getentropy_linux.c,v 1.45 2018/03/13 22:53:28 bcook Exp $	*/
+
+/*
+ * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
+ * Copyright (c) 2014 Bob Beck <beck@obtuse.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Emulation of getentropy(2) as documented at:
+ * http://man.openbsd.org/getentropy.2
+ */
+
+#define	_POSIX_C_SOURCE	199309L
+#define	_GNU_SOURCE	1
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+#include <sys/statvfs.h>
+#include <sys/socket.h>
+#include <sys/mount.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <link.h>
+#include <termios.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <time.h>
+
+#include "hash/sha512.h"
+
+#ifdef HAVE_GETAUXVAL
+#include <sys/auxv.h>
+#endif
+#include <sys/vfs.h>
+
+int	getentropy(void *buf, size_t len);
+
+static int gotdata(char *buf, size_t len);
+
+static int getentropy_urandom(void *buf, size_t len);
+
+int
+getentropy(void *buf, size_t len)
+{
+	int ret = -1;
+
+	if (len > 256) {
+		errno = EIO;
+		return (-1);
+	}
+
+	/*
+	 * Try to get entropy with /dev/urandom
+	 *
+	 * This can fail if the process is inside a chroot or if file
+	 * descriptors are exhausted.
+	 */
+	ret = getentropy_urandom(buf, len);
+	if (ret != -1)
+		return (ret);
+
+	errno = EIO;
+	return (ret);
+}
+
+/*
+ * Basic sanity checking; wish we could do better.
+ */
+static int
+gotdata(char *buf, size_t len)
+{
+	char	any_set = 0;
+	size_t	i;
+
+	for (i = 0; i < len; ++i)
+		any_set |= buf[i];
+	if (any_set == 0)
+		return (-1);
+	return (0);
+}
+
+static int
+getentropy_urandom(void *buf, size_t len)
+{
+	struct stat st;
+	size_t i;
+	int fd, cnt, flags;
+	int save_errno = errno;
+
+start:
+
+	flags = O_RDONLY;
+#ifdef O_NOFOLLOW
+	flags |= O_NOFOLLOW;
+#endif
+#ifdef O_CLOEXEC
+	flags |= O_CLOEXEC;
+#endif
+	fd = open("/dev/urandom", flags, 0);
+	if (fd == -1) {
+		if (errno == EINTR)
+			goto start;
+		goto nodevrandom;
+	}
+#ifndef O_CLOEXEC
+	fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+#endif
+
+	/* Lightly verify that the device node looks sane */
+	if (fstat(fd, &st) == -1 || !S_ISCHR(st.st_mode)) {
+		close(fd);
+		goto nodevrandom;
+	}
+	for (i = 0; i < len; ) {
+		size_t wanted = len - i;
+		ssize_t ret = read(fd, (char *)buf + i, wanted);
+
+		if (ret == -1) {
+			if (errno == EAGAIN || errno == EINTR)
+				continue;
+			close(fd);
+			goto nodevrandom;
+		}
+		i += ret;
+	}
+	close(fd);
+	if (gotdata(buf, len) == 0) {
+		errno = save_errno;
+		return (0);		/* satisfied */
+	}
+nodevrandom:
+	errno = EIO;
+	return (-1);
+}
diff -Nru libbsd-0.9.1.orig/src/getpeereid.c libbsd-0.9.1/src/getpeereid.c
--- libbsd-0.9.1.orig/src/getpeereid.c	2017-06-06 04:06:45.000000000 +0200
+++ libbsd-0.9.1/src/getpeereid.c	2018-05-30 15:10:23.777937764 +0200
@@ -40,7 +40,7 @@
 getpeereid(int s, uid_t *euid, gid_t *egid)
 {
 /* XXX: This should be autodetected at build time instead. */
-#if defined(__linux__)
+#if defined(__linux__) || defined(__midipix__)
 	struct ucred cred;
 #elif defined(__OpenBSD__)
 	struct sockpeercred cred;
diff -Nru libbsd-0.9.1.orig/src/setproctitle.c libbsd-0.9.1/src/setproctitle.c
--- libbsd-0.9.1.orig/src/setproctitle.c	2018-04-21 23:30:22.000000000 +0200
+++ libbsd-0.9.1/src/setproctitle.c	2018-05-30 15:13:25.245835004 +0200
@@ -221,8 +221,13 @@
 #define SPT_MAXTITLE 255
 #endif
 
+#ifdef __midipix__
+void
+setproctitle(const char *fmt, ...)
+#else
 void
 setproctitle_impl(const char *fmt, ...)
+#endif
 {
 	/* Use buffer in case argv[0] is passed. */
 	char buf[SPT_MAXTITLE + 1];
@@ -280,6 +285,7 @@
 		*++nul = '\0';
 	}
 }
+#ifndef __midipix__
 __asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5");
 
 /* The original function introduced in 0.2 was a stub, it only got implemented
@@ -293,3 +299,4 @@
 	__attribute__((alias("setproctitle_impl")));
 #endif
 __asm__(".symver setproctitle_stub,setproctitle@LIBBSD_0.2");
+#endif /* !__midipix__ */
diff -Nru libbsd-0.9.1.orig/src/unvis.c libbsd-0.9.1/src/unvis.c
--- libbsd-0.9.1.orig/src/unvis.c	2018-05-22 16:07:42.000000000 +0200
+++ libbsd-0.9.1/src/unvis.c	2018-05-30 15:20:12.613101869 +0200
@@ -560,6 +560,8 @@
  * OpenBSD, 2001: strnunvis(char *dst, const char *src, size_t dlen);
  * NetBSD: 2012,  strnunvis(char *dst, size_t dlen, const char *src);
  */
+#ifndef __midipix__ /* Temporary fix until upstream resolves this in a later version, */
+		    /* do not upstream */
 ssize_t
 strnunvis_openbsd(char *dst, const char *src, size_t dlen)
 {
@@ -573,3 +575,9 @@
 	return strnunvisx(dst, dlen, src, 0);
 }
 __asm__(".symver strnunvis_netbsd,strnunvis@LIBBSD_0.9.1");
+#else
+int strnunvis(char *dst, size_t dlen, const char *src)
+{
+	return strnunvisx(dst, dlen, src, 0);
+}
+#endif /* __midipix__ */
diff -Nru libbsd-0.9.1.orig/src/vis.c libbsd-0.9.1/src/vis.c
--- libbsd-0.9.1.orig/src/vis.c	2018-05-22 16:07:42.000000000 +0200
+++ libbsd-0.9.1/src/vis.c	2018-05-30 15:34:26.362596310 +0200
@@ -718,6 +718,7 @@
  * OpenBSD, 2001: strnvis(char *dst, const char *src, size_t dlen, int flag);
  * NetBSD: 2012,  strnvis(char *dst, size_t dlen, const char *src, int flag);
  */
+#ifndef __midipix__ /* see src/unvis.c */
 int
 strnvis_openbsd(char *mbdst, const char *mbsrc, size_t dlen, int flags)
 {
@@ -731,6 +732,13 @@
 	return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL);
 }
 __asm__(".symver strnvis_netbsd,strnvis@LIBBSD_0.9.1");
+#else
+int
+strnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags)
+{
+	return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL);
+}
+#endif
 
 int
 stravis(char **mbdstp, const char *mbsrc, int flags)