tools/squashfs4: enable parallel builds
[openwrt/staging/jow.git] / tools / squashfs4 / patches / 005-Don-t-use-sigwaitinfo-sigtimedwait-if-not-supported.patch
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
5
6 If sigwaitinfo() and sigtimedwait() are not supported,
7 use sigwait() instead.
8
9 This will disable the queue/caches dump if ^\ (SIGQUIT)
10 is hit twice within a second.
11
12 But the queue/caches dump is still available if SIGHUP
13 is sent to the program.
14
15 Currently this check is applied to MAC OS X. FreeBSD and
16 NetBSD appear to have these functions.
17
18 Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
19 ---
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
25
26 --- a/squashfs-tools/info.c
27 +++ b/squashfs-tools/info.c
28 @@ -2,7 +2,7 @@
29 * Create a squashfs filesystem. This is a highly compressed read only
30 * filesystem.
31 *
32 - * Copyright (c) 2013, 2014, 2019, 2021
33 + * Copyright (c) 2013, 2014, 2019, 2021, 2022, 2023
34 * Phillip Lougher <phillip@squashfs.org.uk>
35 *
36 * This program is free software; you can redistribute it and/or
37 @@ -42,6 +42,7 @@
38 #include "mksquashfs_error.h"
39 #include "progressbar.h"
40 #include "caches-queues-lists.h"
41 +#include "signals.h"
42
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)
47 {
48 sigset_t sigmask;
49 - struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
50 int sig, waiting = 0;
51
52 sigemptyset(&sigmask);
53 @@ -152,26 +152,7 @@ void *info_thrd(void *arg)
54 sigaddset(&sigmask, SIGHUP);
55
56 while(1) {
57 - if(waiting)
58 - sig = sigtimedwait(&sigmask, NULL, &timespec);
59 - else
60 - sig = sigwaitinfo(&sigmask, NULL);
61 -
62 - if(sig == -1) {
63 - switch(errno) {
64 - case EAGAIN:
65 - /* interval timed out */
66 - waiting = 0;
67 - /* FALLTHROUGH */
68 - case EINTR:
69 - /* if waiting, the wait will be longer, but
70 - that's OK */
71 - continue;
72 - default:
73 - BAD_ERROR("sigtimedwait/sigwaitinfo failed "
74 - "because %s\n", strerror(errno));
75 - }
76 - }
77 + sig = wait_for_signal(&sigmask, &waiting);
78
79 if(sig == SIGQUIT && !waiting) {
80 print_filename();
81 --- /dev/null
82 +++ b/squashfs-tools/signals.h
83 @@ -0,0 +1,54 @@
84 +#ifndef SIGNALS_H
85 +#define SIGNALS_H
86 +/*
87 + * Create a squashfs filesystem. This is a highly compressed read only
88 + * filesystem.
89 + *
90 + * Copyright (c) 2023
91 + * Phillip Lougher <phillip@squashfs.org.uk>
92 + *
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.
97 + *
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.
102 + *
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.
106 + *
107 + * signals.h
108 + */
109 +
110 +static inline int wait_for_signal(sigset_t *sigmask, int *waiting)
111 +{
112 + int sig;
113 +
114 +#if defined(__APPLE__) && defined(__MACH__)
115 + sigwait(sigmask, &sig);
116 + *waiting = 0;
117 +#else
118 + struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
119 +
120 + while(1) {
121 + if(*waiting)
122 + sig = sigtimedwait(sigmask, NULL, &timespec);
123 + else
124 + sig = sigwaitinfo(sigmask, NULL);
125 +
126 + if(sig != -1)
127 + break;
128 +
129 + if(errno == EAGAIN)
130 + *waiting = 0;
131 + else if(errno != EINTR)
132 + BAD_ERROR("sigtimedwait/sigwaitinfo failed because %s\n", strerror(errno));
133 + }
134 +#endif
135 + return sig;
136 +}
137 +#endif
138 --- a/squashfs-tools/unsquashfs_info.c
139 +++ b/squashfs-tools/unsquashfs_info.c
140 @@ -2,7 +2,7 @@
141 * Create a squashfs filesystem. This is a highly compressed read only
142 * filesystem.
143 *
144 - * Copyright (c) 2013, 2021
145 + * Copyright (c) 2013, 2021, 2023
146 * Phillip Lougher <phillip@squashfs.org.uk>
147 *
148 * This program is free software; you can redistribute it and/or
149 @@ -40,6 +40,7 @@
150 #include "squashfs_fs.h"
151 #include "unsquashfs.h"
152 #include "unsquashfs_error.h"
153 +#include "signals.h"
154
155 char *pathname = NULL;
156
157 @@ -96,7 +97,6 @@ void dump_state()
158 void *info_thrd(void *arg)
159 {
160 sigset_t sigmask;
161 - struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
162 int sig, waiting = 0;
163
164 sigemptyset(&sigmask);
165 @@ -104,26 +104,7 @@ void *info_thrd(void *arg)
166 sigaddset(&sigmask, SIGHUP);
167
168 while(1) {
169 - if(waiting)
170 - sig = sigtimedwait(&sigmask, NULL, &timespec);
171 - else
172 - sig = sigwaitinfo(&sigmask, NULL);
173 -
174 - if(sig == -1) {
175 - switch(errno) {
176 - case EAGAIN:
177 - /* interval timed out */
178 - waiting = 0;
179 - /* FALLTHROUGH */
180 - case EINTR:
181 - /* if waiting, the wait will be longer, but
182 - that's OK */
183 - continue;
184 - default:
185 - BAD_ERROR("sigtimedwait/sigwaitinfo failed "
186 - "because %s\n", strerror(errno));
187 - }
188 - }
189 + sig = wait_for_signal(&sigmask, &waiting);
190
191 if(sig == SIGQUIT && !waiting) {
192 if(pathname)