Conan_Kudo / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone
Blob Blame History Raw
diff -Nru libbsd-0.8.7.orig/include/bsd/stdlib.h libbsd-0.8.7/include/bsd/stdlib.h
--- libbsd-0.8.7.orig/include/bsd/stdlib.h	2017-08-05 13:20:00.000000000 +0200
+++ libbsd-0.8.7/include/bsd/stdlib.h	2018-04-27 21:18:23.074047191 +0200
@@ -67,7 +67,7 @@
                const unsigned char *table, unsigned endbyte);
 
 void *reallocf(void *ptr, size_t size);
-#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 26)
+#if defined(_GNU_SOURCE)
 void *reallocarray(void *ptr, size_t nmemb, size_t size);
 #endif
 
diff -Nru libbsd-0.8.7.orig/include/bsd/string.h libbsd-0.8.7/include/bsd/string.h
--- libbsd-0.8.7.orig/include/bsd/string.h	2017-08-05 13:20:54.000000000 +0200
+++ libbsd-0.8.7/include/bsd/string.h	2018-04-27 21:18:02.670455792 +0200
@@ -42,7 +42,7 @@
 char *strnstr(const char *str, const char *find, size_t str_len);
 void strmode(mode_t mode, char *str);
 
-#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 25)
+#if defined(_GNU_SOURCE)
 void explicit_bzero(void *buf, size_t len);
 #endif
 __END_DECLS
diff -Nru libbsd-0.8.7.orig/src/getentropy.c libbsd-0.8.7/src/getentropy.c
--- libbsd-0.8.7.orig/src/getentropy.c	2017-06-06 04:21:24.000000000 +0200
+++ libbsd-0.8.7/src/getentropy.c	2018-04-27 21:09:29.121945744 +0200
@@ -40,6 +40,8 @@
 #include "getentropy_aix.c"
 #elif defined(__hpux)
 #include "getentropy_hpux.c"
+#elif defined(__midipix__) /* temporary - no native getentropy() yet */
+#include "getentropy_midipix.c"
 #else
 #error "No getentropy hooks defined for this platform."
 #endif
diff -Nru libbsd-0.8.7.orig/src/getentropy_midipix.c libbsd-0.8.7/src/getentropy_midipix.c
--- libbsd-0.8.7.orig/src/getentropy_midipix.c	1970-01-01 01:00:00.000000000 +0100
+++ libbsd-0.8.7/src/getentropy_midipix.c	2018-04-27 21:11:22.917696342 +0200
@@ -0,0 +1,118 @@
+/* Temporary copy-paste from getentropy_linux.c until we get a native getentropy() implementation */
+
+
+#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>
+
+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);
+        }
+
+        ret = getentropy_urandom(buf, len);
+        if (ret != -1)
+                return (ret);
+
+	/* Oh well! */
+	raise(SIGKILL);
+	return -1;
+}
+
+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.8.7.orig/src/getpeereid.c libbsd-0.8.7/src/getpeereid.c
--- libbsd-0.8.7.orig/src/getpeereid.c	2017-06-06 04:06:45.000000000 +0200
+++ libbsd-0.8.7/src/getpeereid.c	2018-04-27 21:11:49.277638606 +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.8.7.orig/src/setproctitle.c libbsd-0.8.7/src/setproctitle.c
--- libbsd-0.8.7.orig/src/setproctitle.c	2017-07-17 00:47:19.000000000 +0200
+++ libbsd-0.8.7/src/setproctitle.c	2018-04-27 21:12:24.521561430 +0200
@@ -280,6 +280,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 +294,4 @@
 	__attribute__((alias("setproctitle_impl")));
 #endif
 __asm__(".symver setproctitle_stub,setproctitle@LIBBSD_0.2");
+#endif