From 8718c333ecf071cdbbe8899fce5f229d54782de4 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Tue, 29 Sep 2020 01:28:07 +0000
Subject: file: update to 5.39

---
 ...t-depend-on-the-execute-bit-to-determine-.patch |  30 ++++++
 abs/core/file/001-fix-bug-with-long-options.patch  | 109 ---------------------
 abs/core/file/PKGBUILD                             |  45 ++++++---
 abs/core/file/file-5.38-seccomp-tcgets.patch       |  28 ++++++
 4 files changed, 89 insertions(+), 123 deletions(-)
 create mode 100644 abs/core/file/0001-Revert-Don-t-depend-on-the-execute-bit-to-determine-.patch
 delete mode 100644 abs/core/file/001-fix-bug-with-long-options.patch
 create mode 100644 abs/core/file/file-5.38-seccomp-tcgets.patch

diff --git a/abs/core/file/0001-Revert-Don-t-depend-on-the-execute-bit-to-determine-.patch b/abs/core/file/0001-Revert-Don-t-depend-on-the-execute-bit-to-determine-.patch
new file mode 100644
index 0000000..9c056b2
--- /dev/null
+++ b/abs/core/file/0001-Revert-Don-t-depend-on-the-execute-bit-to-determine-.patch
@@ -0,0 +1,30 @@
+From 84221b0370a8b49e0fa2dbd88c89fb6e87ec95bd Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?S=C3=A9bastien=20Luttringer?= <seblu@seblu.net>
+Date: Fri, 24 Jan 2020 17:07:11 +0100
+Subject: [PATCH] Revert "Don't depend on the execute bit to determine pie
+ executable or shared object."
+
+This reverts commit d653309de04ed10fdeda79f2c6ca7a7e96e122f1.
+---
+ magic/Magdir/elf | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/magic/Magdir/elf b/magic/Magdir/elf
+index b5a2e00b..a35b615d 100644
+--- a/magic/Magdir/elf
++++ b/magic/Magdir/elf
+@@ -50,8 +50,9 @@
+ !:mime	application/x-object
+ >16	leshort		2		executable,
+ !:mime	application/x-executable
+->16	leshort		3		shared object,
+-!:mime	application/x-sharedlib
++>16	leshort		3		${x?pie executable:shared object},
++
++!:mime	application/x-${x?pie-executable:sharedlib}
+ >16	leshort		4		core file,
+ !:mime	application/x-coredump
+ # OS-specific
+-- 
+2.25.0
+
diff --git a/abs/core/file/001-fix-bug-with-long-options.patch b/abs/core/file/001-fix-bug-with-long-options.patch
deleted file mode 100644
index 2637f17..0000000
--- a/abs/core/file/001-fix-bug-with-long-options.patch
+++ /dev/null
@@ -1,109 +0,0 @@
-From 21f9d5f0e0340ada998f7f9d316368c7167a4afa Mon Sep 17 00:00:00 2001
-From: Christos Zoulas <christos@zoulas.com>
-Date: Thu, 11 Jun 2015 12:52:32 +0000
-Subject: [PATCH] Fix bug with long options and explicitly number them to avoid
- this in the future.
-
----
- src/file.c      | 45 +++++++++++++++++++++++----------------------
- src/file_opts.h | 10 +++++-----
- 2 files changed, 28 insertions(+), 27 deletions(-)
-
-diff --git a/src/file.c b/src/file.c
-index f60dde0..c700f66 100644
---- a/src/file.c
-+++ b/src/file.c
-@@ -89,10 +89,15 @@ private int 		/* Global command-line options 		*/
- 
- private const char *separator = ":";	/* Default field separator	*/
- private const struct option long_options[] = {
-+#define OPT_HELP		1
-+#define OPT_APPLE		2
-+#define OPT_EXTENSIONS		3
-+#define OPT_MIME_TYPE		4
-+#define OPT_MIME_ENCODING	5
- #define OPT(shortname, longname, opt, doc)      \
-     {longname, opt, NULL, shortname},
--#define OPT_LONGONLY(longname, opt, doc)        \
--    {longname, opt, NULL, 0},
-+#define OPT_LONGONLY(longname, opt, doc, id)        \
-+    {longname, opt, NULL, id},
- #include "file_opts.h"
- #undef OPT
- #undef OPT_LONGONLY
-@@ -182,24 +187,20 @@ main(int argc, char *argv[])
- 	while ((c = getopt_long(argc, argv, OPTSTRING, long_options,
- 	    &longindex)) != -1)
- 		switch (c) {
--		case 0 :
--			switch (longindex) {
--			case 0:
--				help();
--				break;
--			case 10:
--				flags |= MAGIC_APPLE;
--				break;
--			case 11:
--				flags |= MAGIC_EXTENSION;
--				break;
--			case 12:
--				flags |= MAGIC_MIME_TYPE;
--				break;
--			case 13:
--				flags |= MAGIC_MIME_ENCODING;
--				break;
--			}
-+		case OPT_HELP:
-+			help();
-+			break;
-+		case OPT_APPLE:
-+			flags |= MAGIC_APPLE;
-+			break;
-+		case OPT_EXTENSIONS:
-+			flags |= MAGIC_EXTENSION;
-+			break;
-+		case OPT_MIME_TYPE:
-+			flags |= MAGIC_MIME_TYPE;
-+			break;
-+		case OPT_MIME_ENCODING:
-+			flags |= MAGIC_MIME_ENCODING;
- 			break;
- 		case '0':
- 			nulsep = 1;
-@@ -595,7 +596,7 @@ help(void)
- #define OPT(shortname, longname, opt, doc)      \
- 	fprintf(stdout, "  -%c, --" longname, shortname), \
- 	docprint(doc);
--#define OPT_LONGONLY(longname, opt, doc)        \
-+#define OPT_LONGONLY(longname, opt, doc, id)        \
- 	fprintf(stdout, "      --" longname),	\
- 	docprint(doc);
- #include "file_opts.h"
-diff --git a/src/file_opts.h b/src/file_opts.h
-index 036505f..2e30d06 100644
---- a/src/file_opts.h
-+++ b/src/file_opts.h
-@@ -12,7 +12,7 @@
-  * switch statement!
-  */
- 
--OPT_LONGONLY("help", 0, "                 display this help and exit\n")
-+OPT_LONGONLY("help", 0, "                 display this help and exit\n", OPT_HELP)
- OPT('v', "version", 0, "              output version information and exit\n")
- OPT('m', "magic-file", 1, " LIST      use LIST as a colon-separated list of magic\n"
-     "                               number files\n")
-@@ -29,10 +29,10 @@ OPT('f', "files-from", 1, " FILE      read the filenames to be examined from FIL
- OPT('F', "separator", 1, " STRING     use string as separator instead of `:'\n")
- OPT('i', "mime", 0, "                 output MIME type strings (--mime-type and\n"
-     "                               --mime-encoding)\n")
--OPT_LONGONLY("apple", 0, "                output the Apple CREATOR/TYPE\n")
--OPT_LONGONLY("extension", 0, "            output a slash-separated list of extnsions\n")
--OPT_LONGONLY("mime-type", 0, "            output the MIME type\n")
--OPT_LONGONLY("mime-encoding", 0, "        output the MIME encoding\n")
-+OPT_LONGONLY("apple", 0, "                output the Apple CREATOR/TYPE\n", OPT_APPLE)
-+OPT_LONGONLY("extension", 0, "            output a slash-separated list of extensions\n", OPT_EXTENSIONS)
-+OPT_LONGONLY("mime-type", 0, "            output the MIME type\n", OPT_MIME_TYPE)
-+OPT_LONGONLY("mime-encoding", 0, "        output the MIME encoding\n", OPT_MIME_ENCODING)
- OPT('k', "keep-going", 0, "           don't stop at the first match\n")
- OPT('l', "list", 0, "                 list magic strength\n")
- #ifdef S_IFLNK
diff --git a/abs/core/file/PKGBUILD b/abs/core/file/PKGBUILD
index 805200e..8f78067 100644
--- a/abs/core/file/PKGBUILD
+++ b/abs/core/file/PKGBUILD
@@ -1,29 +1,47 @@
-# $Id$
 # Maintainer: Sébastien Luttringer <seblu@archlinux.org>
 # Contributor: Allan McRae <allan@archlinux.org>
 # Contributor: Andreas Radke <andyrtr@archlinux.org>
 
 pkgname=file
-pkgver=5.23
-pkgrel=2
+pkgver=5.39
+pkgrel=1
 pkgdesc='File type identification utility'
-arch=('i686' 'x86_64')
+arch=('x86_64')
 license=('custom')
-groups=('base' 'base-devel')
-url='http://www.darwinsys.com/file/'
-depends=('glibc' 'zlib')
-source=("ftp://ftp.astron.com/pub/$pkgname/$pkgname-$pkgver.tar.gz"
-        '001-fix-bug-with-long-options.patch')
-md5sums=('61db35209ce71a6d576392ce6e1d2f80'
-         '4138dd409ad6d67ee35a61cf3c71b0fe')
+groups=('base-devel')
+url='https://www.darwinsys.com/file/'
+depends=('glibc' 'zlib' 'xz' 'bzip2' 'libseccomp' 'libseccomp.so')
+provides=('libmagic.so')
+source=("https://astron.com/pub/$pkgname/$pkgname-$pkgver.tar.gz"{,.asc})
+validpgpkeys=('BE04995BA8F90ED0C0C176C471112AB16CB33B3A') # Christos Zoulas
+sha256sums=('f05d286a76d9556243d0cb05814929c2ecf3a5ba07963f8f70bfaaa70517fad1'
+            'SKIP')
 
 prepare() {
-  patch -p1 -d $pkgname-$pkgver < '001-fix-bug-with-long-options.patch'
+  cd $pkgname-$pkgver
+  # apply patch from the source array (should be a pacman feature)
+  local src
+  for src in "${source[@]}"; do
+    src="${src%%::*}"
+    src="${src##*/}"
+    [[ $src = *.patch ]] || continue
+    echo "Applying patch $src..."
+    patch -Np1 < "../$src"
+  done
 }
 
 build() {
   cd $pkgname-$pkgver
-  ./configure --prefix=/usr --datadir=/usr/share/file
+
+  # Fix linking libmagic (vfork needs libpthread)
+  CFLAGS+=" -pthread"
+
+  ./configure \
+    --prefix=/usr \
+    --datadir=/usr/share/file \
+    --enable-fsect-man5 \
+    --enable-libseccomp
+  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
   make
 }
 
@@ -36,7 +54,6 @@ package() {
   cd $pkgname-$pkgver
   make DESTDIR="$pkgdir" install
   install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
-  rmdir "$pkgdir/usr/share/man/man5"
 }
 
 # vim:set ts=2 sw=2 et:
diff --git a/abs/core/file/file-5.38-seccomp-tcgets.patch b/abs/core/file/file-5.38-seccomp-tcgets.patch
new file mode 100644
index 0000000..fac29f4
--- /dev/null
+++ b/abs/core/file/file-5.38-seccomp-tcgets.patch
@@ -0,0 +1,28 @@
+From 78573ec1c43346064661169c5c8df32e7c3bd6d6 Mon Sep 17 00:00:00 2001
+From: Christos Zoulas <christos@zoulas.com>
+Date: Fri, 17 Jan 2020 17:12:58 +0000
+Subject: [PATCH] PR/130: tobias: adjust seccomp for ioctl on hardwired
+ terminal
+
+---
+ src/seccomp.c | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/src/seccomp.c b/src/seccomp.c
+index ebf3ea1cb..0ba17233b 100644
+--- a/src/seccomp.c
++++ b/src/seccomp.c
+@@ -186,8 +186,12 @@ enable_sandbox_full(void)
+ 	ALLOW_IOCTL_RULE(FIONREAD);
+ #endif
+ #ifdef TIOCGWINSZ
+-	// musl libc may call ioctl TIOCGWINSZ when calling stdout
++	// musl libc may call ioctl TIOCGWINSZ on stdout
+ 	ALLOW_IOCTL_RULE(TIOCGWINSZ);
++#endif
++#ifdef TCGETS
++	// glibc may call ioctl TCGETS on stdout on physical terminal
++	ALLOW_IOCTL_RULE(TCGETS);
+ #endif
+ 	ALLOW_RULE(lseek);
+  	ALLOW_RULE(_llseek);
-- 
cgit v0.12