sasquatch
sasquatch copied to clipboard
Errors when building for MacOS. 'sys/sysinfo.h' file not found
Running on MacOS Ventura: 13.6.2 (22G417)
./build.sh
gives this error after patching:
cc -g -O2 -I. -I./LZMA/lzma465/C -I./LZMA/lzmalt -I./LZMA/lzmadaptive/C/7zip/Compress/LZMA_Lib -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -DCOMP_DEFAULT=\"gzip\" -Wall -Werror -DGZIP_SUPPORT -DLZMA_SUPPORT -DXZ_SUPPORT -DLZO_SUPPORT -DXATTR_SUPPORT -DXATTR_DEFAULT -c -o unsquashfs.o unsquashfs.c
unsquashfs.c:34:10: fatal error: 'sys/sysinfo.h' file not found
#include <sys/sysinfo.h>
^~~~~~~~~~~~~~~
1 error generated.
make: *** [unsquashfs.o] Error 1
FYI. A previous version (v4.2) was successfully built using this workaround:
https://zettelchen.blogspot.com/2009/04/build-squashfs-tools-for-mac-os-x.html?sc=1699918602391#c3671849828431191721
wget https://downloads.sourceforge.net/project/squashfs/squashfs/squashfs4.2/squashfs4.2.tar.gz
tar xzvf squashfs4.2.tar.gz
cd squashfs4.2/squashfs-tools/
sed -i.orig 's/FNM_EXTMATCH/0/; s/sysinfo.h/sysctl.h/; s/^inline/static inline/' mksquashfs.c unsquashfs.c
cat <<END >> xattr.h
> #define llistxattr(path, list, size) \
> (listxattr(path, list, size, XATTR_NOFOLLOW))
> #define lgetxattr(path, name, value, size) \
> (getxattr(path, name, value, size, 0, XATTR_NOFOLLOW))
> #define lsetxattr(path, name, value, size, flags) \
> (setxattr(path, name, value, size, 0, flags | XATTR_NOFOLLOW))
> END
make
sudo cp mksquashfs unsquashfs /usr/local/bin
Mac OS Ventura 13.6.3 arm64, now running into:
unsquashfs.c:36:10: fatal error: 'sys/sysmacros.h' file not found
#include <sys/sysmacros.h>
^~~~~~~~~~~~~~~~~
and if just deleting that line,
unsquashfs_info.c:109:10: error: call to undeclared function 'sigtimedwait'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
sig = sigtimedwait(&sigmask, NULL, ×pec);
^
unsquashfs_info.c:111:10: error: call to undeclared function 'sigwaitinfo'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
sig = sigwaitinfo(&sigmask, NULL);
^
See upstream commit: https://github.com/plougher/squashfs-tools/commit/dbe9747b4f09bd2f4d63af06e55c2c3ed35bfca1
Fixup:
Save this to mac.patch
(NOTE this is not the original patch, I have modified it)
From dbe9747b4f09bd2f4d63af06e55c2c3ed35bfca1 Mon Sep 17 00:00:00 2001
From: Phillip Lougher <[email protected]>
Date: Tue, 7 Feb 2023 23:09:30 +0000
Subject: [PATCH] Don't use sigwaitinfo()/sigtimedwait() if not supported
If sigwaitinfo() and sigtimedwait() are not supported,
use sigwait() instead.
This will disable the queue/caches dump if ^\ (SIGQUIT)
is hit twice within a second.
But the queue/caches dump is still available if SIGHUP
is sent to the program.
Currently this check is applied to MAC OS X. FreeBSD and
NetBSD appear to have these functions.
Signed-off-by: Phillip Lougher <[email protected]>
---
squashfs-tools/info.c | 25 ++-------------
squashfs-tools/signals.h | 54 ++++++++++++++++++++++++++++++++
squashfs-tools/unsquashfs_info.c | 25 ++-------------
3 files changed, 60 insertions(+), 44 deletions(-)
create mode 100644 squashfs-tools/signals.h
diff --git a/squashfs-tools/info.c b/squashfs-tools/info.c
index a34dcca9..7135305b 100644
--- a/squashfs-tools/info.c
+++ b/squashfs-tools/info.c
@@ -42,6 +42,7 @@
#include "mksquashfs_error.h"
#include "progressbar.h"
#include "caches-queues-lists.h"
+#include "signals.h"
static int silent = 0;
static struct dir_ent *ent = NULL;
@@ -144,7 +145,6 @@ static void dump_state()
static void *info_thrd(void *arg)
{
sigset_t sigmask;
- struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
int sig, waiting = 0;
sigemptyset(&sigmask);
@@ -152,26 +152,7 @@ static void *info_thrd(void *arg)
sigaddset(&sigmask, SIGHUP);
while(1) {
- if(waiting)
- sig = sigtimedwait(&sigmask, NULL, ×pec);
- else
- sig = sigwaitinfo(&sigmask, NULL);
-
- if(sig == -1) {
- switch(errno) {
- case EAGAIN:
- /* interval timed out */
- waiting = 0;
- /* FALLTHROUGH */
- case EINTR:
- /* if waiting, the wait will be longer, but
- that's OK */
- continue;
- default:
- BAD_ERROR("sigtimedwait/sigwaitinfo failed "
- "because %s\n", strerror(errno));
- }
- }
+ sig = wait_for_signal(&sigmask, &waiting);
if(sig == SIGQUIT && !waiting) {
print_filename();
diff --git a/squashfs-tools/signals.h b/squashfs-tools/signals.h
new file mode 100644
index 00000000..54184485
--- /dev/null
+++ b/squashfs-tools/signals.h
@@ -0,0 +1,54 @@
+#ifndef SIGNALS_H
+#define SIGNALS_H
+/*
+ * Create a squashfs filesystem. This is a highly compressed read only
+ * filesystem.
+ *
+ * Copyright (c) 2023
+ * Phillip Lougher <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * signals.h
+ */
+
+static inline int wait_for_signal(sigset_t *sigmask, int *waiting)
+{
+ int sig;
+
+#if defined(__APPLE__) && defined(__MACH__)
+ sigwait(sigmask, &sig);
+ *waiting = 0;
+#else
+ struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
+
+ while(1) {
+ if(*waiting)
+ sig = sigtimedwait(sigmask, NULL, ×pec);
+ else
+ sig = sigwaitinfo(sigmask, NULL);
+
+ if(sig != -1)
+ break;
+
+ if(errno == EAGAIN)
+ *waiting = 0;
+ else if(errno != EINTR)
+ BAD_ERROR("sigtimedwait/sigwaitinfo failed because %s\n", strerror(errno));
+ }
+#endif
+ return sig;
+}
+#endif
diff --git a/squashfs-tools/unsquashfs_info.c b/squashfs-tools/unsquashfs_info.c
index e906eaf6..2be9f660 100644
--- a/squashfs-tools/unsquashfs_info.c
+++ b/squashfs-tools/unsquashfs_info.c
@@ -40,6 +40,7 @@
#include "squashfs_fs.h"
#include "unsquashfs.h"
#include "error.h"
+#include "signals.h"
static int silent = 0;
char *pathname = NULL;
@@ -96,7 +97,6 @@ void dump_state()
void *info_thrd(void *arg)
{
sigset_t sigmask;
- struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
int sig, waiting = 0;
sigemptyset(&sigmask);
@@ -104,26 +104,7 @@ void *info_thrd(void *arg)
sigaddset(&sigmask, SIGHUP);
while(1) {
- if(waiting)
- sig = sigtimedwait(&sigmask, NULL, ×pec);
- else
- sig = sigwaitinfo(&sigmask, NULL);
-
- if(sig == -1) {
- switch(errno) {
- case EAGAIN:
- /* interval timed out */
- waiting = 0;
- /* FALLTHROUGH */
- case EINTR:
- /* if waiting, the wait will be longer, but
- that's OK */
- continue;
- default:
- BAD_ERROR("sigtimedwait/sigwaitinfo failed "
- "because %s\n", strerror(errno));
- }
- }
+ sig = wait_for_signal(&sigmask, &waiting);
if(sig == SIGQUIT && !waiting) {
if(pathname)
Then, apply this patch
diff --git a/build.sh b/build.sh
index 4acf81f..883c131 100755
--- a/build.sh
+++ b/build.sh
@@ -31,7 +31,28 @@ rm -rf squashfs4.3
tar -zxvf squashfs4.3.tar.gz
# Patch, build, and install the source
-cd squashfs4.3
+
+cd squashfs4.3/squashfs-tools/
+
+sed -i.orig 's/FNM_EXTMATCH/0/; s/sysinfo.h/sysctl.h/; s/^inline/static inline/' mksquashfs.c unsquashfs.c
+
+cat <<END >> xattr.h
+#define llistxattr(path, list, size) \
+ (listxattr(path, list, size, XATTR_NOFOLLOW))
+#define lgetxattr(path, name, value, size) \
+ (getxattr(path, name, value, size, 0, XATTR_NOFOLLOW))
+#define lsetxattr(path, name, value, size, flags) \
+ (setxattr(path, name, value, size, 0, flags | XATTR_NOFOLLOW))
+END
+
+cd ..
+
+patch -p1 < ../mac.patch
patch -p0 < ../patches/patch0.txt
+
cd squashfs-tools
+sed -i.orig 's/\-Werror/\-Werror \-Wno\-self\-assign/' Makefile
+sed -i.orig 's/#LZO_DIR \= .*/LZO_DIR \= \/opt\/homebrew\/opt\/lzo/' Makefile
+sed -i.orig 's/#LZMA_XZ_SUPPORT \= 1/EXTRA_CFLAGS \= \-I\/opt\/homebrew\/opt\/xz\/include/' Makefile
+
make && $SUDO make install