1 From dbe9747b4f09bd2f4d63af06e55c2c3ed35bfca1 Mon Sep 17 00:00:00 2001
2 From: Phillip Lougher <phillip@squashfs.org.uk>
3 Date: Tue, 7 Feb 2023 23:09:30 +0000
4 Subject: [PATCH] Don't use sigwaitinfo()/sigtimedwait() if not supported
6 If sigwaitinfo() and sigtimedwait() are not supported,
9 This will disable the queue/caches dump if ^\ (SIGQUIT)
10 is hit twice within a second.
12 But the queue/caches dump is still available if SIGHUP
13 is sent to the program.
15 Currently this check is applied to MAC OS X. FreeBSD and
16 NetBSD appear to have these functions.
18 Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
20 squashfs-tools/info.c | 25 ++-------------
21 squashfs-tools/signals.h | 54 ++++++++++++++++++++++++++++++++
22 squashfs-tools/unsquashfs_info.c | 25 ++-------------
23 3 files changed, 60 insertions(+), 44 deletions(-)
24 create mode 100644 squashfs-tools/signals.h
26 --- a/squashfs-tools/info.c
27 +++ b/squashfs-tools/info.c
29 * Create a squashfs filesystem. This is a highly compressed read only
32 - * Copyright (c) 2013, 2014, 2019, 2021
33 + * Copyright (c) 2013, 2014, 2019, 2021, 2022, 2023
34 * Phillip Lougher <phillip@squashfs.org.uk>
36 * This program is free software; you can redistribute it and/or
38 #include "mksquashfs_error.h"
39 #include "progressbar.h"
40 #include "caches-queues-lists.h"
43 static int silent = 0;
44 static struct dir_ent *ent = NULL;
45 @@ -144,7 +145,6 @@ void dump_state()
46 void *info_thrd(void *arg)
49 - struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
52 sigemptyset(&sigmask);
53 @@ -152,26 +152,7 @@ void *info_thrd(void *arg)
54 sigaddset(&sigmask, SIGHUP);
58 - sig = sigtimedwait(&sigmask, NULL, ×pec);
60 - sig = sigwaitinfo(&sigmask, NULL);
65 - /* interval timed out */
69 - /* if waiting, the wait will be longer, but
73 - BAD_ERROR("sigtimedwait/sigwaitinfo failed "
74 - "because %s\n", strerror(errno));
77 + sig = wait_for_signal(&sigmask, &waiting);
79 if(sig == SIGQUIT && !waiting) {
82 +++ b/squashfs-tools/signals.h
87 + * Create a squashfs filesystem. This is a highly compressed read only
90 + * Copyright (c) 2023
91 + * Phillip Lougher <phillip@squashfs.org.uk>
93 + * This program is free software; you can redistribute it and/or
94 + * modify it under the terms of the GNU General Public License
95 + * as published by the Free Software Foundation; either version 2,
96 + * or (at your option) any later version.
98 + * This program is distributed in the hope that it will be useful,
99 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
100 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101 + * GNU General Public License for more details.
103 + * You should have received a copy of the GNU General Public License
104 + * along with this program; if not, write to the Free Software
105 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
110 +static inline int wait_for_signal(sigset_t *sigmask, int *waiting)
114 +#if defined(__APPLE__) && defined(__MACH__)
115 + sigwait(sigmask, &sig);
118 + struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
122 + sig = sigtimedwait(sigmask, NULL, ×pec);
124 + sig = sigwaitinfo(sigmask, NULL);
129 + if(errno == EAGAIN)
131 + else if(errno != EINTR)
132 + BAD_ERROR("sigtimedwait/sigwaitinfo failed because %s\n", strerror(errno));
138 --- a/squashfs-tools/unsquashfs_info.c
139 +++ b/squashfs-tools/unsquashfs_info.c
141 * Create a squashfs filesystem. This is a highly compressed read only
144 - * Copyright (c) 2013, 2021
145 + * Copyright (c) 2013, 2021, 2023
146 * Phillip Lougher <phillip@squashfs.org.uk>
148 * This program is free software; you can redistribute it and/or
150 #include "squashfs_fs.h"
151 #include "unsquashfs.h"
152 #include "unsquashfs_error.h"
153 +#include "signals.h"
155 char *pathname = NULL;
157 @@ -96,7 +97,6 @@ void dump_state()
158 void *info_thrd(void *arg)
161 - struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
162 int sig, waiting = 0;
164 sigemptyset(&sigmask);
165 @@ -104,26 +104,7 @@ void *info_thrd(void *arg)
166 sigaddset(&sigmask, SIGHUP);
170 - sig = sigtimedwait(&sigmask, NULL, ×pec);
172 - sig = sigwaitinfo(&sigmask, NULL);
177 - /* interval timed out */
181 - /* if waiting, the wait will be longer, but
185 - BAD_ERROR("sigtimedwait/sigwaitinfo failed "
186 - "because %s\n", strerror(errno));
189 + sig = wait_for_signal(&sigmask, &waiting);
191 if(sig == SIGQUIT && !waiting) {